1. TortoiseHg
  2. TortoiseHg
  3. thg


Yuya Nishihara  committed e4f58d0

i18n: provide a method to switch ui language programmatically

This changes i18n module to use class-based gettext API in order to switch
translation catalog.

  • Participants
  • Parent commits cea2125
  • Branches stable

Comments (0)

Files changed (1)

File tortoisehg/util/i18n.py

View file
  • Ignore whitespace
 # GNU General Public License version 2, incorporated herein by reference.
 import gettext, sys
-from gettext import gettext as _
 from tortoisehg.util import paths
-gettext.bindtextdomain("tortoisehg", paths.get_locale_path())
+def setlanguage(lang=None):
+    """Change translation catalog to the specified language"""
+    global t
+    opts = {}
+    if lang:
+        opts['languages'] = (lang,)
+    t = gettext.translation('tortoisehg', paths.get_locale_path(),
+                            fallback=True, **opts)
+def _(message):
+    return t.gettext(message)
 def agettext(message):
     """Translate message and convert to local encoding