<< Back - Alkacon logo

OpenCms 6.0 interactive documentation:

Step 4: Localization

OpenCms logo - Forward >>

Localization

In order to localize the fields for the automatically generated XML Content editor, you have to create a Java resource bundle containing localized Strings for each input field. Additionally, the resource bundle name has to be defined in the <appinfo> node of the XSD. The resource bundle has to be placed in a classes/ subfolder of your module to be exported to the real file system of the server.

For each element configured in the XSD, the XML content editor tries to get a localized String. The keys that are searched by the editor follow a fixed scheme. Have a look at the elements of the article example article.xsd in the folder /xmlcontentdemo/:

<xsd:complexType name="OpenCmsArticle"> 
	<xsd:sequence> 
		<xsd:element name="Title" type="OpenCmsString" /> 
		<xsd:element name="Teaser" type="OpenCmsString" maxOccurs="5"/> 
		... 
	</xsd:sequence> 
	<xsd:attribute name="language" type="OpenCmsLocale" use="required"/> 
</xsd:complexType> 

To localize these two elements, the resource bundle has to define the keys label.Article.Title  and label.Article.Teaser. If you want to display help texts for the elements, the additional keys   label.Article.Title.help and label.Article.Teaser.help  must be present.

Check out the resource bundle workplace.properties  in the module folder /system/modules/org.opencms.frontend.templateone.xmlcontentdemo/classes/org/opencms/frontend/templateone/xmlcontentdemo/:

label.Article.Title = Title
label.Article.Title.help = The title of the article. This value will be mapped to the "Title" property of the resource.
label.Article.Teaser = Teaser text
label.Article.Teaser.help = The teaser of the article, a short summary that will be displayed on overview lists.

The keys follow a fixed scheme: first is a fixed "label" prefix, after that the name of the XML content element, in this case "Article", and the name of the element to localize. For help texts, the suffix "help" has to be appended.

For all configuration options of the combo or select boxes, it is possible to use localized Strings that were defined in the resource bundle for the XML content. Instead of writing the text directly to the attribute values, use a macro. To get the localized String for the key myselectvalue1 in the resource bundle, use the macro ${key.myselectvalue1}.

...
<layouts>
<layout element="Combobox" widget="ComboWidget" configuration=" value='${key.combo.value1}' help=${key.combo.help1}'| value='${key.combo.value2}' help='${key.combo.help2}'| value='${key.combo.value3}' default='true' help='${key.combo.help3}'| value=${key.combo.value4}' help='${key.combo.help4}'" /> </layouts>
...

Macros can also be used for validation error messages and default values in the XSD. 

Learn in the next step how to create nested contents. 


©2005 Alkacon Software GmbH (http://www.alkacon.com) - The OpenCms experts