Moved translation attribute into toml config. Now using origmsg var for msg text.
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
###################################################################
|
||||
|
||||
Reference in New Issue
Block a user