transcribe: keep Chinese script variants distinct
'zh-Hant' was stripped to 'zh' and silently produced Simplified output. Map the script variants explicitly and let FLORES-200 tags pass through to NLLB, which validates them itself.
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
import re
|
||||
from typing import Optional
|
||||
|
||||
import aiohttp
|
||||
@@ -82,9 +83,21 @@ LANGUAGE_LABELS = {
|
||||
"tk": "Turkmen", "tl": "Tagalog", "tr": "Turkish", "tt": "Tatar",
|
||||
"uk": "Ukrainian", "ur": "Urdu", "uz": "Uzbek", "vi": "Vietnamese",
|
||||
"yi": "Yiddish", "yo": "Yoruba", "yue": "Cantonese", "zh": "Chinese",
|
||||
"zho_Hans": "Simplified Chinese", "zho_Hant": "Traditional Chinese",
|
||||
"zu": "Zulu",
|
||||
}
|
||||
|
||||
# Script variants that a bare ISO code would flatten into the wrong script.
|
||||
SCRIPT_VARIANTS = {
|
||||
"zh-hant": "zho_Hant", "zh-tw": "zho_Hant", "zh-hk": "zho_Hant",
|
||||
"traditional chinese": "zho_Hant", "cantonese traditional": "yue_Hant",
|
||||
"zh-hans": "zho_Hans", "zh-cn": "zho_Hans", "zh-sg": "zho_Hans",
|
||||
"simplified chinese": "zho_Hans",
|
||||
}
|
||||
|
||||
# NLLB also accepts FLORES-200 tags directly; pass those straight through.
|
||||
FLORES_TAG = re.compile(r"^[a-z]{3}_[A-Z][a-z]{3}$")
|
||||
|
||||
|
||||
class ServiceError(Exception):
|
||||
"""Raised when a local transcription/translation service misbehaves."""
|
||||
@@ -201,6 +214,11 @@ class Transcribe(commands.Cog):
|
||||
token = raw.strip().lower().replace("_", " ")
|
||||
if token in LANGUAGE_NAMES:
|
||||
return LANGUAGE_NAMES[token]
|
||||
variant = SCRIPT_VARIANTS.get(raw.strip().lower())
|
||||
if variant:
|
||||
return variant
|
||||
if FLORES_TAG.match(raw.strip()):
|
||||
return raw.strip()
|
||||
code = raw.strip().lower().split("-")[0]
|
||||
if code in LANGUAGE_LABELS:
|
||||
return code
|
||||
|
||||
Reference in New Issue
Block a user