Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for regional variant langauges, like pt-BR #118

Merged
merged 1 commit into from
Jun 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading