feat: add support for regional variant langauges, like pt-BR (#118)
Some checks are pending
CI / Build (push) Waiting to run

This commit is contained in:
Tisfeng 2024-06-16 22:19:18 +08:00 committed by GitHub
parent 93a3204eab
commit 8bf6d05603
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 23 additions and 9 deletions

View File

@ -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,
},
}
}

View File

@ -26,7 +26,7 @@ type Lang struct {
type CommonJobParams struct {
WasSpoken bool `json:"wasSpoken"`
TranscribeAS string `json:"transcribe_as"`
// RegionalVariant string `json:"regionalVariant"`
RegionalVariant string `json:"regionalVariant,omitempty"`
}
type Params struct {