From 79660e41bb9fe5691bd5ec0506eaf72daafbc8a4 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Thu, 7 Mar 2019 18:34:22 +1000 Subject: [PATCH] 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 --- aqt/__init__.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/aqt/__init__.py b/aqt/__init__.py index ae64af076..073ebe771 100644 --- a/aqt/__init__.py +++ b/aqt/__init__.py @@ -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)