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