Debian Codegraph @

lib/i18n.py

raw symbols SCIP
1 # -*- coding: utf-8 -*-
2 #
3 # QBrz - Qt frontend to Breezy commands
4 # Copyright (C) 2007 Lukáš Lalinský <[email protected]om>
5 # Copyright (C) 2007 Alexander Belchenko <[email protected]>
6 #
7 # This program is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU General Public License
9 # as published by the Free Software Foundation; either version 2
10 # of the License, or (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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
21 """I18N and L10N support"""
22
23 import gettext as _gettext
24 import os
25 import sys
26
27 _null_translation = _gettext.NullTranslations()
28 _translation = _null_translation
29
30
31 def gettext(s):
32 return _translation.gettext(s)
33
34
35 def ngettext(s, p, n):
36 return _translation.ngettext(s, p, n)
37
38
39 def N_(s):
40 return s
41
42
43 def install():
44 global _translation
45 if not os.environ.get('LANGUAGE'):
46 from breezy import config
47 lang = config.GlobalConfig().get_user_option('language')
48 if lang:
49 os.environ['LANGUAGE'] = lang
50 if sys.platform == 'win32':
51 _check_win32_locale()
52 _translation = _gettext.translation('qbrz', localedir=_get_locale_dir(), fallback=True)
53
54
55 def uninstall():
56 global _translation
57 _translation = _null_translation
58
59
60 def _get_locale_dir():
61 localedir = os.path.join(os.path.realpath(os.path.dirname(__file__)), '..', 'locale')
62 if sys.platform.startswith('linux'):
63 if not os.access(localedir, os.R_OK | os.X_OK):
64 localedir = '/usr/share/locale'
65 return localedir
66
67
68 def _check_win32_locale():
69 for i in ('LANGUAGE','LC_ALL','LC_MESSAGES','LANG'):
70 if os.environ.get(i):
71 break
72 else:
73 lang = None
74 import locale
75 try:
76 import ctypes
77 except ImportError:
78 # use only user's default locale
79 lang = locale.getdefaultlocale()[0]
80 else:
81 # using ctypes to determine all locales
82 lcid_user = ctypes.windll.kernel32.GetUserDefaultLCID()
83 lcid_system = ctypes.windll.kernel32.GetSystemDefaultLCID()
84 if lcid_user != lcid_system:
85 lcid = [lcid_user, lcid_system]
86 else:
87 lcid = [lcid_user]
88 lang = [locale.windows_locale.get(i) for i in lcid]
89 lang = ':'.join([i for i in lang if i])
90 # set lang code for gettext
91 if lang:
92 os.environ['LANGUAGE'] = lang
93
94
95 # additional strings for translation
96 if 0:
97 # file kinds
98 N_('file')
99 N_('directory')
100 N_('symlink')
101 # bugs status
102 N_('fixed')
103 # qcat titles for various file types
104 N_('View text file')
105 N_('View image file')
106 N_('View binary file')
107 N_('View symlink')
108 N_('View directory')
109 #
110 N_("No changes selected to commit")
111 N_("No changes selected to revert")