Skip to content

Commit

Permalink
feat: add support for regional variant langauges, like pt-BR (#118)
Browse files Browse the repository at this point in the history
  • Loading branch information
tisfeng authored Jun 16, 2024
1 parent 93a3204 commit 8bf6d05
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
26 changes: 20 additions & 6 deletions translate.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,34 @@ 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",
Params: Params{
Splitting: "newlines",
Lang: Lang{
SourceLangUserSelected: sourceLang,
TargetLang: targetLang,
},
CommonJobParams: CommonJobParams{
WasSpoken: false,
TranscribeAS: "",
// RegionalVariant: "en-US",
TargetLang: targetLangCode,
},
CommonJobParams: commonJobParams,
},
}
}
Expand Down
6 changes: 3 additions & 3 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 8bf6d05

Please sign in to comment.