diff --git a/README.md b/README.md index baed21e4..b5ee4865 100644 --- a/README.md +++ b/README.md @@ -110,8 +110,7 @@ of the JSON credentials file. * By default (in accordance with Google's terms of service), we add "[translated by Google]" to the end of all translated messages. You -may customize this attribution text via the environment variable -`GOOGLE_TRANSLATE_ATTRIBUTION`. +may customize this attribution via `TranslationAttribution` config key. ## Examples ### Bridge mattermost (off-topic) - irc (#testing) diff --git a/bridge/config/config.go b/bridge/config/config.go index fac68977..7d2808be 100644 --- a/bridge/config/config.go +++ b/bridge/config/config.go @@ -124,6 +124,7 @@ type Protocol struct { WebhookBindAddress string // mattermost, slack WebhookURL string // mattermost, slack WebhookUse string // mattermost, slack, discord + TranslationAttribution string // all protocols } type ChannelOptions struct { diff --git a/gateway/gateway.go b/gateway/gateway.go index 1b3ec41e..33c42795 100644 --- a/gateway/gateway.go +++ b/gateway/gateway.go @@ -334,17 +334,12 @@ func (gw *Gateway) handleMessage(msg config.Message, dest *bridge.Bridge) []*BrM msg.ID = "" if (gw.Router.GTClient != nil) && (channel.Options.Locale != "") { - attribution, ok := os.LookupEnv("GOOGLE_TRANSLATE_ATTRIBUTION") - if !(ok) { - attribution = " [translated by Google]" - } - ctx := context.Background() client := gw.Router.GTClient defer client.Close() - text := msg.Text + text := origmsg.Text var results [][]string // colons: add temp token @@ -479,7 +474,9 @@ func (gw *Gateway) handleMessage(msg config.Message, dest *bridge.Bridge) []*BrM text = regexp.MustCompile(`(ː)([ $])`).ReplaceAllString(text, ":$2") text = html.UnescapeString(text) - msg.Text = text + attribution + text = text + gw.Router.General.TranslationAttribution + + msg.Text = text } } if res, ok := gw.Messages.Get(origmsg.ID); ok { diff --git a/matterbridge.toml.sample b/matterbridge.toml.sample index e548ec70..5b969339 100644 --- a/matterbridge.toml.sample +++ b/matterbridge.toml.sample @@ -1289,6 +1289,10 @@ MediaDownloadSize=1000000 #OPTIONAL (default empty) MediaDownloadBlacklist=[".html$",".htm$"] +# When Google Translate API feature is enabled, this will be appended to each +# translated message. (This is required by Google's terms of service.) +TranslationAttribution=" [translated by Google]" + ################################################################### #Gateway configuration ###################################################################