# HG changeset patch # User paulb # Date 1166573814 0 # Node ID 3a26a4f4272eea92e9e01ad5c9b0495bbf9679fa # Parent cf60a894ca3647d78d690379517fc7446b8b1278 [project @ 2006-12-20 00:16:54 by paulb] Removed in-page update code from the example. diff -r cf60a894ca36 -r 3a26a4f4272e docs/labels.html --- a/docs/labels.html Tue Nov 28 22:30:38 2006 +0000 +++ b/docs/labels.html Wed Dec 20 00:16:54 2006 +0000 @@ -42,7 +42,7 @@ 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.

+to the translations document specified above.

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

  <p>
Item type:
<select name="..." template:multiple-choice-list-field="type,type-enum,value" multiple="multiple">
<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