Skip to content

Commit

Permalink
fix: support CommonJobParams
Browse files Browse the repository at this point in the history
  • Loading branch information
missuo committed Nov 1, 2024
1 parent 62a993b commit 9edb997
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
15 changes: 12 additions & 3 deletions translate/translate.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author: Vincent Young
* @Date: 2024-09-16 11:59:24
* @LastEditors: Vincent Yang
* @LastEditTime: 2024-11-01 00:42:43
* @LastEditTime: 2024-11-01 12:45:44
* @FilePath: /DeepLX/translate/translate.go
* @Telegram: https://t.me/missuo
* @GitHub: https://github.com/missuo
Expand Down Expand Up @@ -161,6 +161,13 @@ func TranslateByDeepLX(sourceLang, targetLang, text string, tagHandling string,
})
}

hasRegionalVariant := false
targetLangParts := strings.Split(targetLang, "-")
targetLangCode := targetLangParts[0]
if len(targetLangParts) > 1 {
hasRegionalVariant = true
}

// Prepare translation request
id := getRandomNumber()
postData := &PostData{
Expand All @@ -169,17 +176,19 @@ func TranslateByDeepLX(sourceLang, targetLang, text string, tagHandling string,
ID: id,
Params: Params{
CommonJobParams: CommonJobParams{
Mode: "translate",
Mode: "translate",
RegionalVariant: map[bool]string{true: targetLang, false: ""}[hasRegionalVariant],
},
Lang: Lang{
SourceLangComputed: strings.ToUpper(sourceLang),
TargetLang: strings.ToUpper(targetLang),
TargetLang: strings.ToUpper(targetLangCode),
},
Jobs: jobs,
Priority: 1,
Timestamp: getTimeStamp(getICount(text)),
},
}
fmt.Println(postData)

// Make translation request
result, err := makeRequest(postData, "LMT_handle_jobs", proxyURL)
Expand Down
5 changes: 3 additions & 2 deletions translate/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author: Vincent Young
* @Date: 2024-09-16 11:59:24
* @LastEditors: Vincent Yang
* @LastEditTime: 2024-11-01 00:39:49
* @LastEditTime: 2024-11-01 12:47:47
* @FilePath: /DeepLX/translate/types.go
* @Telegram: https://t.me/missuo
* @GitHub: https://github.com/missuo
Expand All @@ -21,7 +21,8 @@ type Lang struct {

// CommonJobParams represents common parameters for translation jobs
type CommonJobParams struct {
Mode string `json:"mode"`
Mode string `json:"mode"`
RegionalVariant string `json:"regionalVariant"`
}

// Sentence represents a sentence in the translation request
Expand Down

0 comments on commit 9edb997

Please sign in to comment.