Moved translation attribute into toml config. Now using origmsg var for msg text.

This commit is contained in:
Patrick Connolly
2018-10-15 06:48:14 +08:00
parent 4eaa59c594
commit f32e7a9c35
4 changed files with 10 additions and 9 deletions

View File

@@ -110,8 +110,7 @@ of the JSON credentials file.
* By default (in accordance with Google's terms of service), we add * By default (in accordance with Google's terms of service), we add
"[translated by Google]" to the end of all translated messages. You "[translated by Google]" to the end of all translated messages. You
may customize this attribution text via the environment variable may customize this attribution via `TranslationAttribution` config key.
`GOOGLE_TRANSLATE_ATTRIBUTION`.
## Examples ## Examples
### Bridge mattermost (off-topic) - irc (#testing) ### Bridge mattermost (off-topic) - irc (#testing)

View File

@@ -124,6 +124,7 @@ type Protocol struct {
WebhookBindAddress string // mattermost, slack WebhookBindAddress string // mattermost, slack
WebhookURL string // mattermost, slack WebhookURL string // mattermost, slack
WebhookUse string // mattermost, slack, discord WebhookUse string // mattermost, slack, discord
TranslationAttribution string // all protocols
} }
type ChannelOptions struct { type ChannelOptions struct {

View File

@@ -334,17 +334,12 @@ func (gw *Gateway) handleMessage(msg config.Message, dest *bridge.Bridge) []*BrM
msg.ID = "" msg.ID = ""
if (gw.Router.GTClient != nil) && (channel.Options.Locale != "") { if (gw.Router.GTClient != nil) && (channel.Options.Locale != "") {
attribution, ok := os.LookupEnv("GOOGLE_TRANSLATE_ATTRIBUTION")
if !(ok) {
attribution = " [translated by Google]"
}
ctx := context.Background() ctx := context.Background()
client := gw.Router.GTClient client := gw.Router.GTClient
defer client.Close() defer client.Close()
text := msg.Text text := origmsg.Text
var results [][]string var results [][]string
// colons: add temp token // 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 = regexp.MustCompile(`(ː)([ $])`).ReplaceAllString(text, ":$2")
text = html.UnescapeString(text) 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 { if res, ok := gw.Messages.Get(origmsg.ID); ok {

View File

@@ -1289,6 +1289,10 @@ MediaDownloadSize=1000000
#OPTIONAL (default empty) #OPTIONAL (default empty)
MediaDownloadBlacklist=[".html$",".htm$"] 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 #Gateway configuration
################################################################### ###################################################################