Technical documentation of Geoportal API

  • FR
  • UK

Index / Documentation / Technical documentation

Internationalization

2D Web Javascript API

Internationalization relies on OpenLayers supports for locales. This support uses the web browser installation language (Have a look at the user-agent HTTP field).

By default, the display uses this language, if the language has been implemented in both OpenLayers and Geoportal APIs. The currently supported languages are :

  • french (fr code).
  • english (en code).
  • german (de code).
  • spanish (es code).
  • italian (it code).

If the installation language is unknown then OpenLayers switches to english.

The webmaster has then nothing to do to obtain a display that complies with the end-user's language.

Assigning language

It is possible to force the use of a language in order not to depend on the end-user's browser's installation language :

OpenLayers.Lang.setCode('fr');

This example forces the use of french as the display language whatever the browser's language is.

Maps internationalization

When adding a layer via addLayer(), it is possible to add translation token to the Geoportal dictionnary :

// add translations
Geoportal.Lang.add(
    {
        'cartorisque.wms.name':
            {
                'fr':"Cartorisque",
                'en':"Avalanches",
                'de':"Lawinen",
                'es':"Aludes",
                'it':"Valanghe"
            },
        'shom.kml.name':
            {
                'fr':"Marées",
                'en':"Tides",
                'de':"Gezeiten",
                'es':"Mareas",
                'it':"Maree"
            }
    }
);
myMap.addLayer("WMS","cartorisque.wms.name",url,params,options);
myMap.addLayer("KML","shom.kml.name",url,params);

This example adds translations for french, english, german, spanish and italian for the Avalanches (MEEDDAT) and Tides (SHOM) layers.

If a translation does not exist, then OpenLayers uses the not-translated code in turn.

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"/>