From 44e6f99e623d041387be2fb2649fc9a708c712bc Mon Sep 17 00:00:00 2001 From: Patrick Connolly Date: Sun, 14 Oct 2018 17:30:01 +0800 Subject: [PATCH] Added fix for Google Translate bug. --- gateway/gateway.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/gateway/gateway.go b/gateway/gateway.go index 20e2a3ac..5dd735fa 100644 --- a/gateway/gateway.go +++ b/gateway/gateway.go @@ -300,6 +300,10 @@ func (gw *Gateway) handleMessage(msg config.Message, dest *bridge.Bridge) []*BrM text := msg.Text var results [][]string + // colons: add temp token + // This is an ugly hack to work around what seems to be a bug in the Google Translate API. + // See: https://github.com/42wim/matterbridge/pull/512#issuecomment-428910199 + text = regexp.MustCompile(`(:)([ $])`).ReplaceAllString(text, "ː$2") // @usernames results = regexp.MustCompile(`(@[a-zA-Z0-9-]+)`).FindAllStringSubmatch(text, -1) @@ -339,6 +343,10 @@ func (gw *Gateway) handleMessage(msg config.Message, dest *bridge.Bridge) []*BrM } text = strip.StripTags(text) + + // colons: revert temp token + // See: previous comment on colons + text = regexp.MustCompile(`(ː)([ $])`).ReplaceAllString(text, ":$2") text = html.UnescapeString(text) msg.Text = text + attribution