mirror of
https://github.com/OwO-Network/DeepLX.git
synced 2026-12-01 23:07:51 +00:00
fix(translate): map Chinese source codes to generic zh
DeepL only accepts the generic "zh" as a source hint; zh-Hans and zh-Hant are target-only script variants and are silently ignored when sent as source_lang. Ambiguous mixed-script Chinese therefore fell back to auto-detection, was detected as English and echoed back untranslated. ZH, ZH-HANS and ZH-HANT now resolve to "zh" for source_lang while the target mapping is unchanged. /v2/translate also reads source_lang (JSON and form) instead of always auto-detecting. Adds resolveSourceLang and resolveTargetLang tests. Fixes #239
This commit is contained in:
@@ -195,7 +195,8 @@ var targetLangMap = map[string]string{
|
||||
|
||||
// sourceLangMap is what the API accepts as `source_lang`. It is a
|
||||
// superset of targetLangMap: EN and PT are first-class source codes
|
||||
// mapping to the generic "en"/"pt".
|
||||
// mapping to the generic "en"/"pt", and the Chinese codes all map to the
|
||||
// generic "zh".
|
||||
var sourceLangMap = func() map[string]string {
|
||||
m := make(map[string]string, len(targetLangMap)+2)
|
||||
for k, v := range targetLangMap {
|
||||
@@ -203,6 +204,13 @@ var sourceLangMap = func() map[string]string {
|
||||
}
|
||||
m["EN"] = "en"
|
||||
m["PT"] = "pt"
|
||||
// DeepL's source codes are the generic language forms. zh-Hans/zh-Hant
|
||||
// are target-only script variants: sent as a source hint they are
|
||||
// silently ignored, so ambiguous mixed-script Chinese fell back to
|
||||
// auto-detection and came back untranslated (#239).
|
||||
m["ZH"] = "zh"
|
||||
m["ZH-HANS"] = "zh"
|
||||
m["ZH-HANT"] = "zh"
|
||||
return m
|
||||
}()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user