Package common :: Module i18n
[hide private]
[frames] | no frames]

Source Code for Module common.i18n

  1  # -*- coding:utf-8 -*- 
  2  ## src/common/i18n.py 
  3  ## 
  4  ## Copyright (C) 2003-2010 Yann Leboulanger <asterix AT lagaule.org> 
  5  ## Copyright (C) 2004 Vincent Hanquez <tab AT snarc.org> 
  6  ## Copyright (C) 2005-2006 Nikos Kouremenos <kourem AT gmail.com> 
  7  ## Copyright (C) 2009 Benjamin Richter <br AT waldteufel-online.net> 
  8  ## 
  9  ## This file is part of Gajim. 
 10  ## 
 11  ## Gajim is free software; you can redistribute it and/or modify 
 12  ## it under the terms of the GNU General Public License as published 
 13  ## by the Free Software Foundation; version 3 only. 
 14  ## 
 15  ## Gajim is distributed in the hope that it will be useful, 
 16  ## but WITHOUT ANY WARRANTY; without even the implied warranty of 
 17  ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
 18  ## GNU General Public License for more details. 
 19  ## 
 20  ## You should have received a copy of the GNU General Public License 
 21  ## along with Gajim. If not, see <http://www.gnu.org/licenses/>. 
 22  ## 
 23   
 24  import locale 
 25  import gettext 
 26  import os 
 27  import defs 
 28  import unicodedata 
 29   
30 -def paragraph_direction_mark(text):
31 """ 32 Determine paragraph writing direction according to 33 http://www.unicode.org/reports/tr9/#The_Paragraph_Level 34 35 Returns either Unicode LTR mark or RTL mark. 36 """ 37 for char in text: 38 bidi = unicodedata.bidirectional(char) 39 if bidi == 'L': 40 return u'\u200E' 41 elif bidi == 'AL' or bidi == 'R': 42 return u'\u200F' 43 44 return u'\u200E'
45 46 APP = 'gajim' 47 DIR = defs.localedir 48 49 # set '' so each part of the locale that should be modified is set 50 # according to the environment variables 51 locale.setlocale(locale.LC_ALL, '') 52 53 ## For windows: set, if needed, a value in LANG environmental variable ## 54 if os.name == 'nt': 55 lang = os.getenv('LANG') 56 if lang is None: 57 default_lang = locale.getdefaultlocale()[0] # en_US, fr_FR, el_GR etc.. 58 if default_lang: 59 lang = default_lang 60 61 if lang: 62 os.environ['LANG'] = lang 63 64 gettext.install(APP, DIR, unicode = True) 65 if gettext._translations: 66 _translation = gettext._translations.values()[0] 67 else: 68 _translation = gettext.NullTranslations() 69
70 -def Q_(text):
71 """ 72 Translate the given text, optionally qualified with a special 73 construction, which will help translators to disambiguate between 74 same terms, but in different contexts. 75 76 When translated text is returned - this rudimentary construction 77 will be stripped off, if it's present. 78 79 Here is the construction to use: 80 Q_("?vcard:Unknown") 81 82 Everything between ? and : - is the qualifier to convey the context 83 to the translators. Everything after : - is the text itself. 84 """ 85 text = _(text) 86 if text.startswith('?'): 87 qualifier, text = text.split(':', 1) 88 return text
89
90 -def ngettext(s_sing, s_plural, n, replace_sing = None, replace_plural = None):
91 """ 92 Use as: 93 i18n.ngettext('leave room %s', 'leave rooms %s', len(rooms), 'a', 'a, b, c') 94 95 In other words this is a hack to ngettext() to support %s %d etc.. 96 """ 97 text = _translation.ungettext(s_sing, s_plural, n) 98 if n == 1 and replace_sing is not None: 99 text = text % replace_sing 100 elif n > 1 and replace_plural is not None: 101 text = text % replace_plural 102 return text
103