Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/i18n.py
diff options
context:
space:
mode:
Diffstat (limited to 'i18n.py')
-rw-r--r--i18n.py65
1 files changed, 31 insertions, 34 deletions
diff --git a/i18n.py b/i18n.py
index ea6d687..963d258 100644
--- a/i18n.py
+++ b/i18n.py
@@ -1,8 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
-# Copyright 2007 World Wide Workshop Foundation
-#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
@@ -17,14 +15,18 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
-# If you find this activity useful or end up using parts of it in one of your
-# own creations we would love to hear from you at info@WorldWideWorkshop.org !
-#
+
+
+### i18n.py
+### TODO: Describe
+### $Id: $
+###
+### author: Carlos Neves (cn (at) sueste.net)
+### (c) 2007 World Wide Workshop Foundation
import os
import gettext
import locale
-import logging
import gtk, gobject
@@ -39,7 +41,6 @@ lang_name_mapping = {
'cs':(None, _('Czech'),'czech_republic'),
'da':(None, _('Danish'),'denmark'),
'nl':(None, _('Dutch'), 'netherlands'),
- 'af':(None, _('Afrikaans'), 'south_africa'),
'en':('English', _('English'),'united_states'),
'en_gb':('English', _('English - Great Britain'),'united_kingdom'),
'en_us':('English', _('English - U.S.'),'united_states'),
@@ -59,17 +60,19 @@ lang_name_mapping = {
'es':('EspaƱol', _('Spanish'),'spain'),
'sv':(None, _('Swedish'),'sweden'),
'tr':(None, _('Turkish'),'turkey'),
+ 'af':(None, _('Afrikaans'), 'south_africa'),
}
class LangDetails (object):
- def __init__ (self, code, name, image):
+ def __init__ (self, code, name, image, domain):
self.code = code
self.country_code = self.code.split('_')[0]
self.name = name
self.image = image
+ self.domain = domain
def guess_translation (self, fallback=False):
- self.gnutranslation = gettext.translation('JokeMachine', './po', [self.code], fallback=fallback)
+ self.gnutranslation = gettext.translation(self.domain, 'locale', [self.code], fallback=fallback)
def install (self):
self.gnutranslation.install()
@@ -79,7 +82,7 @@ class LangDetails (object):
return code.lower() == self.code.lower()
return code.split('_')[0].lower() == self.country_code.lower()
-def get_lang_details (lang):
+def get_lang_details (lang, domain):
mapping = lang_name_mapping.get(lang.lower(), None)
if mapping is None:
# Try just the country code
@@ -88,15 +91,17 @@ def get_lang_details (lang):
if mapping is None:
return None
if mapping[0] is None:
- return LangDetails(lang, mapping[1], mapping[2])
- return LangDetails(lang, mapping[0], mapping[2])
+ return LangDetails(lang, mapping[1], mapping[2], domain)
+ return LangDetails(lang, mapping[0], mapping[2], domain)
-def list_available_translations ():
- rv = [get_lang_details('en')]
+def list_available_translations (domain):
+ rv = [get_lang_details('en', domain)]
rv[0].guess_translation(True)
- for i,x in enumerate([x for x in os.listdir('po') if os.path.isdir('po/' + x) and not x.startswith('.')]):
+ if not os.path.isdir('locale'):
+ return rv
+ for i,x in enumerate([x for x in os.listdir('locale') if os.path.isdir('locale/' + x) and not x.startswith('.')]):
try:
- details = get_lang_details(x)
+ details = get_lang_details(x, domain)
if details is not None:
details.guess_translation()
rv.append(details)
@@ -106,7 +111,7 @@ def list_available_translations ():
return rv
class LanguageComboBox (gtk.ComboBox):
- def __init__ (self):
+ def __init__ (self, domain):
liststore = gtk.ListStore(gobject.TYPE_STRING)
gtk.ComboBox.__init__(self, liststore)
@@ -114,7 +119,7 @@ class LanguageComboBox (gtk.ComboBox):
self.pack_start(self.cell, True)
self.add_attribute(self.cell, 'text', 0)
- self.translations = list_available_translations()
+ self.translations = list_available_translations(domain)
for i,x in enumerate(self.translations):
liststore.insert(i+1, (gettext.gettext(x.name), ))
self.connect('changed', self.install)
@@ -125,19 +130,11 @@ class LanguageComboBox (gtk.ComboBox):
def install (self, *args):
if self.get_active() > -1:
- translation = self.translations[self.get_active()]
- logging.debug('i18n - Installing locale: %r %r - %r',
- translation.code,
- translation.country_code,
- translation.name)
- translation.install()
+ self.translations[self.get_active()].install()
else:
code, encoding = locale.getdefaultlocale()
- logging.debug('Locale code: %r' % code)
if code is None:
- locale.setlocale(locale.LC_ALL, 'en_US')
- code, encoding = locale.getlocale()
-
+ code = 'en'
# Try to find the exact translation
for i,t in enumerate(self.translations):
if t.matches(code):
@@ -158,13 +155,13 @@ class LanguageComboBox (gtk.ComboBox):
###
def gather_other_translations ():
from glob import glob
- entries = filter(lambda x: os.path.isdir(x), glob('images/*'))
- entries.extend(filter(lambda x: os.path.isdir(x), glob('lessons/*')))
- entries = map(lambda x: os.path.basename(x), entries)
+ lessons = filter(lambda x: os.path.isdir(x), glob('lessons/*'))
+ lessons = map(lambda x: os.path.basename(x), lessons)
+ lessons = map(lambda x: x[0].isdigit() and x[1:] or x, lessons)
+ images = filter(lambda x: os.path.isdir(x), glob('images/*'))
+ images = map(lambda x: os.path.basename(x), images)
f = file('i18n_misc_strings.py', 'w')
- for e in entries:
+ for e in images+lessons:
f.write('_("%s")\n' % e)
f.close()
-if __name__ == '__main__':
- gather_other_translations()