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 ALL USERS: Make sure you rebuild the UI every time you git pull, otherwise you
will get errors down the road. will get errors down the road.
The translations are stored in a bazaar repo for integration with Launchpad's If you want to use a language other than English, copy the locale/ folder
translation services. If you want to use a language other than English: from a source tarball into the root of the repo.
$ 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
And now you're ready to run Anki: And now you're ready to run Anki:
$ ./runanki $ ./runanki

View file

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

View file

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

View file

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