comparison Generic/win32Locale.py @ 15:2a13413dcc13

gettext on windows
author Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
date Sun, 02 Jan 2011 10:27:16 +0100
parents
children
comparison
equal deleted inserted replaced
14:d9e718bdee41 15:2a13413dcc13
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3 ## File win32Locale.py
4 ## This file is part of pyArq-Presupuestos.
5 ##
6 ## Copyright (C) 2010 Miguel Ángel Bárcena Rodríguez
7 ## <miguelangel@obraencurso.es>
8 ##
9 ## This file is based in i18n.py from QBzr - Qt frontend to Bazaar commands
10 ## Copyright (C) 2007 Lukáš Lalinský <lalinsky@gmail.com>
11 ## Copyright (C) 2007 Alexander Belchenko <bialix@ukr.net>
12 ##
13 ## pyArq-Presupuestos is free software: you can redistribute it and/or modify
14 ## it under the terms of the GNU General Public License as published by
15 ## the Free Software Foundation, either version 3 of the License, or
16 ## (at your option) any later version.
17 ##
18 ## pyArq-Presupuestos is distributed in the hope that it will be useful,
19 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ## GNU General Public License for more details.
22 ##
23 ## You should have received a copy of the GNU General Public License
24 ## along with this program. If not, see <http://www.gnu.org/licenses/>.
25
26 """win32 locale"""
27
28 import os
29 import sys
30
31 def check_win32_locale():
32 for i in ('LANGUAGE','LC_ALL','LC_MESSAGES','LANG'):
33 if os.environ.get(i):
34 break
35 else:
36 lang = None
37 import locale
38 try:
39 import ctypes
40 except ImportError:
41 # use only user's default locale
42 lang = locale.getdefaultlocale()[0]
43 else:
44 # using ctypes to determine all locales
45 lcid_user = ctypes.windll.kernel32.GetUserDefaultLCID()
46 lcid_system = ctypes.windll.kernel32.GetSystemDefaultLCID()
47 if lcid_user != lcid_system:
48 lcid = [lcid_user, lcid_system]
49 else:
50 lcid = [lcid_user]
51 lang = [locale.windows_locale.get(i) for i in lcid]
52 lang = ':'.join([i for i in lang if i])
53 # set lang code for gettext
54 if lang:
55 os.environ['LANGUAGE'] = lang