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>
9 ## This file is part of Gajim.
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.
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.
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/>.
30 def paragraph_direction_mark(text
):
32 Determine paragraph writing direction according to
33 http://www.unicode.org/reports/tr9/#The_Paragraph_Level
35 Returns either Unicode LTR mark or RTL mark.
38 bidi
= unicodedata
.bidirectional(char
)
41 elif bidi
== 'AL' or bidi
== 'R':
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
, '')
53 ## For windows: set, if needed, a value in LANG environmental variable ##
55 lang
= os
.getenv('LANG')
57 default_lang
= locale
.getdefaultlocale()[0] # en_US, fr_FR, el_GR etc..
62 os
.environ
['LANG'] = lang
64 gettext
.install(APP
, DIR
, unicode = True)
65 if gettext
._translations
:
66 _translation
= gettext
._translations
.values()[0]
68 _translation
= gettext
.NullTranslations()
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.
76 When translated text is returned - this rudimentary construction
77 will be stripped off, if it's present.
79 Here is the construction to use:
82 Everything between ? and : - is the qualifier to convey the context
83 to the translators. Everything after : - is the text itself.
86 if text
.startswith('?'):
87 qualifier
, text
= text
.split(':', 1)
90 def ngettext(s_sing
, s_plural
, n
, replace_sing
= None, replace_plural
= None):
93 i18n.ngettext('leave room %s', 'leave rooms %s', len(rooms), 'a', 'a, b, c')
95 In other words this is a hack to ngettext() to support %s %d etc..
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