[cc-commits] [SCM] Wrapper egg for the i18n checkout (branch master) updated. 538172f207b265de50e479e85cef92500ac629d7

git version control git at a7.creativecommons.org
Wed Mar 10 17:09:36 EST 2010


The branch, master has been updated
       via  538172f207b265de50e479e85cef92500ac629d7 (commit)
       via  6370cb457dbae741ee6e2937786b4dee3560761b (commit)
      from  53fdba3ac9b3f783610ad2cb2439eac71e9333e2 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 538172f207b265de50e479e85cef92500ac629d7
Author: Christopher Allan Webber <cwebber at dustycloud.org>
Date:   Wed Mar 10 16:09:32 2010 -0600

    Convenience method, ugettext_for_locale

commit 6370cb457dbae741ee6e2937786b4dee3560761b
Author: Christopher Allan Webber <cwebber at dustycloud.org>
Date:   Wed Mar 10 15:27:43 2010 -0600

    Make it so you can get a gettext object that matches the current locale

-----------------------------------------------------------------------

Summary of changes (followed by patch):
 cc/i18npkg/gettext_i18n.py |   29 ++++++++++++++++++++++++++++-
 1 files changed, 28 insertions(+), 1 deletions(-)

diff --git a/cc/i18npkg/gettext_i18n.py b/cc/i18npkg/gettext_i18n.py
index 360b99a..3cd4e74 100644
--- a/cc/i18npkg/gettext_i18n.py
+++ b/cc/i18npkg/gettext_i18n.py
@@ -1,7 +1,34 @@
+import os
 import gettext
 import pkg_resources
 
+
 MO_PATH = pkg_resources.resource_filename(
     'cc.i18npkg', 'mo')
 I18N_DOMAIN = 'cc_org'
-CCORG_GETTEXT = gettext.translation(I18N_DOMAIN, MO_PATH)
+CCORG_GETTEXT_TRANSLATIONS = {}
+
+
+def translations_for_locale(locale):
+    """
+    Get the right translation and return it
+    """
+    if CCORG_GETTEXT_TRANSLATIONS.has_key(locale):
+        return CCORG_GETTEXT_TRANSLATIONS[locale]
+
+    # do I have the order backwards here?
+    langs = [locale]
+    if '_' in locale:
+        root_lang = locale.split('_')[0]
+        if os.path.exists(os.path.join(MO_PATH, root_lang)):
+            langs.append(root_lang)
+
+    langs.append('en')
+
+    translations = gettext.translation(I18N_DOMAIN, MO_PATH, langs)
+    CCORG_GETTEXT_TRANSLATIONS[locale] = translations
+    return translations
+
+
+def ugettext_for_locale(locale):
+    return translations_for_locale(locale).ugettext


hooks/post-receive
-- 
Wrapper egg for the i18n checkout



More information about the cc-commits mailing list