~ubuntu-branches/ubuntu/trusty/openerp-client/trusty

« back to all changes in this revision

Viewing changes to bin/translate.py

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Baumann
  • Date: 2008-12-07 20:17:00 UTC
  • Revision ID: james.westby@ubuntu.com-20081207201700-a875pic3sd7xkoru
Tags: upstream-5.0.0~alpha
Import upstream version 5.0.0~alpha

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- encoding: utf-8 -*-
 
2
##############################################################################
 
3
#
 
4
#    OpenERP, Open Source Management Solution   
 
5
#    Copyright (C) 2004-2008 Tiny SPRL (<http://tiny.be>). All Rights Reserved
 
6
#    $Id$
 
7
#
 
8
#    This program is free software: you can redistribute it and/or modify
 
9
#    it under the terms of the GNU General Public License as published by
 
10
#    the Free Software Foundation, either version 3 of the License, or
 
11
#    (at your option) any later version.
 
12
#
 
13
#    This program is distributed in the hope that it will be useful,
 
14
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
#    GNU General Public License for more details.
 
17
#
 
18
#    You should have received a copy of the GNU General Public License
 
19
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
20
#
 
21
##############################################################################
 
22
 
 
23
import sys,os
 
24
import locale
 
25
import release
 
26
import gettext
 
27
import gtk
 
28
import logging
 
29
 
 
30
#from tools import call_log
 
31
#locale.setlocale = call_log(locale.setlocale)
 
32
#locale.getdefaultlocale = call_log(locale.getdefaultlocale)
 
33
 
 
34
_LOCALE2WIN32 = {
 
35
    "af_ZA":"Afrikaans_South Africa",
 
36
    "sq_AL":"Albanian_Albania",
 
37
    "ar_DZ":"Arabic_Algeria",
 
38
    "ar_BH":"Arabic_Bahrain",
 
39
    "ar_EG":"Arabic_Egypt",
 
40
    "ar_IQ":"Arabic_Iraq",
 
41
    "ar_JO":"Arabic_Jordan",
 
42
    "ar_KW":"Arabic_Kuwait",
 
43
    "ar_LB":"Arabic_Lebanon",
 
44
    "ar_LY":"Arabic_Libya",
 
45
    "ar_MA":"Arabic_Morocco",
 
46
    "ar_OM":"Arabic_Oman",
 
47
    "ar_QA":"Arabic_Qatar",
 
48
    "ar_SA":"Arabic_Saudi Arabia",
 
49
    "ar_SY":"Arabic_Syria",
 
50
    "ar_TN":"Arabic_Tunisia",
 
51
    "ar_YE":"Arabic_Yemen",
 
52
    "az_AZ":"Azeri (Cyrillic)_Azerbaijan",
 
53
    "az_AZ":"Azeri (Latin)_Azerbaijan",
 
54
    "eu_ES":"Basque_Spain",
 
55
    "be_BY":"Belarusian_Belarus",
 
56
    "bg_BG":"Bulgarian_Bulgaria",
 
57
    "ca_ES":"Catalan_Spain",
 
58
    "zh_HK":"Chinese_Hong Kong",
 
59
    "zh_MO":"Chinese_Macau",
 
60
    "zh_CN":"Chinese_People's Republic of China",
 
61
    "zh_SG":"Chinese_Singapore",
 
62
    "zh_TW":"Chinese_Taiwan",
 
63
    "hr_HR":"Croatian_Croatia",
 
64
    "cs_CZ":"Czech_Czech Republic",
 
65
    "da_DK":"Danish_Denmark",
 
66
    "nl_BE":"Dutch_Belgium",
 
67
    "nl_NL":"Dutch_Netherlands",
 
68
    "en_AU":"English_Australia",
 
69
    "en_BZ":"English_Belize",
 
70
    "en_CA":"English_Canada",
 
71
    "en_CB":"English_Caribbean",
 
72
    "en_IE":"English_Ireland",
 
73
    "en_JM":"English_Jamaica",
 
74
    "en_NZ":"English_New Zealand",
 
75
    "en_PH":"English_Republic of the Philippines",
 
76
    "en_ZA":"English_South Africa",
 
77
    "en_TT":"English_Trinidad y Tobago",
 
78
    "en_GB":"English_United Kingdom",
 
79
    "en_US":"English_United States",
 
80
    "en_ZW":"English_Zimbabwe",
 
81
    "et_EE":"Estonian_Estonia",
 
82
    "fo_FO":"Faeroese_Faeroe Islands",
 
83
    "fa_IR":"Farsi_Iran",
 
84
    "fi_FI":"Finnish_Finland",
 
85
    "fr_BE":"French_Belgium",
 
86
    "fr_CA":"French_Canada",
 
87
    "fr_FR":"French_France",
 
88
    "fr_LU":"French_Luxembourg",
 
89
    "fr_MC":"French_Principality of Monaco",
 
90
    "fr_CH":"French_Switzerland",
 
91
    "de_AT":"German_Austria",
 
92
    "de_DE":"German_Germany",
 
93
    "de_LI":"German_Liechtenstein",
 
94
    "de_LU":"German_Luxembourg",
 
95
    "de_CH":"German_Switzerland",
 
96
    "el_GR":"Greek_Greece",
 
97
    "iw_IL":"Hebrew_Israel",
 
98
    "hu_HU":"Hungarian_Hungary",
 
99
    "is_IS":"Icelandic_Iceland",
 
100
    "id_ID":"Indonesian_Indonesia",
 
101
    "it_IT":"Italian_Italy",
 
102
    "it_CH":"Italian_Switzerland",
 
103
    "ja_JP":"Japanese_Japan",
 
104
    "kk_KZ":"Kazakh_Kazakstan",
 
105
    "ko_KR":"Korean_Korea",
 
106
    "lv_LV":"Latvian_Latvia",
 
107
    "lt_LT":"Lithuanian_Lithuania",
 
108
    "mk_MK":"Macedonian_Former Yugoslav Republic of Macedonia",
 
109
    "ms_BN":"Malay_Brunei Darussalam",
 
110
    "ms_MY":"Malay_Malaysia",
 
111
    "no_NO":"Norwegian_Norway",
 
112
    "no_NO":"Norwegian (Bokm�l)_Norway",
 
113
    "nn_NO":"Norwegian-Nynorsk_Norway",
 
114
    "pl_PL":"Polish_Poland",
 
115
    "pt_BR":"Portuguese_Brazil",
 
116
    "pt_PT":"Portuguese_Portugal",
 
117
    "ro_RO":"Romanian_Romania",
 
118
    "ru_RU":"Russian_Russia",
 
119
    "sr_SP":"Serbian (Cyrillic)_Serbia",
 
120
    "sr_SP":"Serbian (Latin)_Serbia",
 
121
    "sk_SK":"Slovak_Slovakia",
 
122
    "sl_SI":"Slovenian_Slovenia",
 
123
    "es_AR":"Spanish_Argentina",
 
124
    "es_BO":"Spanish_Bolivia",
 
125
    "es_CL":"Spanish_Chile",
 
126
    "es_CO":"Spanish_Colombia",
 
127
    "es_CR":"Spanish_Costa Rica",
 
128
    "es_DO":"Spanish_Dominican Republic",
 
129
    "es_EC":"Spanish_Ecuador",
 
130
    "es_SV":"Spanish_El Salvador",
 
131
    "es_GT":"Spanish_Guatemala",
 
132
    "es_HN":"Spanish_Honduras",
 
133
    "es_MX":"Spanish_Mexico",
 
134
    "es_NI":"Spanish_Nicaragua",
 
135
    "es_PA":"Spanish_Panama",
 
136
    "es_PY":"Spanish_Paraguay",
 
137
    "es_PE":"Spanish_Peru",
 
138
    "es_PR":"Spanish_Puerto Rico",
 
139
    "es_ES":"Spanish_Spain",
 
140
    "es_UY":"Spanish_Uruguay",
 
141
    "es_VE":"Spanish_Venezuela",
 
142
    "sw_KE":"Swahili_Kenya",
 
143
    "sv_FI":"Swedish_Finland",
 
144
    "sv_SE":"Swedish_Sweden",
 
145
    "tt_TA":"Tatar_Tatarstan",
 
146
    "th_TH":"Thai_Thailand",
 
147
    "tr_TR":"Turkish_Turkey",
 
148
    "uk_UA":"Ukrainian_Ukraine",
 
149
    "ur_PK":"Urdu_Islamic Republic of Pakistan",
 
150
    "uz_UZ":"Uzbek_Republic of Uzbekistan",
 
151
    "vi_VN":"Vietnamese_Viet Nam",
 
152
}
 
153
 
 
154
def setlang(lang=None):
 
155
    APP = release.name
 
156
    DIR = os.path.join(os.getcwd(), os.path.dirname(sys.argv[0]), 'share/locale')
 
157
    if not os.path.isdir(DIR):
 
158
        DIR = os.path.join(sys.prefix, 'share/locale')
 
159
    if not os.path.isdir(DIR):
 
160
        gettext.install(APP, unicode=1)
 
161
        return False
 
162
    if lang:
 
163
        lc, encoding = locale.getdefaultlocale()
 
164
        if encoding == 'utf':
 
165
            encoding = 'UTF-8'
 
166
        if encoding == 'cp1252':
 
167
            encoding = '1252'
 
168
        if not encoding:
 
169
            encoding = 'UTF-8'
 
170
 
 
171
        lang2 = lang
 
172
        if os.name == 'nt':
 
173
            lang2 = _LOCALE2WIN32.get(lang, lang)
 
174
            os.environ['LANG'] = lang
 
175
        elif os.name == 'mac':
 
176
            encoding = 'UTF-8'
 
177
 
 
178
        lang_enc = lang2 + '.' + encoding
 
179
        try:
 
180
            locale.setlocale(locale.LC_ALL, lang_enc)
 
181
        except:
 
182
            logging.getLogger('translate').warning(
 
183
                    _('Unable to set locale %s') % lang_enc)
 
184
 
 
185
        lang = gettext.translation(APP, DIR, languages=[lang], fallback=True)
 
186
        lang.install(unicode=1)
 
187
    else:
 
188
        try:
 
189
            if os.name == 'nt':
 
190
                os.environ['LANG'] = ''
 
191
            locale.setlocale(locale.LC_ALL, '')
 
192
        except:
 
193
            logging.getLogger('translate').warning('Unable to set locale !')
 
194
        gettext.bindtextdomain(APP, DIR)
 
195
        gettext.textdomain(APP)
 
196
        gettext.install(APP, unicode=1)
 
197
    gtk.glade.bindtextdomain(APP, DIR)
 
198
 
 
199
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
 
200