2022-08-11 17:36:54 +08:00
|
|
|
import gettext
|
|
|
|
from common.params import Params
|
|
|
|
|
|
|
|
locale_dir = "/data/openpilot/selfdrive/assets/locales"
|
|
|
|
# supported_language = ["en-US", "zh-TW", "zh-CN", "ja-JP", "ko-KR"]
|
|
|
|
supported_languages = {
|
2022-09-15 14:48:14 +08:00
|
|
|
"main_en": "en-US",
|
2022-08-11 17:36:54 +08:00
|
|
|
"main_zh-CHT": "zh-TW",
|
|
|
|
"main_zh-CHS": "zh-CN",
|
|
|
|
"main_ko": "ko-KR",
|
2022-11-30 17:29:13 +08:00
|
|
|
"main_ja": "ja-JP",
|
2022-12-30 15:48:08 +08:00
|
|
|
"main_de": "de-DE",
|
|
|
|
"main_pt-BR": "pt_BR",
|
2022-08-11 17:36:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
def events():
|
|
|
|
locale = Params().get("LanguageSetting", encoding='utf8')
|
2022-09-15 14:48:14 +08:00
|
|
|
try:
|
|
|
|
if locale is not None:
|
|
|
|
locale = supported_languages[locale.strip()]
|
|
|
|
else:
|
|
|
|
locale = "en-US"
|
|
|
|
except KeyError:
|
2022-08-11 17:36:54 +08:00
|
|
|
locale = "en-US"
|
|
|
|
i18n = gettext.translation("events", localedir=locale_dir, fallback=True, languages=[locale])
|
|
|
|
i18n.install()
|
|
|
|
return i18n.gettext
|