3.3.3. Adding/Removing a language

Warning

You are looking at documentation for an older release. Not what you want? See the current release documentation.

Developers can define new or remove a defined language through the locale configuration file. The resource is managed by org.exoplatform.services.resources.LocaleConfigService as follows:


<component>
    <key>org.exoplatform.services.resources.LocaleConfigService</key>
    <type>org.exoplatform.services.resources.impl.LocaleConfigServiceImpl</type>
      <init-params>
        <value-param>
          <name>locale.config.file</name>
          <value>war:/conf/common/locales-config.xml</value>
        </value-param>
      </init-params>
  </component>

All languages defined in the locale-config.xml file are listed in the Interface Language Settings window. The resource bundle is managed by org.exoplatform.services.resources.ResourceBundleService as follows:


<external-component-plugins>
  <!-- The full qualified name of the ResourceBundleService -->
  <target-component>org.exoplatform.services.resources.ResourceBundleService</target-component>
  <component-plugin>
    <!-- The name of the plugin -->
    <name>Sample ResourceBundle Plugin</name>
    <!-- The name of the method to call on the ResourceBundleService in order to register the ResourceBundles -->
    <set-method>addResourceBundle</set-method>
    <!-- The full qualified name of the BaseResourceBundlePlugin -->
    <type>org.exoplatform.services.resources.impl.BaseResourceBundlePlugin</type>
    <init-params>
      <!--values-param>
        <name>classpath.resources</name>
        <description>The resources that start with the following package name should be load from file system</description>
        <value>locale.portlet</value>
      </values-param-->
      <values-param>
        <name>init.resources</name>
        <description>Store the following resources into the db for the first launch</description>
        <value>locale.portal.sample</value>
      </values-param>
      <values-param>
        <name>portal.resource.names</name>
        <description>The properties files of the portal , those files will be merged
          into one ResourceBundle properties
        </description>
        <value>locale.portal.sample</value>
      </values-param>
    </init-params>
  </component-plugin>
</external-component-plugins>

Adding a new language

To add a new language, you need to copy the default locale-config.xml file from platform-extension/WEB-INF/conf/common/locales-config.xml to your custom-extension.war (with the same path) and add the corresponding language entry.

For example, to add Italian, do as follows:

  1. Add the following code to the locale-config.xml file under your extension project.

    
    <locale-config>
      <locale>it</locale>
      <output-encoding>UTF-8</output-encoding>
      <input-encoding>UTF-8</input-encoding>
      <description>Default configuration for Italian locale</description>
    </locale-config>
  2. Create a new resource bundle as sample_it.properties in the custom-extension.war!/WEB-INF/classes/locale/portal folder or in the src/main/resources/locale/portal folder of the source code if you are using Maven.

    Note

    This step is necessary because the Resource Bundle Service of the portal will find keys and values in the resource bundle of each corresponding language.

  3. Restart the server.

    To check if the added language takes effect, click your username on the top navigation bar and click Change Language. In the Interface Language Settings window that appears, you will see the Italian is listed as below:

Removing a language

To remove an existing language, you need to delete the relevant language code in the locale-config.xml file and all files containing the suffix name as the key of language.

For example, to remove French, do as follows:

  1. Find and remove the following code from the locale-config.xml file under your extension project.

    
    <locale-config>
      <locale>fr</locale>
      <output-encoding>UTF-8</output-encoding>
      <input-encoding>UTF-8</input-encoding>
      <description>Default configuration for france locale</description>
    </locale-config>
  2. Continue removing all resource bundle files containing the suffix name as fr in all folders.

    Note

    It is recommended this step be done to delete unnecessary data in the application.

  3. Restart the server.

    To check if French is removed, hover your cursor over your username on the top navigation bar, then click Change Language.

    In the Interface Language Settings window that appears, French is no longer listed.

Copyright ©. All rights reserved. eXo Platform SAS
blog comments powered byDisqus