Permalink
Browse files

Use languages names instead of codes on preferences.

Refs #1122
  • Loading branch information...
1 parent 21fdb35 commit 41d0beaf5ef26fb7917ae5a1dc6b40a564ca3853 @arielj arielj committed Apr 6, 2012
Showing with 56 additions and 10 deletions.
  1. +28 −7 emesene/Language.py
  2. +28 −3 emesene/gui/gtkui/Preferences.py
View
@@ -32,6 +32,30 @@ class Language(object):
DESCRIPTION = 'Language management module'
AUTHOR = 'Lucas F. Ottaviano (lfottaviano)'
WEBSITE = 'www.emesene.org'
+ LANGUAGES_DICT = {'af':'Afrikaans','ar':'Arabic','ast':'Asturian', \
+ 'az':'Azerbaijani','bg':'Bulgarian','bn':'Bengali','bs':'Bosnian', \
+ 'ca':'Catalan','cs':'Czech','da':'Danish','de':'German','dv':'Divehi', \
+ 'el':'Greek','en':'English','en_AU':'English(Australia)', \
+ 'en_CA':'English(Canada)','en_GB':'English(United Kingdom)', \
+ 'eo':'Esperanto','es':'Espa\xc3\xb1ol','et':'Estonian','eu':'Basque', \
+ 'fi':'Finnish','fil':'Filipino','fo':'Faroese','fr':'French', \
+ 'ga':'Irish','gl':'Galician','gv':'Manx','he':'Hebrew','hr':'Croatian', \
+ 'hu':'Hungarian','ia':'Interlingua','id':'Indonesian','is':'Icelandic', \
+ 'it':'Italian','ja':'Japanese','kab':'Kabyle','kn':'Kannada', \
+ 'ko':'Korean','ku':'Kurdish','la':'Latin','lb':'Luxembourgish', \
+ 'lt':'Lithuanian','lv':'Latvian','mk':'Macedonian','ms':'Malay', \
+ 'nan':'Min Nan Chinese','nb':'Norwegian Bokmal','nds':'Low German', \
+ 'nl':'Dutch','nn':'Norwegian Nynorsk','oc':'Occitan (post 1500)', \
+ 'pl':'Polish','pt':'Portuguese','pt_BR':'Brazilian Portuguese', \
+ 'ro':'Romanian','ru':'Russian','sk':'Slovak','sl':'Slovenian', \
+ 'sq':'Albanian','sr':'Serbian','sv':'Swedish','ta':'Tamil','th':'Thai', \
+ 'tr':'Turkish','uk':'Ukrainian','vec':'Venetian', \
+ 'zh_CN':'Chinese (Simplified)','zh_HK':'Chinese (Hong Kong)', \
+ 'zh_TW':'Chinese (Traditional)'}
+
+ LANGUAGES_DICT_R = {}
+ for key,value in LANGUAGES_DICT.iteritems():
+ LANGUAGES_DICT_R[value] = key
def __init__(self):
""" constructor """
@@ -51,16 +75,12 @@ def install_desired_translation(self, language):
"""
self._lang = language
- if self._lang in self._languages:
+ try:
lfottaviano
lfottaviano Apr 6, 2012 Member

why this? haven't you synced your repo before pushing? I had eliminated all try excepts.

see file at: https://github.com/emesene/emesene/blob/4677adcf74946e26f7ef405404dab40030af406f/emesene/Language.py

arielj
arielj Apr 7, 2012 Member

yes, I synced it, I just didn't realized you used that fallback=True thing :P

I will refactor it again then

self._translation = gettext.translation('emesene',
localedir=self._locales_path,
languages=[self._lang])
- else:
- try:
- self._translation = gettext.translation('emesene',
- localedir=self._locales_path)
- except IOError:
- self._translation = gettext.NullTranslations()
+ except IOError:
+ self._translation = gettext.NullTranslations()
self._translation.install()
@@ -109,6 +129,7 @@ def _get_languages_list(self):
'LC_MESSAGES', 'emesene.mo'))
self._languages = [path.split(os.path.sep)[-3] for path in paths]
+ self._languages.append('en')
self._languages.sort()
return self._languages
@@ -1130,9 +1130,31 @@ def __init__(self, session):
'language_config')
self.add_text(_("Select language:"), 0, 3, True)
- self.languages_cb = self.create_combo(
- self._language_management.get_available_languages,
- 'session.config.language_config' )
+ self.languages_cb = gtk.combo_box_new_text()
+
+ default = None
+ index = 0
+
+ lang_dict_r = self._language_management.LANGUAGES_DICT_R
+ for lang in sorted(lang_dict_r.keys()):
+ self.languages_cb.append_text(lang)
+ if lang_dict_r[lang] == self.session.config.language_config:
+ default = index
+ index += 1
+
+ #in case we have some new language and it's not already on the DICT
+ for lang in self._language_management.get_available_languages():
+ if lang not in self._language_management.LANGUAGES_DICT.keys():
+ self.languages_cb.append_text(lang)
+ lang_dict_r[lang] = lang
+ if lang == self.session.config.language_config:
+ default = index
+ index += 1
+
+ self.languages_cb.set_active(default)
+ self.languages_cb.connect('changed', self.on_language_combo_changed, \
+ 'session.config.language_config',
+ lang_dict_r)
self.attach(self.languages_cb, 2, 3, 3, 4, gtk.EXPAND|gtk.FILL, 0)
@@ -1161,6 +1183,9 @@ def on_path_selected(f_chooser):
def _on_language_changed(self, lang):
self._language_management.install_desired_translation(lang)
+
+ def on_language_combo_changed(self, combo, property_name, values):
+ self.set_attr(property_name, values[combo.get_active_text()])
class MSNPapylib(BaseTable):

0 comments on commit 41d0bea

Please sign in to comment.