# HG changeset patch # User paulb # Date 1133566228 0 # Node ID 7433c7447832d85edf3de1bacc6c0b6ea61fdea6 # Parent 9b3c9f5287fe1e713f9b9e6eeae0d76b8dfc7af4 [project @ 2005-12-02 23:30:28 by paulb] Added internationalisation documentation. diff -r 9b3c9f5287fe -r 7433c7447832 docs/internationalisation.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/docs/internationalisation.html Fri Dec 02 23:30:28 2005 +0000 @@ -0,0 +1,61 @@ + + + + + Internationalisation + + +

Internationalisation

+

One important issue was intentionally not covered in the "Template Design" +document: the usage of different texts, labels or phrases chosen +according to the languages understood by users of an application. The +XSLForms toolkit provides two mechanisms for the use of translations +and translated phrases:

Each +of the above mechanisms has its own specific purpose in template +documents, and these purposes are described below, along with the +necessary procedures for initialising and invoking the translation +mechanisms in an XSLForms application.

Translating Element Content

Consider the following document fragment:

<h1>System Configurator</h1>

In +order to translate this to a different language, according to that +preferred by the user, we must annotate the element containing the text +as follows:

<h1 template:i18n="-">System Configurator</h1>

Here, we state that the contents on the h1 element (the exact text System Configurator) +will be used to find a suitable translation in a translation dictionary +(as described below). The anticipated result of applying the annotation +would resemble the following output document fragment:

<h1>Systemkonfigurasjon</h1>

Consequently, +a translation has been inserted in place of the original text. In +cases where no translation could be found, the original contents of the +element would be preserved.

It is also possible to employ a +specific translation as opposed to the text which just happen to reside +inside an element; for example:

<h1 template:i18n="sysconfig">System Configurator</h1>

Here, instead of taking the exact text System Configurator as the "token" to be used to find a translation, we instead use the token with the name sysconfig. The effect, providing that the translation of sysconfig is Systemkonfigurasjon, would be the same as the result given above.

See the template:i18n section of the "Template Attribute Reference" document for details of this annotation.

Translating Attributes

Consider the following document fragment:

<input type="submit" name="update" value="Update!"/>

In order to translate the label of this particular form control to another language, we must modify the value attribute as follows:

<input type="submit" name="update" value="{template:i18n('Update!')}"/>

Here, +we insert an expression inside the attribute whose result will be +inserted in place of the expression. Note that for non-template +attributes, the expression must reside between { and } characters for the evaluation to take place. The anticipated result might resemble something like the following:

<input type="submit" name="update" value="Oppdatér"/>

Where +no suitable translation can be found for the text passed to the +function, the submitted text is returned as a result, producing +something resembling the original, non-translated document fragment.

See the template:i18n extension function description in the extension function API documentation for more details.

Initialising and Invoking Translations

To +permit the translation of text to occur, we must first prepare the +translations themselves; then, we must change our application to make +use of the translations.

Preparing the Translations

Translations +are typically stored in an XML file alongside other resources such as +templates and documents containing data which are also used to prepare +the final user-viewable output from an application. For example, one +can define a file with the name translations.xml and then insert the following contents into it:

<?xml version="1.0" encoding="iso-8859-1"?>
<translations>
<locale>
<code value="en_GB"/>
<code value="en"/>
</locale>
<locale>
<code value="nb_NO"/>
<code value="nb"/>
<translation value="System Configurator">Systemkonfigurasjon</translation>
<translation value="Update!">Oppdatér!</translation>
<translation value="Export!">Eksportér!</translation>
</locale>
</translations>

The structure of any such translations file must resemble the above:

  1. A top-level translations element containing...
  2. A number of locale sections, each containing...
  3. One or more code elements identifying the locale, together with...
  4. A number of translation elements, each providing a translation for each token.

In the above example, the locale for en and en_GB have no translations defined; as a result, for any requests for translations in this locale the +text already found in the document will be preserved, and this +behaviour is therefore equivalent to requests for translations +in locales which are not defined or mentioned in the above +document.

Conversely, in the above example, the locale for en and en_GB +has some translations defined; as a result, requests for translations +in this locale will result in the specified translations being +returned, provided the token is defined in a value attribute of a translation element; otherwise, the text already found in the document will be preserved.

Using the Translations

To make use of such a translation file, the file must first be registered in an application. As described in the "Creating Applications: Write a Web Resource" and "Using the XSLFormsResource API" documents, we may add the above example to a resource in the document_resources attribute:

document_resources = {
"translations" : "translations.xml"
# Other resources are defined here.
}

When +producing output for a template which uses internationalisation +features, we must first obtain a reference to the above document:

# In the respond_to_form method of an XSLFormsResource...
translations_xml = self.prepare_document("translations")

Then, +we must decide which language or locale the output will employ. One way +of making that decision is to use the WebStack API to find out which +languages a user's Web browser is configured to receive:

# In the respond_to_form method of an XSLFormsResource...
languages = trans.get_content_languages()
# Get the first one...
language = languages[0]

Finally, +with the above information in hand, we may now modify the output +production by adding a document reference (thus permitting the output +stylesheet to access the translations document) and by specifying the +chosen locale with the locale stylesheet parameter:

# Use the transaction, output stylesheet, form data document, stylesheet parameters
# as well as the document reference.
self.send_output(trans, [output_xsl], doc, {"locale" : language},
references={"translations" : translations_xml})

This +should produce an output document which uses the registered +translations as much as is possible for the selected language. +Obviously, a more complicated approach could be used to choose the most +appropriate language in the languages list, but such algorithms are not covered here.

\ No newline at end of file diff -r 9b3c9f5287fe -r 7433c7447832 docs/overview.html --- a/docs/overview.html Fri Dec 02 14:51:55 2005 +0000 +++ b/docs/overview.html Fri Dec 02 23:30:28 2005 +0000 @@ -22,5 +22,5 @@
  • Adding multivalued fields
  • Recommendations and advice
  • Adding in-page updates
  • -

    A topic-by-topic guide to XSLTools:

    Some other resources:

    +

    A topic-by-topic guide to XSLTools:

    Some other resources:

    \ No newline at end of file diff -r 9b3c9f5287fe -r 7433c7447832 docs/reference.html --- a/docs/reference.html Fri Dec 02 14:51:55 2005 +0000 +++ b/docs/reference.html Fri Dec 02 23:30:28 2005 +0000 @@ -4,7 +4,7 @@

    Template Attribute Reference

    This document presents each of the attributes used in templates to annotate the structure of the XML documents being -presented and to modify the final output of the presented document.

    Basic Annotations

    The annotation attributes in this section are the most basic of those available. Apart from template:element, it is usually preferable to use the annotations listed in the "Convenience Annotations" section below.

    template:element

    This +presented and to modify the final output of the presented document.

    Basic Annotations

    The annotation attributes in this section are the most basic of those available. Apart from template:element and template:i18n, it is usually preferable to use the annotations listed in the "Convenience Annotations" section below.

    template:element

    This attribute associates the template element on which it is used with an element from the XML document being presented. Matching elements are found from the current position (or context), where the position @@ -12,7 +12,11 @@ attribute permits the inclusion of a section of the template document according to a test performed on the XML document being presented.

    Example:

    <p template:if="@value = 'true'">
    If the value attribute is set to the string value 'true', include this section.
    </p>

    Syntax:

    XPath-expression

    Here, the underlying XPath mechanisms are exposed, and any XPath expression -which tests aspects of the XML document can be written.

    Initialisation Annotations

    The annotation attributes in this section control the initialisation of documents where this is done by the XSLForms toolkit.

    template:init

    This attribute controls the creation of elements in the initialisation process and is used together with template:element. For each element name listed in a template:element annotation, the corresponding value in a template:init annotation states whether or how such elements are to be initialised.

    Example:

    <p template:element="item" template:init="no">
    Such item elements will not be created automatically when the document is initialised.
    </p>

    Example:

    <p template:element="first,second,third" template:init="yes,yes,no">
    The first and second elements will be created automatically when the document is initialised.
    No third elements will be created automatically when the document is initialised.
    </p>

    Syntax:

    yes|no|auto[,yes|no|auto[,...]]

    Here, yes means that an element will be created automatically, no means that an element will not be created automatically (relying on the existence of such elements from before), and auto +which tests aspects of the XML document can be written.

    template:i18n

    This +attribute is used to translate the textual contents of an element to +another language where additional parameters specifying the language +and the whereabouts of the translations have been provided to the +stylesheet in the output generation process.

    Example:

    <span template:i18n="-">Hello</span>

    In this example, the contents of the span element would be replaced with an appropriate translation for the text Hello.

    Example:

    <span template:i18n="hello">Hello</span>

    In this example, the contents of the span element would be replaced with an appropriate translation using the token hello as a key in the translation dictionary.

    Syntax:

    -|token

    See the "Internationalisation" document for more information on this attribute.

    Initialisation Annotations

    The annotation attributes in this section control the initialisation of documents where this is done by the XSLForms toolkit.

    template:init

    This attribute controls the creation of elements in the initialisation process and is used together with template:element. For each element name listed in a template:element annotation, the corresponding value in a template:init annotation states whether or how such elements are to be initialised.

    Example:

    <p template:element="item" template:init="no">
    Such item elements will not be created automatically when the document is initialised.
    </p>

    Example:

    <p template:element="first,second,third" template:init="yes,yes,no">
    The first and second elements will be created automatically when the document is initialised.
    No third elements will be created automatically when the document is initialised.
    </p>

    Syntax:

    yes|no|auto[,yes|no|auto[,...]]

    Here, yes means that an element will be created automatically, no means that an element will not be created automatically (relying on the existence of such elements from before), and auto means that the initialisation process will attempt to guess whether an element should be created automatically (by looking for selectors which use the element's name and only creating elements where no such diff -r 9b3c9f5287fe -r 7433c7447832 docs/template-design.html --- a/docs/template-design.html Fri Dec 02 14:51:55 2005 +0000 +++ b/docs/template-design.html Fri Dec 02 23:30:28 2005 +0000 @@ -16,12 +16,17 @@ template design process with this structure in mind, although the structure definition is likely to be modified by decisions made in the design process and when testing the user interface by using the -application itself.

    Defining the Presentation

    Given a +application itself.

    Defining the Presentation

    Given +a document structure, one has to think about the most suitable ways of representing the information in the user interface. The most common -medium for presentation is HTML and its derivatives, and we consider -here the different HTML elements available to present different -"patterns" in a document structure.

    General Template Structure

    Templates based on HTML usually have the following general structure:

    <?xml version="1.0"?>
    <html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:template="http://www.boddie.org.uk/ns/xmltools/template">
    <head>
    <title>Some title</title>
    </head>
    <body template:element="structure">

    <!-- The interesting part goes here... -->

    </body>
    </html>

    Since we will want to edit the data produced by such a template, an HTML form element is usually necessary within the body element:

    <body template:element="structure">
    <form action="" method="POST">

    <!-- The interesting part goes here... -->

    </form>
    </body>

    We usually define the method as post in order to minimise complications with handling the data in the XSLForms toolkit.

    Static Elements

    Static +medium for presentation is HTML and its derivatives, and we consider in +this document the different HTML elements available to present +different +"patterns" in a document structure.

    Multiple Languages and Translations

    One +presentation issue which is largely separate from the presentation of +the structure of form data involves the use of appropriate languages +for an application's users - this is described in the "Internationalisation" document.

    General Template Structure

    Templates based on HTML usually have the following general structure:

    <?xml version="1.0"?>
    <html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:template="http://www.boddie.org.uk/ns/xmltools/template">
    <head>
    <title>Some title</title>
    </head>
    <body template:element="structure">

    <!-- The interesting part goes here... -->

    </body>
    </html>

    Since we will want to edit the data produced by such a template, an HTML form element is usually necessary within the body element:

    <body template:element="structure">
    <form action="" method="POST">

    <!-- The interesting part goes here... -->

    </form>
    </body>

    We usually define the method as post in order to minimise complications with handling the data in the XSLForms toolkit.

    Static Elements

    Static elements, as opposed to collection elements, are elements in the form data document structure which maintain some kind of organisation or grouping within a document, but whose presence cannot be edited by the user of