Added lots of debug output while working on PR.
This commit is contained in:
@@ -351,6 +351,8 @@ func (gw *Gateway) handleMessage(msg config.Message, dest *bridge.Bridge) []*BrM
|
|||||||
url_re := regexp.MustCompile(`(((http(s)?(\:\/\/))+(www\.)?([\w\-\.\/])*(\.[a-zA-Z]{2,3}\/?))[^\s\n|]*[^.,;:\?\!\@\^\$ -])`)
|
url_re := regexp.MustCompile(`(((http(s)?(\:\/\/))+(www\.)?([\w\-\.\/])*(\.[a-zA-Z]{2,3}\/?))[^\s\n|]*[^.,;:\?\!\@\^\$ -])`)
|
||||||
text = url_re.ReplaceAllString(text, "<span translate='no'>$0</span>")
|
text = url_re.ReplaceAllString(text, "<span translate='no'>$0</span>")
|
||||||
|
|
||||||
|
flog.Debugf("pre-parseMD:"+text)
|
||||||
|
|
||||||
// Get rid of these wierdo bullets that Slack uses, which confuse translation
|
// Get rid of these wierdo bullets that Slack uses, which confuse translation
|
||||||
text = strings.Replace(text, "•", "-", -1)
|
text = strings.Replace(text, "•", "-", -1)
|
||||||
|
|
||||||
@@ -364,6 +366,7 @@ func (gw *Gateway) handleMessage(msg config.Message, dest *bridge.Bridge) []*BrM
|
|||||||
blackfriday.EXTENSION_HARD_LINE_BREAK
|
blackfriday.EXTENSION_HARD_LINE_BREAK
|
||||||
output := blackfriday.Markdown([]byte(text), renderer, extensions)
|
output := blackfriday.Markdown([]byte(text), renderer, extensions)
|
||||||
text = string(output)
|
text = string(output)
|
||||||
|
flog.Debugf("post-parseMD:"+string(output))
|
||||||
|
|
||||||
// @usernames
|
// @usernames
|
||||||
results = regexp.MustCompile(`(@[a-zA-Z0-9-]+)`).FindAllStringSubmatch(text, -1)
|
results = regexp.MustCompile(`(@[a-zA-Z0-9-]+)`).FindAllStringSubmatch(text, -1)
|
||||||
@@ -375,6 +378,8 @@ func (gw *Gateway) handleMessage(msg config.Message, dest *bridge.Bridge) []*BrM
|
|||||||
text = regexp.MustCompile(fmt.Sprintf(`([^>])(%s)`, r[1])).ReplaceAllString(text, "$1<span translate='no'>$2</span>")
|
text = regexp.MustCompile(fmt.Sprintf(`([^>])(%s)`, r[1])).ReplaceAllString(text, "$1<span translate='no'>$2</span>")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
flog.Debugf("post cleanup:usernames:"+text)
|
||||||
|
|
||||||
// #channels
|
// #channels
|
||||||
results = regexp.MustCompile(`(#[a-zA-Z0-9-]+)`).FindAllStringSubmatch(text, -1)
|
results = regexp.MustCompile(`(#[a-zA-Z0-9-]+)`).FindAllStringSubmatch(text, -1)
|
||||||
// Sort so that longest channel names are acted on first
|
// Sort so that longest channel names are acted on first
|
||||||
@@ -386,12 +391,15 @@ func (gw *Gateway) handleMessage(msg config.Message, dest *bridge.Bridge) []*BrM
|
|||||||
text = regexp.MustCompile(fmt.Sprintf(`([^>])(%s)`, r[1])).ReplaceAllString(text, "$1<span translate='no'>$2</span>")
|
text = regexp.MustCompile(fmt.Sprintf(`([^>])(%s)`, r[1])).ReplaceAllString(text, "$1<span translate='no'>$2</span>")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
flog.Debugf("post cleanup:channels:"+text)
|
||||||
|
|
||||||
// :emoji:
|
// :emoji:
|
||||||
text = regexp.MustCompile(`:[a-z0-9-_]+?:`).ReplaceAllString(text, "<span translate='no'>$0</span>")
|
text = regexp.MustCompile(`:[a-z0-9-_]+?:`).ReplaceAllString(text, "<span translate='no'>$0</span>")
|
||||||
|
|
||||||
// :emoji: codepoints, ie. 💎
|
// :emoji: codepoints, ie. 💎
|
||||||
text = emoji.NewEmojiParser().ReplaceAllString(text, "<span translate='no'>$0</span>")
|
text = emoji.NewEmojiParser().ReplaceAllString(text, "<span translate='no'>$0</span>")
|
||||||
|
|
||||||
|
flog.Debugf("post cleanup:emojis:"+text)
|
||||||
|
|
||||||
channelLang, err := language.Parse(channel.Options.Locale)
|
channelLang, err := language.Parse(channel.Options.Locale)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -403,6 +411,7 @@ func (gw *Gateway) handleMessage(msg config.Message, dest *bridge.Bridge) []*BrM
|
|||||||
})
|
})
|
||||||
|
|
||||||
text = resp[0].Text
|
text = resp[0].Text
|
||||||
|
flog.Debugf("post-translate:"+text)
|
||||||
|
|
||||||
if resp[0].Source != channelLang {
|
if resp[0].Source != channelLang {
|
||||||
// If the source language is the same as this channel,
|
// If the source language is the same as this channel,
|
||||||
@@ -429,6 +438,7 @@ func (gw *Gateway) handleMessage(msg config.Message, dest *bridge.Bridge) []*BrM
|
|||||||
|
|
||||||
stripped, _ := htmltags.Strip(text, allowableTags, false)
|
stripped, _ := htmltags.Strip(text, allowableTags, false)
|
||||||
text = stripped.ToString()
|
text = stripped.ToString()
|
||||||
|
flog.Debugf("post-strip:"+text)
|
||||||
html2md.AddRule("del", &html2md.Rule{
|
html2md.AddRule("del", &html2md.Rule{
|
||||||
Patterns: []string{"del"},
|
Patterns: []string{"del"},
|
||||||
Replacement: func(innerHTML string, attrs []string) string {
|
Replacement: func(innerHTML string, attrs []string) string {
|
||||||
@@ -472,7 +482,10 @@ func (gw *Gateway) handleMessage(msg config.Message, dest *bridge.Bridge) []*BrM
|
|||||||
// colons: revert temp token
|
// colons: revert temp token
|
||||||
// See: previous comment on colons
|
// See: previous comment on colons
|
||||||
text = regexp.MustCompile(`(ː)([ $])`).ReplaceAllString(text, ":$2")
|
text = regexp.MustCompile(`(ː)([ $])`).ReplaceAllString(text, ":$2")
|
||||||
|
|
||||||
|
flog.Debugf("post-MDconvert:"+text)
|
||||||
text = html.UnescapeString(text)
|
text = html.UnescapeString(text)
|
||||||
|
flog.Debugf("post-unescaped:"+text)
|
||||||
|
|
||||||
text = text + gw.Router.General.TranslationAttribution
|
text = text + gw.Router.General.TranslationAttribution
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user