fnando / i18n-js

It's a small library to provide the I18n translations on the Javascript. It comes with Rails support.
MIT License
3.77k stars 520 forks source link

Feature Request: Have the I18nJS.listen call be lazy #667

Closed gregorbg closed 1 year ago

gregorbg commented 2 years ago

Description

Currently, calling I18nJS.listen in a Rails context starts a listener and also immediately exports all files, no matter what. This is causing an inconvenience in our project because it overwrites all exported JSON files even if absolutely nothing changed. The overwrite implies a change in mtime timestamp, which in turn is used by our Webpack dev server to assess whether or not it needs to recompile.

Briefly put, using I18nJS.listen makes our Webpack setup recompile upon on botting the server due to I18N assets, even when those assets haven't changed

Describe the solution

Have the listener determine whether or not it needs to write the file.

Alternatives you considered

None.

Additional context

The relevant section of the code I believe is https://github.com/fnando/i18n-js/blob/main/lib/i18n-js/listen.rb#L29-L30 It always invokes I18nJS.call after setting up the listener, without determining changes.