# HG changeset patch # User paulb # Date 1133574798 0 # Node ID 3bbbcd3ff0b20d25c05b193abe3e10dd41726082 # Parent 0095469d53a231a875019cdfe53f01d4d298c7d1 [project @ 2005-12-03 01:53:18 by paulb] Added internationalisation/translation and labelling issues to the tutorial. Fixed various cross-references. diff -r 0095469d53a2 -r 3bbbcd3ff0b2 docs/in-page-updates.html --- a/docs/in-page-updates.html Sat Dec 03 01:52:11 2005 +0000 +++ b/docs/in-page-updates.html Sat Dec 03 01:53:18 2005 +0000 @@ -50,7 +50,7 @@
  1. Inside this new options element, investigate the values associated with the type element.
  2. -
  3. If any of the selected type values is "Personal", make a new comment +
  4. If any of the selected type values represents the "Personal" category, make a new comment element, then add any attributes that may be found on existing comment elements within the current type element.
  5. @@ -194,7 +194,9 @@

    Instead of just obtaining a stylesheet for the structure document, we instead check to see if an in-page update is being requested and, if so, prepare the stylesheet representing the fragment -of the Web form to be presented. Additionally, we obtain special stylesheet parameters using the raw request parameters; this introduces information that will be used to control the +of the Web form to be presented. Additionally, we obtain special +stylesheet parameters using the raw request parameters; this introduces +information that will be used to control the stylesheet when making the final Web page output.

    Finally, we send the output to the user but employing the additional stylesheet parameters to configure the result:

    @@ -220,4 +222,4 @@ script file; otherwise it gets a Web page showing either all of the form (if a normal request is received), or a part of the form (if an in-page request is received).

    - + \ No newline at end of file diff -r 0095469d53a2 -r 3bbbcd3ff0b2 docs/internationalisation.html --- a/docs/internationalisation.html Sat Dec 03 01:52:11 2005 +0000 +++ b/docs/internationalisation.html Sat Dec 03 01:53:18 2005 +0000 @@ -10,11 +10,11 @@ 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 +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 +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) @@ -25,7 +25,7 @@ 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, +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 @@ -34,7 +34,7 @@ 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 +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 @@ -45,7 +45,7 @@ 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 +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 diff -r 0095469d53a2 -r 3bbbcd3ff0b2 docs/labels.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/docs/labels.html Sat Dec 03 01:53:18 2005 +0000 @@ -0,0 +1,50 @@ + + + + + Creating Applications: Labelling Multiple-Choice Values + + +

    Creating Applications: Labelling Multiple-Choice Values

    +

    When introducing the item type multiple-choice field into the application, we defined the following values:

    <?xml version="1.0"?>
    <type>
    <type-enum value="(Not selected)"/>
    <type-enum value="Important"/>
    <type-enum value="Not important"/>
    <type-enum value="Personal"/>
    </type>

    For +simple applications with a limited audience, it is often acceptable to +use values which are then presented unchanged such that the value Personal is known both inside the application and is also shown to the user as the textual string Personal. However, for other applications there may be good reasons not to show values directly in this way:

    1. There may be a special internal value which is not descriptive; for example 123 representing the same concept as Personal.
    2. The value might be understandable not be understandable to some users; for example, the text Personal may not be understood by users who do not speak or otherwise use the English language.

    We +must therefore consider introducing additional label information in +order to remedy the first case, at least. Consequently, we may modify +the defined values as follows:

    ?xml version="1.0"?>
    <type>
    <type-enum value="0">(Not selected)</type-enum>
    <type-enum value="I">Important</type-enum>
    <type-enum value="N">Not important</type-enum>
    <type-enum value="P">Personal</type-enum>
    </type>

    Here, +we have provided user-visible labels which can now be used by the +template. A single change to the item type choices list is required to +include these labels as the visible text in that particular form +control whilst maintaining the usage of the internal values:

      <p>
    Item type:
    <select template:multiple-choice-list-field="type,type-enum,value" name="..." multiple="multiple"
    onchange="requestUpdate(
    'comments',
    '{template:list-attribute('type-enum', 'value')}',
    '{template:other-elements(../options)}',
    '{template:child-attribute('value', template:child-element('comment', 1, template:other-elements(../options)))}',
    '/structure/item/options')">
    <option template:multiple-choice-list-value="type-enum,value,selected,text()" value="..." />
    </select>
    </p>

    The addition, as described in the template:multiple-choice-value and template:multiple-choice-list-value sections of the "Template Attribute Reference" document, selects the text inside the appropriate type-enum elements and inserts it as a label into each choice in the item type list.

    Updating the Web Resource

    +

    To update the special WebStack resource, we +now need to modify a few of the class attributes:

    +
        template_resources = {
    "structure" : ("structure_multivalue_label_template.xhtml", "structure_output.xsl")
    }
    init_resources = {
    "structure" : ("structure_multivalue_label_template.xhtml", "structure_input.xsl")
    }
    document_resources = {
    "types" : "structure_types_label.xml"
    }
    +

    With these adjustments, it should now be possible to see the +original labels and yet have the application manipulate a separate set +of internal values. +Note that it may be necessary to remove the old stylesheet for +producing output, structure_output.xsl, so that the updated version of the template is taken into use.

    Translating Labels

    Whilst +the above work made it possible to satisfy the first motivation of the +use of labels - to hide internal values - it did not permit us to +provide translations for different languages. In fact, there are at +least two approaches which could provide labels in multiple languages:

    1. Define a file containing the types and type-enum elements for each language.
    2. Use the internationalisation support in XSLForms to translate the labels.

    The +former approach might work in situations where multiple-choice values +are obtained from a repository, such as a database, which contains the +labels for items in each supported language. One can envisage a product +database, for example, containing product descriptions for each +language or market, and such information could be extracted in such a +way that it could be convenient to use many different data files (or to +extract the information dynamically, insert it into the form data +document, and to provide a reference to the form data document as a +source of value information).

    Let us concentrate, however, on the +latter, more convenient approach for our example application. In order +to produce translated labels, we must first define a translations file as described in the "Internationalisation" document; this file can be saved alongside our other resources with the name translations.xml, and its contents can be defined as follows:

    <?xml version="1.0" encoding="iso-8859-1"?>
    <translations>
    <locale>
    <code value="nb"/>
    <code value="nb_NO"/>
    <translation value="(Not selected)">(Ikke valgt)</translation>
    <translation value="Important">Viktig</translation>
    <translation value="Not important">Ikke viktig</translation>
    <translation value="Personal">Personlig</translation>
    </locale>
    </translations>

    To make use of this file, we must add additional references in the Web resource's attributes:

        document_resources = {
    "types" : "structure_types_label.xml",
    "translations" : "translations.xml"
    }

    And to introduce the translation mechanisms into the output production, we must modify the resource further:

            # Complete the response.

    stylesheet_parameters["locale"] = trans.get_content_languages()[0]
    self.send_output(trans, [trans_xsl], structure, stylesheet_parameters,
    references={"translations" : self.prepare_document("translations")})

    Here, we define a locale +parameter for the output stylesheet using the first language specified +in each user's browser's language preferences. Then, we add a reference +to the translations document specified above.

    Finally, we have to change the template to make use of the translations:

      <p>
    Item type:
    <select template:multiple-choice-list-field="type,type-enum,value" name="..." multiple="multiple"
    onchange="requestUpdate(
    'comments',
    '{template:list-attribute('type-enum', 'value')}',
    '{template:other-elements(../options)}',
    '{template:child-attribute('value', template:child-element('comment', 1, template:other-elements(../options)))}',
    '/structure/item/options')">
    <option template:multiple-choice-list-value="type-enum,value,selected,template:i18n(text())" value="..." />
    </select>
    </p>

    Note that we use the template:i18n extension function to modify the text found in each type-enum element in the types document. The usage of this function is described in the extension function API documentation.

    Now, upon adding items in the application, if the browser is set up appropriately - in this case using Norwegian Bokmål [nb] as the first choice of language - the item types will appear translated in the final output.

    +

    Further Reading

    +

    Now that we have designed and implemented a simple application, it +may be worth reading some recommendations +about developing your own applications.

    + \ No newline at end of file diff -r 0095469d53a2 -r 3bbbcd3ff0b2 docs/multiple.html --- a/docs/multiple.html Sat Dec 03 01:52:11 2005 +0000 +++ b/docs/multiple.html Sat Dec 03 01:53:18 2005 +0000 @@ -74,9 +74,9 @@
  6. The value attribute is set to a value which does not matter - it will be replaced in the final output.
  7. The result of this is that the type element in the this example structure fragment...

    -
    <type value="2">
    <type-enum value="1"/>
    <type-enum value="2"/>
    <type-enum value="3"/>
    </type>
    +
    <type value="2">
    <type-enum value="(Not selected)"/>
    <type-enum value="Important"/>
    <type-enum value="Not important"/>
    <type-enum value="Personal"/>
    </type>

    ...is transformed into something resembling this HTML code:

    -
    <select name="...">
    <option value="1">1</option>
    <option value="2" selected="selected">2</option>
    <option value="3">3</option>
    </select>
    +
    <select name="...">
    <option value="(Not selected)">(Not selected)</option>
    <option value="Important" selected="selected">Important</option>
    <option value="Not important">Not important</option>
    <option value="Personal">Personal</option>
    </select>

    Such presentation techniques are sufficient if the input form data structure is identical to the output structure, but since we will receive a structure resembling that defined diff -r 0095469d53a2 -r 3bbbcd3ff0b2 docs/multivalue.html --- a/docs/multivalue.html Sat Dec 03 01:52:11 2005 +0000 +++ b/docs/multivalue.html Sat Dec 03 01:53:18 2005 +0000 @@ -66,9 +66,9 @@ as in the single-valued case. The result of the presentation of the extra values is that the type element in the this example structure fragment...

    -
    <type>
    <type-enum value="1"/>
    <type-enum value="2" value-is-set="true"/>
    <type-enum value="3" value-is-set="true"/>
    </type>
    +
    <type>
    <type-enum value="(Not selected)"/>
    <type-enum value="Important" value-is-set="true"/>
    <type-enum value="Not important" value-is-set="true"/>
    <type-enum value="Personal"/>
    </type>

    ...is transformed into something resembling this HTML code:

    -
    <select name="..." multiple="multiple">
    <option value="1">1</option>
    <option value="2" selected="selected">2</option>
    <option value="3" selected="selected">3</option>
    </select>
    +
    <select name="..." multiple="multiple">
    <option value="(Not selected)">(Not selected)</option>
    <option value="Important" selected="selected">Important</option>
    <option value="Not important" selected="selected">Not important</option>
    <option value="Personal">Personal</option>
    </select>

    Above, the special value-is-set attribute is an XSLForms mechanism to remember which values were set. Fortunately, the document initialisation mechanism automatically @@ -85,8 +85,8 @@ Note that it may be necessary to remove the old stylesheet for producing output, structure_output.xsl, so that the multivalue version of the template is taken into use.

    -

    Further Reading

    -

    Now that we have designed and implemented a simple application, it -may be worth reading some recommendations -about developing your own applications.

    +

    Improving the Presented Values

    +

    In the application we have been developing, we have been content to show the multiple-choice values as they are known in the application - that is, the application refers to values like Personal +and the same text is shown to users of the application. However, there +are various situations where this is not desirable, and the usage of separate labels is described in the next section of the development process.

    \ No newline at end of file diff -r 0095469d53a2 -r 3bbbcd3ff0b2 docs/overview.html --- a/docs/overview.html Sat Dec 03 01:52:11 2005 +0000 +++ b/docs/overview.html Sat Dec 03 01:53:18 2005 +0000 @@ -19,7 +19,7 @@
  8. Write a Web resource to display the form
  9. Adding multiple-choice fields and values
  10. -
  11. Adding multivalued fields
  12. +
  13. Adding multivalued fields
  14. Labelling multiple-choice values
  15. Recommendations and advice
  16. Adding in-page updates

A topic-by-topic guide to XSLTools:

Some other resources:

diff -r 0095469d53a2 -r 3bbbcd3ff0b2 docs/reference.html --- a/docs/reference.html Sat Dec 03 01:52:11 2005 +0000 +++ b/docs/reference.html Sat Dec 03 01:53:18 2005 +0000 @@ -12,7 +12,7 @@ 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.

template:i18n

This +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