use locales instead of two digit lang codes

and move away from launchpad
This commit is contained in:
Damien Elmes 2019-09-23 21:18:03 +10:00
parent df3314ff79
commit 241b7ea005
4 changed files with 104 additions and 63 deletions

View file

@ -42,15 +42,8 @@ the top and check the requirements again.
ALL USERS: Make sure you rebuild the UI every time you git pull, otherwise you
will get errors down the road.
The translations are stored in a bazaar repo for integration with Launchpad's
translation services. If you want to use a language other than English:
$ cd ..
$ mv anki dtop # i18n code expects anki folder to be called dtop
$ bzr branch lp:anki i18n
$ cd i18n
$ ./update-mos.sh
$ cd ../dtop
If you want to use a language other than English, copy the locale/ folder
from a source tarball into the root of the repo.
And now you're ready to run Anki:
$ ./runanki

View file

@ -6,58 +6,101 @@ import os, sys, re
import gettext
import threading
langs = [
("Afrikaans", "af"),
("Bahasa Melayu", "ms"),
("Català", "ca"),
("Dansk", "da"),
("Deutsch", "de"),
("Eesti", "et"),
("English", "en"),
("Español", "es"),
("Esperanto", "eo"),
("Euskara", "eu"),
("Français", "fr"),
("Galego", "gl"),
("Hrvatski", "hr"),
("Interlingua", "ia"),
("Italiano", "it"),
langs = sorted([
("Afrikaans", "af_ZA"),
("Bahasa Melayu", "ms_MY"),
("Català", "ca_ES"),
("Dansk", "da_DK"),
("Deutsch", "de_DE"),
("Eesti", "et_EE"),
("English (United States)", "en_US"),
("English (United Kingdom)", "en_GB"),
("Español", "es_ES"),
("Esperanto", "eo_UY"),
("Euskara", "eu_ES"),
("Français", "fr_FR"),
("Galego", "gl_ES"),
("Hrvatski", "hr_HR"),
("Italiano", "it_IT"),
("lo jbobau", "jbo"),
("Lenga d'òc", "oc"),
("Magyar", "hu"),
("Nederlands","nl"),
("Norsk","nb"),
("Occitan","oc"),
("Plattdüütsch", "nds"),
("Polski", "pl"),
("Lenga d'òc", "oc_FR"),
("Magyar", "hu_HU"),
("Nederlands","nl_NL"),
("Norsk","nb_NO"),
("Polski", "pl_PL"),
("Português Brasileiro", "pt_BR"),
("Português", "pt"),
("Română", "ro"),
("Slovenčina", "sk"),
("Slovenščina", "sl"),
("Suomi", "fi"),
("Svenska", "sv"),
("Tiếng Việt", "vi"),
("Türkçe", "tr"),
("Português", "pt_PT"),
("Română", "ro_RO"),
("Slovenčina", "sk_SK"),
("Slovenščina", "sl_SI"),
("Suomi", "fi_FI"),
("Svenska", "sv_SE"),
("Tiếng Việt", "vi_VN"),
("Türkçe", "tr_TR"),
("简体中文", "zh_CN"),
("日本語", "ja"),
("日本語", "ja_JP"),
("繁體中文", "zh_TW"),
("한국어", "ko"),
("Čeština", "cs"),
("Ελληνικά", "el"),
("Ελληνικά", "el"),
("босански", "bs"),
("Български", "bg"),
("Монгол хэл","mn"),
("русский язык", "ru"),
("Српски", "sr"),
("українська мова", "uk"),
("Հայերեն", "hy"),
("עִבְרִית", "he"),
("العربية", "ar"),
("فارسی", "fa"),
("ภาษาไทย", "th"),
]
("한국어", "ko_KR"),
("Čeština", "cs_CZ"),
("Ελληνικά", "el_GR"),
("Български", "bg_BG"),
("Монгол хэл","mn_MN"),
("русский язык", "ru_RU"),
("Српски", "sr_SP"),
("українська мова", "uk_UA"),
("Հայերեն", "hy_AM"),
("עִבְרִית", "he_IL"),
("العربية", "ar_SA"),
("فارسی", "fa_IR"),
("ภาษาไทย", "th_TH"),
("Latin", "la_LA"),
])
# compatibility with old versions
compatMap = {
"af": "af_ZA",
"ar": "ar_SA",
"bg": "bg_BG",
"ca": "ca_ES",
"cs": "cs_CZ",
"da": "da_DK",
"de": "de_DE",
"el": "el_GR",
"en": "en_US",
"eo": "eo_UY",
"es": "es_ES",
"et": "et_EE",
"eu": "eu_ES",
"fa": "fa_IR",
"fi": "fi_FI",
"fr": "fr_FR",
"gl": "gl_ES",
"he": "he_IL",
"hr": "hr_HR",
"hu": "hu_HU",
"hy": "hy_AM",
"it": "it_IT",
"ja": "ja_JP",
"ko": "ko_KR",
"mn": "mn_MN",
"ms": "ms_MY",
"nl": "nl_NL",
"nb": "nb_NL",
"no": "nb_NL",
"oc": "oc_FR",
"pl": "pl_PL",
"pt": "pt_PT",
"ro": "ro_RO",
"ru": "ru_RU",
"sk": "sk_SK",
"sl": "sl_SI",
"sr": "sr_SP",
"sv": "sv_SE",
"th": "th_TH",
"tr": "tr_TR",
"uk": "uk_UA",
"vi": "vi_VN",
}
threadLocal = threading.local()
@ -92,6 +135,7 @@ def langDir():
return dir
def setLang(lang, local=True):
lang = mungeCode(lang)
trans = gettext.translation(
'anki', langDir(), languages=[lang], fallback=True)
if local:
@ -113,5 +157,12 @@ def noHint(str):
"Remove translation hint from end of string."
return re.sub(r"(^.*?)( ?\(.+?\))?$", "\\1", str)
def mungeCode(code):
code = code.replace("-", "_")
if code in compatMap:
code = compatMap[code]
return code
if not currentTranslation:
setLang("en_US", local=False)

View file

@ -58,7 +58,7 @@ class Preferences(QDialog):
try:
return codes.index(anki.lang.getLang())
except:
return codes.index("en")
return codes.index("en_US")
def onLangIdxChanged(self, idx):
code = anki.lang.langs[idx][1]

View file

@ -11,7 +11,6 @@ import pickle
import shutil
import io
import locale
import re
from aqt.qt import *
from anki.db import DB
@ -376,14 +375,12 @@ please see:
(lang, enc) = locale.getdefaultlocale()
except:
# fails on osx
lang = "en"
if lang and lang not in ("pt_BR", "zh_CN", "zh_TW"):
lang = re.sub("(.*)_.*", "\\1", lang)
lang = "en_US"
# find index
idx = None
en = None
for c, (name, code) in enumerate(anki.lang.langs):
if code == "en":
if code == "en_US":
en = c
if code == lang:
idx = c