[Mpuls-commits] r2955 - base/trunk/mpulsweb/lib

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Wed Jun 9 17:06:15 CEST 2010


Author: torsten
Date: 2010-06-09 17:06:15 +0200 (Wed, 09 Jun 2010)
New Revision: 2955

Modified:
   base/trunk/mpulsweb/lib/translation.py
Log:
* mpulsweb/lib/translation.py (ungettext): new function to translate a string in plural forms.


Modified: base/trunk/mpulsweb/lib/translation.py
===================================================================
--- base/trunk/mpulsweb/lib/translation.py	2010-06-09 14:13:26 UTC (rev 2954)
+++ base/trunk/mpulsweb/lib/translation.py	2010-06-09 15:06:15 UTC (rev 2955)
@@ -30,7 +30,30 @@
 
 _ = ugettext
 
+def ungettext(singular, plural, n):
+    """Mark a string for translation. Returns the localized unicode
+    string of the pluralized value.
 
+    This does a plural-forms lookup of a message id. ``singular`` is
+    used as the message id for purposes of lookup in the catalog, while
+    ``n`` is used to determine which plural form to use. The returned
+    message is a Unicode string.
+
+    Mark a string to be localized as follows::
+
+        ungettext('There is %(num)d file here', 'There are %(num)d files here',
+                  n) % {'num': n}
+
+    """
+    # TODO: Do not build a new newbranslator every time. Save it in app_globals
+    # e.g
+    base_translated = _get_translator(get_lang())
+    translated = pylons.translator.ungettext(singular, plural, n)
+    if translated == singular:
+        # Seems not to be translated look in baseapplication
+        translated = base_translated.ungettext(singular, plural, n)
+    return translated
+
 def _get_translator(lang, **kwargs):
     """Utility method to get a valid translator object from a language
     name"""



More information about the Mpuls-commits mailing list