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.
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.
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>
Traditional script must be declared in the
            scripts
            tag instead of module.
          
Dependencies can be declared using
            depends
            but it can only depend on other
            scripts, but not modules. This is
            also true at the module side, a module can only depend on other modules.
          
Once a portlet uses a non-AMD script module declared in scripts, the module will be pushed into the HTML head. It means those scripts will be loaded and executed before the DOM is created and will likely have impact on front-end performance.
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>