1.1 --- a/XSLForms/Output.py Thu Dec 01 18:06:40 2005 +0000
1.2 +++ b/XSLForms/Output.py Fri Dec 02 13:51:37 2005 +0000
1.3 @@ -316,6 +316,26 @@
1.4
1.5 # Utility functions.
1.6
1.7 +def i18n(context, value):
1.8 +
1.9 + """
1.10 + Exposed as {template:i18n(value)}.
1.11 +
1.12 + Provides a translation of the given 'value' using the 'translations' and
1.13 + 'locale' variables defined in the output stylesheet.
1.14 + """
1.15 +
1.16 + context = libxml2mod.xmlXPathParserGetContext(context)
1.17 + transform_context = libxsltmod.xsltXPathGetTransformContext(context)
1.18 + translations_var = libxsltmod.xsltVariableLookup(transform_context, "translations", None)
1.19 + locale_var = libxsltmod.xsltVariableLookup(transform_context, "locale", None)
1.20 + if translations_var is not None and locale_var is not None:
1.21 + translations = libxml2dom.Node(translations_var[0])
1.22 + results = translations.xpath("/translations/locale[code/@value='%s']/translation[@value='%s']/text()" % (locale_var, value))
1.23 + if len(results) > 0:
1.24 + return results[0].nodeValue.encode("utf-8")
1.25 + return value
1.26 +
1.27 def choice(context, value, true_string, false_string=None):
1.28
1.29 """
1.30 @@ -426,6 +446,7 @@
1.31
1.32 # Utility functions.
1.33
1.34 +libxsltmod.xsltRegisterExtModuleFunction("i18n", "http://www.boddie.org.uk/ns/xmltools/template", i18n)
1.35 libxsltmod.xsltRegisterExtModuleFunction("choice", "http://www.boddie.org.uk/ns/xmltools/template", choice)
1.36 libxsltmod.xsltRegisterExtModuleFunction("url-encode", "http://www.boddie.org.uk/ns/xmltools/template", url_encode)
1.37 libxsltmod.xsltRegisterExtModuleFunction("element-path", "http://www.boddie.org.uk/ns/xmltools/template", element_path)