CloudMade/Leaflet — pull request #1232 by yohanboniface (2012-12-23 10:38:28+00:00)
Title: POC of a i18n system

Hi!

While working on a i18n feature for [Leaflet.Storage](https://github.com/yohanboniface/Leaflet.Storage), I though it should be more convenient to have all Leaflet plugins share the same system. That's why a suggest to add it in Leaflet core instead of making a plugin. Making a plugin (say Leaflet.I18n) means making it a dependency for all the other plugins, so I think it will not work.

So here is a suggestion.

The API is:

* to make a string translatable, just call `L._` (shortcut for `L.i18n`), like this:

```
L._("The phrase I want to be translatable");
L._("A complex sentence with a {variable}", {variable: "my value"});
```

* one or more `locale/{locale_code}.js` should be provided, something like:

```
var mylocale = {
"Simple phrase to translate": "Une simple phrase à traduire",
"A sentence with a {variable}": "Une phrase avec une {variable}",
};
```

* the locale must register itself, doing something like:
```
L.registerLocale('fr', mylocale);
```

This can be done more than once. For example, every plugin can add it's translations for some locale without overriding all the already registered strings. However, if the same string for the same locale is registered twice, the last wins.

* end user must load the `locale/` files provided by Leaflet, or plugins

* end user must set his locale, doing so:
```
L.setLocale('fr');
```

And then all the translatable strings available will be translated :).

Of course, i18n is optional: unless one locale has been set, the behaviour is unchanged.

Insolved:

* Not sure of the better way to make the locale available in the `dist/` module. I just think that each end user must only load the locales he wants

Of course, some documentation of this will be needed, if merged.

Thanks for reviewing!

Yohan