Package turbogears :: Package i18n :: Module kidutils

Module kidutils

source code

Functions for use with Kid template

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 which calls translates all elements matching language attribute(set in configuration as i18n.templateLocaleAttribute, default 'lang')
source code
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 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="item.attrib.has_key('lang')"
py:replace="translate(item)"/>
<h1 lang="">Welcome!</h1>
@param item: element to be translated
@type item: ElementTree element
@param attr: 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