jeresig / i18n-node-2

Lightweight simple translation module for node.js / express.js with dynamic json storage. Uses common __('...') syntax in app and templates.
MIT License
507 stars 79 forks source link

When in Dev Mode JSON is overwritten when accidentally invalidating the JSON language file. #124

Open Netgator opened 5 years ago

Netgator commented 5 years ago

Related to Issue #39 which has been closed.

I noticed that in sails this is a NON-ISSUE however when implementing i18n-2 in my own class and executing it outside of sails this is STILL an issue.

The Issue: I have a fairly large en.js file with many of the strings "KEYED" to English sentences. For example: "TEST": "This is a Test message for %s" I was manually adding my KEY/sentence pairs to the file while testing a custom class outside of sails. I inadvertently left off a comma on one of the pairs and the next time I started my "test" (because I was outside of sails in DEV mode with an "invalid" JSON file) the i18n-2 package OVERWROTE the ENTIRE en.js file because of ONE missing comma!

It would be nice if the package just automatically prevented an overwrite even in DEV mode if the following are ALL TRUE: 1.) language file exists 2.) file IS NOT EMPTY 3.) file is INVALID JSON. If this doesn't make sense then a second option would be to add a configuration option to the "setup" config that while in DEV mode I can say that YES I want the strings to be automatically written to the file HOWEVER if the JSON is invalid to error and stop completely.

Like: let i18n = new(require('i18n-2'))({ locales: ['en'], error_invalid_language: true });