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