jquery.i18n
jquery.i18n copied to clipboard
Comma at the end of translations file causes strange behaviour
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!
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
i am not abl to understand this issue can you please elaborate it
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.