# HG changeset patch # User paulb # Date 1133531497 0 # Node ID 65e168404d144ce5ac20138683a8728bb69d5da5 # Parent bfc995c3c23201e2ce353fb327480ee24563ab1b [project @ 2005-12-02 13:51:37 by paulb] Added an i18n function which is to be used within attribute values instead of the previously employed template:i18n attribute (which referred to other attributes to be translated). diff -r bfc995c3c232 -r 65e168404d14 XSLForms/Output.py --- a/XSLForms/Output.py Thu Dec 01 18:06:40 2005 +0000 +++ b/XSLForms/Output.py Fri Dec 02 13:51:37 2005 +0000 @@ -316,6 +316,26 @@ # Utility functions. +def i18n(context, value): + + """ + Exposed as {template:i18n(value)}. + + Provides a translation of the given 'value' using the 'translations' and + 'locale' variables defined in the output stylesheet. + """ + + context = libxml2mod.xmlXPathParserGetContext(context) + transform_context = libxsltmod.xsltXPathGetTransformContext(context) + translations_var = libxsltmod.xsltVariableLookup(transform_context, "translations", None) + locale_var = libxsltmod.xsltVariableLookup(transform_context, "locale", None) + if translations_var is not None and locale_var is not None: + translations = libxml2dom.Node(translations_var[0]) + results = translations.xpath("/translations/locale[code/@value='%s']/translation[@value='%s']/text()" % (locale_var, value)) + if len(results) > 0: + return results[0].nodeValue.encode("utf-8") + return value + def choice(context, value, true_string, false_string=None): """ @@ -426,6 +446,7 @@ # Utility functions. +libxsltmod.xsltRegisterExtModuleFunction("i18n", "http://www.boddie.org.uk/ns/xmltools/template", i18n) libxsltmod.xsltRegisterExtModuleFunction("choice", "http://www.boddie.org.uk/ns/xmltools/template", choice) libxsltmod.xsltRegisterExtModuleFunction("url-encode", "http://www.boddie.org.uk/ns/xmltools/template", url_encode) libxsltmod.xsltRegisterExtModuleFunction("element-path", "http://www.boddie.org.uk/ns/xmltools/template", element_path)