root/branches/0.3/src/mesk/i18n.py

Revision 662, 2.7 kB (checked in by nicfit, 2 years ago)

Removed attempt at devel dir po files, it never worked and forces testing install.

Line 
1 ################################################################################
2 #  Copyright (C) 2003-2004 Vincent Hanquez <tab@snarc.org>
3 #  Copyright (C) 2003-2006 Yann Le Boulanger <asterix@lagaule.org>
4 #  Copyright (C) 2006 Nikos Kouremenos <kourem@gmail.com>
5 #  Copyright (C) 2006 Travis Shirk <travis@pobox.com>
6 #
7 #  This program is free software; you can redistribute it and/or modify
8 #  it under the terms of the GNU General Public License as published by
9 #  the Free Software Foundation; either version 2 of the License, or
10 #  (at your option) any later version.
11 #
12 #  This program is distributed in the hope that it will be useful,
13 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
14 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 #  GNU General Public License for more details.
16 #
17 #  You should have received a copy of the GNU General Public License
18 #  along with this program; if not, write to the Free Software
19 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20 #
21 #  $Id$
22 ################################################################################
23
24 ### NOTE: Thanks to the Gajim <http://gajim.org/> project for this code
25
26 import os, sys
27
28 # WRT install environment, the dir containing lang mesk i18n files (dir/mesk)
29 DIR = '../../share/locale'
30 DIR = os.path.abspath(os.getcwd() + os.sep + DIR)
31
32 import locale, gettext
33 _translation = None
34 try:
35     # set '' so each part of the locale that should be modified is set
36     # according to the environment variables
37     locale.setlocale(locale.LC_ALL, '')
38     _translation = gettext.translation('mesk', DIR)
39 except Exception, ex:
40     _translation = gettext.NullTranslations()
41
42 def _(s):
43     if s == '':
44         return s
45     return _translation.ugettext(s)
46
47 def Q_(s):
48     # Qualified translatable strings
49     # Some strings are too ambiguous to be easily translated.
50     # so we must use as:
51     # s = Q_('?vcard:Unknown')
52     # widget.set_text(s)
53     # Q_() removes the ?vcard:
54     # but gettext while parsing the file detects ?vcard:Unknown as a whole
55     # string.
56     # translator can either put the ?vcard: part or no (easier for him/her to
57     # no) nothing fails
58     s = _(s)
59     if s[0] == '?':
60         s = s[s.find(':')+1:] # remove ?abc: part
61     return s
62
63 def ngettext(s_sing, s_plural, n, replace_sing = None, replace_plural = None):
64     '''use as:
65     i18n.ngettext('leave room %s', 'leave rooms %s', len(rooms), 'a', 'a, b, c')
66     in other words this is a hack to ngettext() to support %s %d etc..
67     '''
68     text = _translation.ungettext(s_sing, s_plural, n)
69     if n == 1 and replace_sing is not None:
70         text = text % replace_sing
71     elif n > 1 and replace_plural is not None:
72         text = text % replace_plural
73     return text
Note: See TracBrowser for help on using the browser.