Package turbogears :: Package i18n :: Module kidutils

Module kidutils

source code

Functions supporting translation of strings in Kid templates

Functions
 
translate(item, attr=None)
Translates the text of element plus the text of all child elements.
source code
 
translate_all(tree, lang, attr, inroot=True)
Recursive function to translate all text in child elements.
source code
 
i18n_filter(stream, template, locale=None)
Kid template filter translating all elements matching lang attribute.
source code
Variables
  __package__ = 'turbogears.i18n'
Function Details

translate(item, attr=None)

source code 

Translates the text of element plus the text of all child elements.

If 'attr' is present this is used to provide the locale name; if not then the value provided by 'get_locale' is used. For example:

   <div lang="">
       this is a test
       <a href="de">testing</a>
   </div>

The string 'this is a test' is rendered by the locale provided by 'get_locale', the string 'testing' by the German locale.

Possible use in Kid template:

   <?python
   from turbogears.i18n import translate
   ?>
   <translate xmlns:py="http://purl.org/kid/ns#"
       py:match="'lang' in item.attrib"
       py:replace="translate(item)" />
   <h1 lang="">Welcome!</h1>
Parameters:
  • item (ElementTree element) - element to be translated
  • attr (str) - attribute name used to store locale, if any

translate_all(tree, lang, attr, inroot=True)

source code 

Recursive function to translate all text in child elements.

Parameters:
  • tree - parent ElementTree element
  • lang - language setting
  • attr - attribute name used to store locale

i18n_filter(stream, template, locale=None)

source code 

Kid template filter translating all elements matching lang attribute.

The name of of the attribute is set in the configuration as 'i18n.templateLocaleAttribute' and defaults to 'lang'.