1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 import locale
25 import gettext
26 import os
27 import defs
28 import unicodedata
29
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
50
51 locale.setlocale(locale.LC_ALL, '')
52
53
54 if os.name == 'nt':
55 lang = os.getenv('LANG')
56 if lang is None:
57 default_lang = locale.getdefaultlocale()[0]
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
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