2.13.9. Localisation

GateIn can localise modules on the server. The JavaScript of each module is rewritten and replaces keys with values borrowed from resource bundles. Each script will be available under a different URL for each localisation to provide the maximum caching of the resource.

The localisation of a script is activated with the resource-bundle XML tag along with the path tag. Resources bundles are declared by the supported-locale tag and must be available in the web application classpath:


<module>
  <name>greetings</name>
  <supported-locale>de</supported-locale>
  <supported-locale>en</supported-locale>
  <supported-locale>fr</supported-locale>
  <supported-locale>vi</supported-locale>
  <supported-locale>ru</supported-locale>
  <script>
    <path>/path/to/greetings.js</path>
    <resource-bundle>greetings_bundle</resource-bundle>
  </script>
  ...
</module>

GateIn will escape any key of the {key} form and will look up the value in the resource bundles. For instance, one can easily build a JSON object containing localised values:

function() {
 return {
 "hello": "${hello}",
 "goodbye": "${goodbye}"
 };
})();

At runtime, different versions of this script will be served by GateIn with the properly escaped values.

Scripts in GateIn

Whenever possible, JavaScript should be written as an AMD module. This is the best practice which helps to manage dependencies, organize code, but not pollute the global scope and do parallel loading.

Note

GateIn also supports the custom adapter mechanism to adapt traditional script into GateIn module.

However, in some specific cases, you may want to use the old way which loads the scripts as non-AMD module. GateIn still supports this and allows you to manage those js dependencies:


 <scripts>
  <name>foo</name>
  <script>
    <path>/path/to/foo.js</path>
  </script>
  <depends>
    <scripts>bar</scripts>
  <depends>
</scripts>

You can also use a script provided on the internet by using the url tag instead of the script tag:


<scripts>
  <name>foo</name>
  <url></url>
</scripts>
Copyright ©. All rights reserved. eXo Platform SAS
blog comments powered byDisqus