home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_1381 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  1.1 KB  |  30 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. __license__ = 'GPL v3'
  5. __copyright__ = '2008, Marshall T. Vandegrift <llasram@gmail.com>'
  6. import os
  7. from gettext import GNUTranslations
  8. from calibre.utils.localization import get_lc_messages_path
  9. __all__ = [
  10.     'translate']
  11. _CACHE = { }
  12.  
  13. def translate(lang, text):
  14.     trans = None
  15.     if lang in _CACHE:
  16.         trans = _CACHE[lang]
  17.     else:
  18.         mpath = get_lc_messages_path(lang)
  19.         if mpath is not None:
  20.             p = os.path.join(mpath, 'messages.mo')
  21.             if os.path.exists(p):
  22.                 trans = GNUTranslations(open(p, 'rb'))
  23.                 _CACHE[lang] = trans
  24.             
  25.         
  26.     if trans is None:
  27.         return getattr(__builtins__, '_', (lambda x: x))(text)
  28.     return trans.ugettext(text)
  29.  
  30.