keep global i18n handlers working

the previous change broke the translations of copy&pasted anki code in
add-ons

should fix
https://anki.tenderapp.com/discussions/ankidesktop/32922-chinese-characters-in-the-main-window-when-setting-language-to-japanese#comment_47043676
This commit is contained in:
Damien Elmes 2019-03-07 18:34:22 +10:00
parent 0543df7dfa
commit 79660e41bb

View file

@ -137,12 +137,19 @@ def setupLang(pm, app, force=None):
# gettext
_gtrans = gettext.translation(
'anki', dir, languages=[lang], fallback=True)
def fn(arg, *args):
print("accessing _ and ngettext without importing from anki.lang will break in the future")
def fn__(arg):
print("accessing _ without importing from anki.lang will break in the future")
print("".join(traceback.format_stack()[-2]))
return arg
builtins.__dict__['_'] = fn
builtins.__dict__['ngettext'] = fn
from anki.lang import _
return _(arg)
def fn_ngettext(a, b, c):
print("accessing ngettext without importing from anki.lang will break in the future")
print("".join(traceback.format_stack()[-2]))
from anki.lang import ngettext
return ngettext(a, b, c)
builtins.__dict__['_'] = fn__
builtins.__dict__['ngettext'] = fn_ngettext
anki.lang.setLang(lang, local=False)
if lang in ("he","ar","fa"):
app.setLayoutDirection(Qt.RightToLeft)