eligrey / l10n.js

Passive localization JavaScript library
http://purl.eligrey.com/l10n.js
Other
392 stars 68 forks source link

Do you need to include a translation when one isn't needed? #36

Closed cyphix333 closed 7 years ago

cyphix333 commented 7 years ago

Just starting to use this library and wondering for like the default language or similar ones do you need to provide the translation if one is not needed?

For example, say your translation is l("my message") then you would normally have to do something like this:

{
  "en-US": {
      "my message": "my message",
      "color": "color"
  },
  "en-GB": {
      "my message": "my message",
      "color": "colour"
  },
}

Whereas, if not already an acceptable way to do it, something like this would save a lot of repeated data and code bloat:

{
  "en-US": {

  },
  "en-GB": {
      "color": "colour"
  },
}

So basically if it didn't find the translation then the text would remain the same; in this instance we would be using en-US as our default (writing) language and hence no translations are needed and en-GB is very similar so the file should only need to contain the translations that actually need to be translated.

Is this an acceptable way of doing it or does all translations have to be put in the files whether they need translating or not?

eligrey commented 7 years ago

Put equivalent translations under the same root language tag. You would make an entry for "en", and en-us/gb will automatically get translations from "en"

cyphix333 commented 7 years ago

Can you give an example? Are you saying you can't make en-US.json and en-GB.json files and have to make a en.json file with all the locales in it?

However, I'm still unsure if this means you can leave out data that doesn't need translating as it's either the default language or is the same in en-GB as it is in the default language.

ghost commented 7 years ago

As stated by eligrey, you could solve this requirement by structuring your localized messages as follows:

{ "en":{ "my message": "my message" }, "en-US": { "color": "color" }, "en-GB": { "color": "colour" } }

when a property is not found for an specific locale variant ("en-US" for example), it will search its base locale ("en" in this case).