URI: 
       ti18n.py - electrum - Electrum Bitcoin wallet
  HTML git clone https://git.parazyd.org/electrum
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
       ---
       ti18n.py (1104B)
       ---
            1 import gettext
            2 
            3 
            4 class _(str):
            5 
            6     observers = set()
            7     lang = None
            8 
            9     def __new__(cls, s):
           10         if _.lang is None:
           11             _.switch_lang('en')
           12         t = _.translate(s)
           13         o = super(_, cls).__new__(cls, t)
           14         o.source_text = s
           15         return o
           16 
           17     @staticmethod
           18     def translate(s, *args, **kwargs):
           19         return _.lang(s)
           20 
           21     @staticmethod
           22     def bind(label):
           23         try:
           24             _.observers.add(label)
           25         except:
           26             pass
           27         # garbage collection
           28         new = set()
           29         for label in _.observers:
           30             try:
           31                 new.add(label)
           32             except:
           33                 pass
           34         _.observers = new
           35 
           36     @staticmethod
           37     def switch_lang(lang):
           38         # get the right locales directory, and instanciate a gettext
           39         from electrum.i18n import LOCALE_DIR
           40         locales = gettext.translation('electrum', LOCALE_DIR, languages=[lang], fallback=True)
           41         _.lang = locales.gettext
           42         for label in _.observers:
           43             try:
           44                 label.text = _(label.text.source_text)
           45             except:
           46                 pass