2
# -*- coding: utf-8 -*-
4
# Copyright 2007 World Wide Workshop Foundation
6
# This program is free software; you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation; either version 2 of the License, or
9
# (at your option) any later version.
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU General Public License for more details.
16
# You should have received a copy of the GNU General Public License
17
# along with this program; if not, write to the Free Software
18
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
# If you find this activity useful or end up using parts of it in one of your
21
# own creations we would love to hear from you at info@WorldWideWorkshop.org !
32
# Images were taken from http://www.sodipodi.com/
33
# except for korea taken from http://zh.wikipedia.org/wiki/Image:Unification_flag_of_Korea.svg
36
'zh_cn':(None, _('Chinese (simplified)'), 'china'),
37
'zh_tw':(None, _('Chinese (traditional)'), 'china'),
38
'cs':(None, _('Czech'),'czech_republic'),
39
'da':(None, _('Danish'),'denmark'),
40
'nl':(None, _('Dutch'), 'netherlands'),
41
'en':('English', _('English'),'united_states'),
42
'en_gb':('English', _('English - Great Britain'),'united_kingdom'),
43
'en_us':('English', _('English - U.S.'),'united_states'),
44
'fi':(None, _('Finnish'),'finland'),
45
'fr':('Français', _('French'),'france'),
46
'de':(None, _('German'),'germany'),
47
'hu':(None, _('Hungarian'),'hungary'),
48
'it':(None, _('Italian'),'italy'),
49
'ja':(None, _('Japanese'),'japan'),
50
'ko':(None, _('Korean'),'korea'),
51
'no':(None, _('Norwegian'),'norway'),
52
'pl':(None, _('Polish'),'poland'),
53
'pt':('Português', _('Portuguese'),'portugal'),
54
'pt_br':('Português do Brasil', _('Portuguese - Brazilian'),'brazil'),
55
'ru':(None, _('Russian'),'russian_federation'),
56
'sk':(None, _('Slovak'),'slovenia'),
57
'es':('Español', _('Spanish'),'spain'),
58
'sv':(None, _('Swedish'),'sweden'),
59
'tr':(None, _('Turkish'),'turkey'),
62
class LangDetails (object):
63
def __init__ (self, code, name, image, domain):
65
self.country_code = self.code.split('_')[0]
70
def guess_translation (self, fallback=False):
72
self.gnutranslation = gettext.translation(self.domain, 'locale',
73
languages=[self.code], fallback=fallback)
79
self.gnutranslation.install()
81
def matches (self, code, exact=True):
83
return code.lower() == self.code.lower()
84
return code.split('_')[0].lower() == self.country_code.lower()
86
def get_lang_details (lang, domain):
87
mapping = lang_name_mapping.get(lang.lower(), None)
89
# Try just the country code
90
lang = lang.split('_')[0]
91
mapping = lang_name_mapping.get(lang.lower(), None)
94
if mapping[0] is None:
95
return LangDetails(lang, mapping[1], mapping[2], domain)
96
return LangDetails(lang, mapping[0], mapping[2], domain)
98
def list_available_translations (domain):
99
rv = [get_lang_details('en', domain)]
100
rv[0].guess_translation(True)
101
if not os.path.isdir('locale'):
103
for i,x in enumerate([x for x in os.listdir('locale') if os.path.isdir('locale/' + x) and not x.startswith('.')]):
105
details = get_lang_details(x, domain)
106
if details is not None:
107
if details.guess_translation():
114
class LanguageComboBox (gtk.ComboBox):
115
def __init__ (self, domain):
116
liststore = gtk.ListStore(gobject.TYPE_STRING)
117
gtk.ComboBox.__init__(self, liststore)
119
self.cell = gtk.CellRendererText()
120
self.pack_start(self.cell, True)
121
self.add_attribute(self.cell, 'text', 0)
123
self.translations = list_available_translations(domain)
124
for i,x in enumerate(self.translations):
125
liststore.insert(i+1, (gettext.gettext(x.name), ))
126
self.connect('changed', self.install)
128
def modify_bg (self, state, color):
129
setattr(self.cell, 'background-gdk',color)
130
setattr(self.cell, 'background-set',True)
132
def install (self, *args):
133
if self.get_active() > -1:
134
self.translations[self.get_active()].install()
136
code, encoding = locale.getdefaultlocale()
139
# Try to find the exact translation
140
for i,t in enumerate(self.translations):
144
if self.get_active() < 0:
145
# Failed, try to get the translation based only in the country
146
for i,t in enumerate(self.translations):
147
if t.matches(code, False):
150
if self.get_active() < 0:
151
# nothing found, select first translation
153
# Allow for other callbacks
157
def gather_other_translations ():
158
from glob import glob
159
lessons = filter(lambda x: os.path.isdir(x), glob('lessons/*'))
160
lessons = map(lambda x: os.path.basename(x), lessons)
161
lessons = map(lambda x: x[0].isdigit() and x[1:] or x, lessons)
162
images = filter(lambda x: os.path.isdir(x), glob('images/*'))
163
images = map(lambda x: os.path.basename(x), images)
164
f = file('i18n_misc_strings.py', 'w')
165
for e in images+lessons:
166
f.write('_("%s")\n' % e)