# HG changeset patch # User Miguel Ángel Bárcena Rodríguez # Date 1293960436 -3600 # Node ID 2a13413dcc1335472c0ad3f23b72cc1bf2984a3b # Parent d9e718bdee417ba3035bef91135acca28625fe86 gettext on windows diff -r d9e718bdee41 -r 2a13413dcc13 Generic/win32Locale.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Generic/win32Locale.py Sun Jan 02 10:27:16 2011 +0100 @@ -0,0 +1,55 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +## File win32Locale.py +## This file is part of pyArq-Presupuestos. +## +## Copyright (C) 2010 Miguel Ángel Bárcena Rodríguez +## +## +## This file is based in i18n.py from QBzr - Qt frontend to Bazaar commands +## Copyright (C) 2007 Lukáš Lalinský +## Copyright (C) 2007 Alexander Belchenko +## +## pyArq-Presupuestos is free software: you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation, either version 3 of the License, or +## (at your option) any later version. +## +## pyArq-Presupuestos is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program. If not, see . + +"""win32 locale""" + +import os +import sys + +def check_win32_locale(): + for i in ('LANGUAGE','LC_ALL','LC_MESSAGES','LANG'): + if os.environ.get(i): + break + else: + lang = None + import locale + try: + import ctypes + except ImportError: + # use only user's default locale + lang = locale.getdefaultlocale()[0] + else: + # using ctypes to determine all locales + lcid_user = ctypes.windll.kernel32.GetUserDefaultLCID() + lcid_system = ctypes.windll.kernel32.GetSystemDefaultLCID() + if lcid_user != lcid_system: + lcid = [lcid_user, lcid_system] + else: + lcid = [lcid_user] + lang = [locale.windows_locale.get(i) for i in lcid] + lang = ':'.join([i for i in lang if i]) + # set lang code for gettext + if lang: + os.environ['LANGUAGE'] = lang diff -r d9e718bdee41 -r 2a13413dcc13 pyArq-Presupuestos.py --- a/pyArq-Presupuestos.py Sat Jan 01 20:09:02 2011 +0100 +++ b/pyArq-Presupuestos.py Sun Jan 02 10:27:16 2011 +0100 @@ -19,6 +19,18 @@ ## You should have received a copy of the GNU General Public License ## along with this program. If not, see . +# Modules +import sys +import gettext +# pyArq-Presupuestos modules +from Generic import globalVars +from Generic import win32Locale + +def _take_APPDATA_path(): + # take path to find mo file + _path = sys.path[0] + globalVars.path["APPDATA"]= _path + def _translate(): """def translate() @@ -26,6 +38,8 @@ """ _app = "pyArq-Presupuestos" _dir = globalVars.path["APPDATA"] + "/mo/" + if sys.platform == 'win32': + win32Locale.check_win32_locale() gettext.install(_app, _dir, unicode=1) def _run_gui(): @@ -33,17 +47,11 @@ Shows main window and starts the GTK+ event processing loop. """ + from Gtk import gui _window = gui.MainWindow() # Run pyArq-Presupuestos if __name__ == "__main__": - # Modules - import gettext - import sys - from Generic import globalVars - # take path to find mo file - _path = sys.path[0] - globalVars.path["APPDATA"]= _path + _take_APPDATA_path() _translate() - from Gtk import gui _run_gui()