Localization

From OpenCms Wiki
(Difference between revisions)
Jump to: navigation, search
(Editing the default body)
 
(9 intermediate revisions by 5 users not shown)
Line 1: Line 1:
*[[Multi-language site structure]]
+
== Multi-language site structure ==
*[[Switch between languages]]
+
To achieve a '''multi-language site''' in opencms it's a good idea to create one top-level folder per language. These top-level folders are usually named after their two-letter lowercase code as identified by the [http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes ISO 639-1 list], although you can name them however you want. On each of these folders, the locale property should be defined. This can be done by left-clicking the folder icon and selecting properties > advanced. In the advanced properties the locale property should be listed.
*[[Automatic detection of user's preferred language]]
+
All the child folders and pages will then inherit the locale of their parent folder. If you would like a page to be available in several locales, you start out by creating the page in one of the locale folders, after which you create a sibling to this page in the folders of the other locales for which you want this page to be available.
*[[Using the Administration View tools for multi-language site creation]]
+
  
 
== Caveats ==
 
== Caveats ==
 
This section will contain a number of pitfalls related to developing or working with a multilingual site in OpenCms.
 
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 ====
 
==== 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:
 
An example body that has the same *body element as the "default body" provided by OpenCms but supports multiple languages would look as follows:
 
+
<code lang="xml">
 
     <?xml version="1.0" encoding="UTF-8"?>
 
     <?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">
 
     <pages xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.opencms.org/dtd/6.0/xmlpage.xsd">
Line 42: Line 36:
 
       </page>
 
       </page>
 
     </pages>
 
     </pages>
 
+
</code>
 
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.
 
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 ====
 
==== Editing the default body ====
The "default body" file can be found in the folder <em>/system/modules/org.opencms.welcome/default_bodies/</em>
+
The "default body" file can be found in the folder <em>/system/modules/org.opencms.workplace/default_bodies/</em>
  
 
==== Creating a custom body ====
 
==== Creating a custom body ====
 
If you have created your own module, you can add custom bodies by creating the default_bodies folder in <em>/system/modules/your.module.name/</em>
 
If you have created your own module, you can add custom bodies by creating the default_bodies folder in <em>/system/modules/your.module.name/</em>
  
==== 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.
+
 
 +
 
 +
 
 +
== See also ==
 +
*[[Switch between languages]]
 +
*[[Automatic detection of user's preferred language]]
 +
*[[Using the Administration View tools for multi-language site creation]]
 +
*[[Using ResourceBundles (without having to restart container)]]

Latest revision as of 07:56, 10 July 2009

Contents

Multi-language site structure

To achieve a multi-language site in opencms it's a good idea to create one top-level folder per language. These top-level folders are usually named after their two-letter lowercase code as identified by the ISO 639-1 list, although you can name them however you want. On each of these folders, the locale property should be defined. This can be done by left-clicking the folder icon and selecting properties > advanced. In the advanced properties the locale property should be listed. All the child folders and pages will then inherit the locale of their parent folder. If you would like a page to be available in several locales, you start out by creating the page in one of the locale folders, after which you create a sibling to this page in the folders of the other locales for which you want this page to be available.

Caveats

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

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.workplace/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/



See also

Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox