Skip to content

Makes it possible to translate Leaflet.draw #87

Merged
merged 2 commits into from May 21, 2013

4 participants

@Starefossen

All localization specific strings has been refactored out of the core and into a /locales/Leaflet.draw.en.js file which is then referenced throughout the project.

This makes it possible to translate Leaflet.draw into other languages.

@yohanboniface

FYI, here is a proposal to add a simple i18n system centralized in Leaflet and make all the plugins share the same rules: Leaflet/Leaflet#1232

@Starefossen

Very interesting. I'll have a look and see if I can make this pull compliant with your suggestion :-)

@jacobtoye jacobtoye referenced this pull request Apr 23, 2013
Closed

Localization #128

@aleksejleonov

Thanks!

It would be great to make function to switch locales, like L.drawLocal.setLocale("en").
And make localisation files this way:

// Leaflet.draw.en.js
L.drawLocal.en = {
  draw: {
    toolbar: {
      polyline: 'Draw a polyline',
      polygon: 'Draw a polygon',
      ...

// Leaflet.draw.ru.js
L.drawLocal.ru = {
  draw: {
    toolbar: {
      polyline: 'Добавить линию',
      polygon: 'Добавить полигон',
      ...

So, it would be possible to include all localisation files from folder and than just set locale with function.

@aleksejleonov

I think very important for current users of Leaflet.draw (they mostly don't use localisation) is ability to make simple update without necessity to add any localisation files.

Maybe solution is to set default locale to "en" and include "en" localisation strings directly in leaflet.draw.js.
So, current users could just replace their leaflet.draw.js with updated version without any drawbacks. And users which want localisation feature could just add localisation files and switch locale.

@Starefossen

@aleksejleonov don't get me wrong but the reason they don't use translation is that there is no translation atm.

What I am pretty sure about is that most users won't compile their own leaflet.draw.js from source, meaning that we need to provide users an easy mean to include their own translation. The simplest way is to have one namespace that they can override if they like. Either by including their own translation file or by simply setting the variables, one by one, L.drawLocal.draw.simpleshape.tooltip.end = 'End this thing'. This is favorable because it won't break when new locals are introduced.

I'm thinking about rewriting this pull to the suggested model by @mourner in https://github.com/Leaflet/Leaflet/pull/1232.

@jacobtoye
Leaflet member

Finally found the time to look into this pull guys. Sorry :( It should be "good enough" until (if ever) leaflet decides to support localization officially.

@jacobtoye jacobtoye merged commit ea19da9 into Leaflet:master May 21, 2013
@Starefossen Starefossen deleted the Turistforeningen:translation-wip branch May 21, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.