Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

So, OpenLayers has a i18n namespace.

But in my example at the bottom of the blog.

I am not getting the "Pan Up" which is what I would expect, but instead "PanUp", which is the string that should be translated in en.js.

I don't know enough about how this should work to debug it. I couldn't find much in the documentation about this either.

How does OpenLayers know what language to use? When I switch to French will it know to pull out the translations of "PanUp" from the fr.js file?

share|improve this question
up vote 3 down vote accepted

Say you want your OpenLayers based map viewer from English to Spanish. The first step is:


To get the translation of 'Base layer' to Spanish:

var translatedString = OpenLayers.i18n('Base layer');

To show the translated string in the layer switcher:

var layerSwitcher = new OpenLayers.Control.LayerSwitcher({'title': translatedString}); map.addControl(layerSwitcher);

Taken From

Here's another good blog post.

share|improve this answer
Ok, so there is no use of setCode in the examples, so this may well be a first. So, I've got an English setCode defined in this jsFiddle. I'm using a custom OpenLayers.js file that I built from a fork of the 2.12 project. And the languages are defined in OpenLayers/Lang/en.js. So I can't see (yet) what I'm doing wrong. So is there no default language that is used in the OpenLayers.js file if one isn't defined? – Mike Gifford Apr 12 '12 at 18:17
NOTE: So you have to add the language file separately seems Lang/en.js isn't brought by default into the build of OpenLayers.js – Mike Gifford Apr 12 '12 at 18:25

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.