diff --git a/translate.go b/translate.go index 8075ecc3..44e022a4 100644 --- a/translate.go +++ b/translate.go @@ -14,6 +14,24 @@ import ( ) func initDeepLXData(sourceLang string, targetLang string) *PostData { + hasRegionalVariant := false + targetLangParts := strings.Split(targetLang, "-") + + // targetLang can be "en", "pt", "pt-PT", "pt-BR" + // targetLangCode is the first part of the targetLang, e.g. "pt" in "pt-PT" + targetLangCode := targetLangParts[0] + if len(targetLangParts) > 1 { + hasRegionalVariant = true + } + + commonJobParams := CommonJobParams{ + WasSpoken: false, + TranscribeAS: "", + } + if hasRegionalVariant { + commonJobParams.RegionalVariant = targetLang + } + return &PostData{ Jsonrpc: "2.0", Method: "LMT_handle_texts", @@ -21,13 +39,9 @@ func initDeepLXData(sourceLang string, targetLang string) *PostData { Splitting: "newlines", Lang: Lang{ SourceLangUserSelected: sourceLang, - TargetLang: targetLang, - }, - CommonJobParams: CommonJobParams{ - WasSpoken: false, - TranscribeAS: "", - // RegionalVariant: "en-US", + TargetLang: targetLangCode, }, + CommonJobParams: commonJobParams, }, } } diff --git a/types.go b/types.go index feb1037e..b81eb0ad 100644 --- a/types.go +++ b/types.go @@ -24,9 +24,9 @@ type Lang struct { } type CommonJobParams struct { - WasSpoken bool `json:"wasSpoken"` - TranscribeAS string `json:"transcribe_as"` - // RegionalVariant string `json:"regionalVariant"` + WasSpoken bool `json:"wasSpoken"` + TranscribeAS string `json:"transcribe_as"` + RegionalVariant string `json:"regionalVariant,omitempty"` } type Params struct {