Technical documentation of Geoportal API

  • FR
  • UK

Index / Documentation / Technical documentation

Internationalization

2D Web Javascript API

It is possible to change the current language for the end-user of your web pages. This functionality is linked with an event that has been added to OpenLayers. This event allows you to intercept the language change.

The following example shows how to set up such a mechanism :

function initGeoportalMap() {
    ...
    // get default language
    var language= OpenLayers.Lang.getCode();
    var re= new RegExp("^"+language,i);
    var slct= OpenLayers.Util.getElement('gpChooseLang');
    for(var i= 0; i<slct.options.length; i++) {
        if( slct.options[i].value.match(re) ) {
            slct.options[i].selected= true;
        }
    }
    ...
}

In the initGeoportalMap() called on the load event of the HTML body, the default language (which is the installation language of the web browser) is fetched. A search over the relevant options in the form is made. The selected option is then retrieved.

<form style="border:0;margin:0;padding:0;" name="gpLangChange" action="#">
  <select style="font-size:0.75em;" id="gpChooseLang" name="gpChooseLang" size="1"
          onChange="YOUR_INSTANCE.getMap().setLocale(this.options[this.selectedIndex].value);">
      <option value="fr">Français</option>
      <option value="en">English</option>
      <option value="de">Deutsch</option>
      <option value="es">Español</option>
      <option value="it">Italiano</option>
  </select>
</form>

The form allows you the choose a language, when selected, the onChange event is raised. This allows to, in turn, raise the "changelang" for the Geoportal API.

It is important to note that the HTML page should indicate the UTF-8 encoding and should be encoded as such to allow nice characters displaying :

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>