i18n-node-2 icon indicating copy to clipboard operation
i18n-node-2 copied to clipboard

Large HB project, seems to write to JSON file over and over even with no changes

Open scottlet opened this issue 7 years ago • 6 comments

I have a project set up with a watcher to regenerate templates on language file change - but the action of running the template generation sends the thing into a loop as it detects changes to the i18n json file and runs over and over again, even when there are no new keys added.

Is there a way to a) simply prevent updating of the json file? I'm happy adding my own keys or b) making the module only create a new json file on change?

scottlet avatar Feb 16 '18 06:02 scottlet

I'm not sure what you mean. I think devMode is supposed to prevent writing files and might help you

gjuchault avatar Feb 17 '18 16:02 gjuchault

I am using livereload to reload the pages I'm working on when they change. I'm using a watcher to generate HTML from HBS templates when those templates change I'm also using a watcher to generate HTML from HBS templates when the language file changes too

However, every time HBS generates pages, i18n-node-2 writes to the language file, even if I've not changed any text/added any keys

This leads to a loop whereby the two watchers are triggering each other.

For the time being I've added

dump: function () {
            throw ('error');
        }

into the options passed in on instantiation which forces it to throw an error before it tries to write to the file, this works but fills my debug log with error messages...

devMode would work but unfortunately it caches the JSON meaning the page doesn't get updates when I add keys to the JSON. Is there an option to disable the cache?

scottlet avatar Feb 20 '18 05:02 scottlet

Hm, I'm not sure if there is a solution to this and I don't have a lot of time to investigate myself.

If you ever find a solution, don't hesitate to discuss / PR.

gjuchault avatar Feb 20 '18 20:02 gjuchault

I can certainly create a PR with a "preventWrite" option or something - if you'd like me to I'll do this, just let me know your preferred name for this option...

scottlet avatar Feb 27 '18 05:02 scottlet

disableWrite seems nice ! Thank you for your help

gjuchault avatar Feb 27 '18 09:02 gjuchault

Hello, I am also facing the same issue(language file being modified by library). Is it required that the language file should be even touched by the i18n-node-2 code? As far as I can understand, the language file should be a constant (non changing) until the user himself goes and modifies it and the i18n program should just read it and use it for translation and nothing else. So, technically, the file should not change at all by the library. If it sees any errors in the translation file, it should throw the error and stop its work. Please let me know if my understanding is not right.

Thanks.

bgth avatar Jun 15 '18 12:06 bgth