3.3.3. Localizing with resources

In your custom-extension.war, if you want to add your own resource files to support localization, you can do as follows:

  1. Add some folders and files to your custom extension to have:

    WEB-INF
    |__ classes
    |   |__ locale
    |       |__ portal
    |           |__ sample_en.properties
    |           |__ sample_fr.properties
    |__ conf
    |   |__ configuration.xml
    |   |__ locale-configuration.xml
    |__ web.xml

    In this example there are 2 resources for English (_en) and French (_fr). The resource files can be .properties or .xml.

    It is necessary that the resources are located in WEB-INF/classes.

  2. Edit locale-configuration.xml to configure ResourceBundleService:

    
    <configuration
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.exoplatform.org/xml/ns/kernel_1_2.xsd http://www.exoplatform.org/xml/ns/kernel_1_2.xsd"
       xmlns="http://www.exoplatform.org/xml/ns/kernel_1_2.xsd">
        <external-component-plugins>
            <target-component>org.exoplatform.services.resources.ResourceBundleService</target-component>
            <component-plugin>
                <name>Sample ResourceBundle Plugin</name>
                <set-method>addResourceBundle</set-method>
                <type>org.exoplatform.services.resources.impl.BaseResourceBundlePlugin</type>
                <init-params>
                    <values-param>
                        <name>init.resources</name>
                        <value>locale.portal.sample</value>
                    </values-param>
                    <values-param>
                        <name>portal.resource.names</name>
                        <value>locale.portal.sample</value>
                    </values-param>
                </init-params>
            </component-plugin>
        </external-component-plugins>
    </configuration>

    Pay attention to the value locale.portal.sample. It is like a translation of the path of your resources (locale/portal/sample - with the language code and file extension name is eliminated).

  3. Edit configuration.xml to import the locale-configuration.xml:

    
    <configuration
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.exoplatform.org/xml/ns/kernel_1_2.xsd http://www.exoplatform.org/xml/ns/kernel_1_2.xsd"
       xmlns="http://www.exoplatform.org/xml/ns/kernel_1_2.xsd">
       
        <import>war:/conf/locale-configuration.xml</import>
        
    </configuration>
Copyright ©. All rights reserved. eXo Platform SAS
blog comments powered byDisqus