Package entropy :: Module i18n

Source Code for Module entropy.i18n

 1  # -*- coding: utf-8 -*- 
 2  """ 
 3   
 4      @author: Fabio Erculiani <lxnay@sabayonlinux.org> 
 5      @contact: lxnay@sabayonlinux.org 
 6      @copyright: Fabio Erculiani 
 7      @license: GPL-2 
 8   
 9      B{Entropy Framework internationalization module} 
10   
11      This module contains Entropy Framework i18n functions and 
12      variables. 
13   
14  """ 
15   
16  import os 
17  _LOCALE = None 
18  _LOCALE_FULL = os.getenv('LC_ALL') 
19  if _LOCALE_FULL == None: 
20      _LOCALE_FULL = os.getenv('LANG') 
21  if _LOCALE_FULL == None: 
22      _LOCALE_FULL = os.getenv('LANGUAGE') 
23   
24  if _LOCALE_FULL: 
25      _LOCALE = _LOCALE_FULL.split('.')[0] 
26      _LOCALE = _LOCALE.split('_')[0] 
27      _LOCALE = _LOCALE.lower() 
28   
29  try: 
30      import gettext 
31      gettext.bindtextdomain('entropy', '/usr/share/locale') 
32      gettext.textdomain('entropy') 
33      gettext.install('entropy', unicode=True) 
34      # thanks weirdness! 
35      _ = gettext.gettext 
36  except (ImportError,OSError,): 
37 - def _(raw_string):
38 """ 39 Fallback in case gettext is not available, same syntax 40 for the gettext provided function. 41 42 @param raw_string: raw untranslated string 43 @type raw_string: string 44 @return: translated string using environment locale 45 setting (LC_ALL, LANG or LANGUAGE) 46 @rtype: string 47 """ 48 return raw_string
49