Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
cyphix333 opened this issue Nov 22, 2016 · 3 comments
Closed

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

cyphix333 opened this issue Nov 22, 2016 · 3 comments

Comments

@cyphix333
Copy link

cyphix333 commented Nov 22, 2016

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
Copy link
Owner

eligrey commented Nov 22, 2016

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
Copy link
Author

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
Copy link

ghost commented Jun 8, 2017

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).

@eligrey eligrey closed this as completed Jun 8, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants