Skip to content

Commit

Permalink
print warning when add-ons access _ without importing it
Browse files Browse the repository at this point in the history
  • Loading branch information
dae committed Mar 4, 2019
1 parent da2ddcc commit 919738a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
7 changes: 5 additions & 2 deletions aqt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,11 @@ def setupLang(pm, app, force=None):
# gettext
_gtrans = gettext.translation(
'anki', dir, languages=[lang], fallback=True)
builtins.__dict__['_'] = _gtrans.gettext
builtins.__dict__['ngettext'] = _gtrans.ngettext
def fn(*args):
print("accessing _ and ngettext without importing from anki.lang will break in the future")
print("".join(traceback.format_stack()[-2]))
builtins.__dict__['_'] = fn
builtins.__dict__['ngettext'] = fn
anki.lang.setLang(lang, local=False)
if lang in ("he","ar","fa"):
app.setLayoutDirection(Qt.RightToLeft)
Expand Down
4 changes: 0 additions & 4 deletions aqt/profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,10 +357,6 @@ def ensureProfile(self):
# On first run, allow the user to choose the default language

def _setDefaultLang(self):
# the dialog expects _ to be defined, but we're running before
# setupLang() has been called. so we create a dummy op for now
import builtins
builtins.__dict__['_'] = lambda x: x
# create dialog
class NoCloseDiag(QDialog):
def reject(self):
Expand Down

0 comments on commit 919738a

Please sign in to comment.