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

Comma at the end of translations file causes strange behaviour #209

Open
DigitalLeaves opened this issue Mar 23, 2020 · 3 comments
Open

Comments

@DigitalLeaves
Copy link

DigitalLeaves commented Mar 23, 2020

Yesterday i18n stopped working all of a sudden for no apparent reason. After banging my head against a wall going through my code and trying to figure out when this had happened, I finally realized it is because when adding the last translation item in one language JSON file I had added a comma at the very end.

{
   "key_1": "value 1",
   "key_2": "value 2",
   ...,
   "key_n": "value n", <== here
}

I know JSON specification does not allow trailing commas, but I did not get a complaint or error message from i18n. I think there should be some kind of indication when the JSON files provided are wrong (which I think i18n probably does already?), but this case I think should be considered?

Thank you!

@santhoshtr
Copy link
Member

santhoshtr commented Mar 24, 2020

This library is being ported to a jquery indepedent javascript library. See https://github.com/wikimedia/banana-i18n/ It comes with a linter called banana-checker. There are some js framework loaders like vue loader(with vue binding). So I guess those projects take care of this. It is very unlikely that this project(jquery.i18n) will have any new features.

If you are using some good IDEs such as VS Code, there are extension that does this validation. If the translation json files are hand edited, there is a chance for syntax errors. but if a localization tool such as translatewiki.net is used, it is nearly impossible to get an invalid json.

Hope that helps

@Kirtishukla2004
Copy link

i am not abl to understand this issue can you please elaborate it

@DigitalLeaves
Copy link
Author

It is quite simple.
A comma at the end of a translation JSON file like shown in my original post makes i18n fail without indication that there is an extra trailing comma.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants