Localization

From OpenCms Wiki
Revision as of 14:11, 28 November 2006 by Andras.balogh (Talk | contribs)
Jump to: navigation, search

Contents

Caveats

This section will contain a number of pitfalls related to developing or working with a multilingual site in OpenCms.

NullPointerException when saving a Page in a non-default locale

When your site needs to support several languages, and you are using the "default body" as your "Copy body from" option, you might run into NullPointerExceptions when trying to save a Page in a locale different from the locale in which the Page was created.

This happens because the default template does not provide a <body> element for all languages.

Example body supporting multiple languages

An example body that has the same *body element as the "default body" provided by OpenCms but supports multiple languages would look as follows:

   <?xml version="1.0" encoding="UTF-8"?>
   <pages xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.opencms.org/dtd/6.0/xmlpage.xsd">
     <page language="nl">
       <element name="body">
         <links/>
         <content><![CDATA[]]></content>
       </element>
     </page>
     <page language="fr">
       <element name="body">
         <links/>
         <content><![CDATA[]]></content>
       </element>
     </page>
     <page language="en">
       <element name="body">
         <links/>
         <content><![CDATA[]]></content>
       </element>
     </page>
     <page language="de">
       <element name="body">
         <links/>
         <content><![CDATA[]]></content>
       </element>
     </page>
   </pages>

This example would create a body element for the dutch, english, french and german versions of the Page. You can either edit the existing "default body" provided by OpenCms, or create your own body if you are working on a custom module.

Editing the default body

The "default body" file can be found in the folder /system/modules/org.opencms.welcome/default_bodies/

Creating a custom body

If you have created your own module, you can add custom bodies by creating the default_bodies folder in /system/modules/your.module.name/

Is this a bug

It looks like this is a bug with the way OpenCms tries to save Pages of the type "Page with free text". If a particular element is missing for the selected locale, it should be created on saving. Additionally, if one or more extra language(s) are added to a site in the future, the Control Code of all the existing "Page with free text" files will have to be manually updated to support the new language(s).XMLContent does not suffer from this problem.

Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox