bugfix with binary field and wizard
[openerp-client.git] / bin / translate.py
blobb589c47ac1c608f2716e5cc4dc96d5813a49d6db
1 # -*- encoding: utf-8 -*-
2 ##############################################################################
4 # Copyright (c) 2004-2008 TINY SPRL. (http://tiny.be) All Rights Reserved.
6 # $Id$
8 # WARNING: This program as such is intended to be used by professional
9 # programmers who take the whole responsability of assessing all potential
10 # consequences resulting from its eventual inadequacies and bugs
11 # End users who are looking for a ready-to-use solution with commercial
12 # garantees and support are strongly adviced to contract a Free Software
13 # Service Company
15 # This program is Free Software; you can redistribute it and/or
16 # modify it under the terms of the GNU General Public License
17 # as published by the Free Software Foundation; either version 2
18 # of the License, or (at your option) any later version.
20 # This program is distributed in the hope that it will be useful,
21 # but WITHOUT ANY WARRANTY; without even the implied warranty of
22 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 # GNU General Public License for more details.
25 # You should have received a copy of the GNU General Public License
26 # along with this program; if not, write to the Free Software
27 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29 ##############################################################################
31 import sys,os
32 import locale
33 import release
34 import gettext
35 import gtk
36 import logging
38 #from tools import call_log
39 #locale.setlocale = call_log(locale.setlocale)
40 #locale.getdefaultlocale = call_log(locale.getdefaultlocale)
42 _LOCALE2WIN32 = {
43 'af_ZA': 'Afrikaans_South Africa',
44 'sq_AL': 'Albanian_Albania',
45 'ar_SA': 'Arabic_Saudi Arabia',
46 'eu_ES': 'Basque_Spain',
47 'be_BY': 'Belarusian_Belarus',
48 'bs_BA': 'Serbian (Latin)',
49 'bg_BG': 'Bulgarian_Bulgaria',
50 'ca_ES': 'Catalan_Spain',
51 'hr_HR': 'Croatian_Croatia',
52 'zh_CN': 'Chinese_China',
53 'zh_TW': 'Chinese_Taiwan',
54 'cs_CZ': 'Czech_Czech Republic',
55 'da_DK': 'Danish_Denmark',
56 'nl_NL': 'Dutch_Netherlands',
57 'et_EE': 'Estonian_Estonia',
58 'fa_IR': 'Farsi_Iran',
59 'ph_PH': 'Filipino_Philippines',
60 'fi_FI': 'Finnish_Finland',
61 'fr_FR': 'French_France',
62 'fr_BE': 'French_France',
63 'fr_CH': 'French_France',
64 'fr_CA': 'French_France',
65 'ga': 'Scottish Gaelic',
66 'gl_ES': 'Galician_Spain',
67 'ka_GE': 'Georgian_Georgia',
68 'de_DE': 'German_Germany',
69 'el_GR': 'Greek_Greece',
70 'gu': 'Gujarati_India',
71 'he_IL': 'Hebrew_Israel',
72 'hi_IN': 'Hindi',
73 'hu': 'Hungarian_Hungary',
74 'is_IS': 'Icelandic_Iceland',
75 'id_ID': 'Indonesian_indonesia',
76 'it_IT': 'Italian_Italy',
77 'ja_JP': 'Japanese_Japan',
78 'kn_IN': 'Kannada',
79 'km_KH': 'Khmer',
80 'ko_KR': 'Korean_Korea',
81 'lo_LA': 'Lao_Laos',
82 'lt_LT': 'Lithuanian_Lithuania',
83 'lat': 'Latvian_Latvia',
84 'ml_IN': 'Malayalam_India',
85 'id_ID': 'Indonesian_indonesia',
86 'mi_NZ': 'Maori',
87 'mn': 'Cyrillic_Mongolian',
88 'no_NO': 'Norwegian_Norway',
89 'nn_NO': 'Norwegian-Nynorsk_Norway',
90 'pl': 'Polish_Poland',
91 'pt_PT': 'Portuguese_Portugal',
92 'pt_BR': 'Portuguese_Brazil',
93 'ro_RO': 'Romanian_Romania',
94 'ru_RU': 'Russian_Russia',
95 'mi_NZ': 'Maori',
96 'sr_CS': 'Serbian (Cyrillic)_Serbia and Montenegro',
97 'sk_SK': 'Slovak_Slovakia',
98 'sl_SI': 'Slovenian_Slovenia',
99 'es_ES': 'Spanish_Spain',
100 'sv_SE': 'Swedish_Sweden',
101 'ta_IN': 'English_Australia',
102 'th_TH': 'Thai_Thailand',
103 'mi_NZ': 'Maori',
104 'tr_TR': 'Turkish_Turkey',
105 'uk_UA': 'Ukrainian_Ukraine',
106 'vi_VN': 'Vietnamese_Viet Nam',
109 def setlang(lang=None):
110 APP = release.name
111 DIR = os.path.join(os.getcwd(), os.path.dirname(sys.argv[0]), 'share/locale')
112 if not os.path.isdir(DIR):
113 DIR = os.path.join(sys.prefix, 'share/locale')
114 if not os.path.isdir(DIR):
115 gettext.install(APP, unicode=1)
116 return False
117 if lang:
118 lc, encoding = locale.getdefaultlocale()
119 if encoding == 'utf':
120 encoding = 'UTF-8'
121 if encoding == 'cp1252':
122 encoding = '1252'
123 if not encoding:
124 encoding = 'UTF-8'
126 lang2 = lang
127 if os.name == 'nt':
128 lang2 = _LOCALE2WIN32.get(lang, lang)
129 os.environ['LANG'] = lang
130 elif os.name == 'mac':
131 encoding = 'UTF-8'
133 lang_enc = lang2 + '.' + encoding
134 try:
135 locale.setlocale(locale.LC_ALL, lang_enc)
136 except:
137 logging.getLogger('translate').warning(
138 _('Unable to set locale %s') % lang_enc)
140 lang = gettext.translation(APP, DIR, languages=[lang], fallback=True)
141 lang.install(unicode=1)
142 else:
143 try:
144 if os.name == 'nt':
145 os.environ['LANG'] = ''
146 locale.setlocale(locale.LC_ALL, '')
147 except:
148 logging.getLogger('translate').warning('Unable to set locale !')
149 gettext.bindtextdomain(APP, DIR)
150 gettext.textdomain(APP)
151 gettext.install(APP, unicode=1)
152 gtk.glade.bindtextdomain(APP, DIR)
154 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: