fnando / i18n-js

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

Bug: overwriting identical exported JSON localization files #693

Closed oleksii-leonov closed 1 year ago

oleksii-leonov commented 1 year ago

Description

Running i18n export should not rewrite exported JSON localization files if the content hasn't changed.

In v3, it was fixed in https://github.com/fnando/i18n-js/pull/473. https://github.com/fnando/i18n-js/blob/4b07b30e8b6f42c4415f4bb967e8e2986a0e2268/lib/i18n/js.rb#L256

Description from original PR https://github.com/fnando/i18n-js/pull/473:

Writing files triggers other actions in anything watching those files - eg rebuilding a webpack bundle. Normally this won't occur as i18n-js's caching will determine that nothing needs to be done, but it can add up quickly when running individual specs from the command line, where the cache is reset on every load.

How to reproduce

> i18n export
> ls -la app/packs/locales/generated

drwxr-xr-x 4 vscode vscode    4096 Dec 30 16:06 ..
-rw-r--r-- 1 vscode vscode 1532625 Dec 30 16:29 bg.json
-rw-r--r-- 1 vscode vscode 1058584 Dec 30 16:29 cs.json
# ...

# 1 minute later

> i18n export
> ls -la app/packs/locales/generated

drwxr-xr-x 4 vscode vscode    4096 Dec 30 16:06 ..
-rw-r--r-- 1 vscode vscode 1532625 Dec 30 16:30 bg.json
-rw-r--r-- 1 vscode vscode 1058584 Dec 30 16:30 cs.json
# ...

What do you expect

Files should not be rewritten if identical (v3 behavior):

> i18n export
> ls -la app/packs/locales/generated

drwxr-xr-x 4 vscode vscode    4096 Dec 30 16:06 ..
-rw-r--r-- 1 vscode vscode 1532625 Dec 30 16:29 bg.json
-rw-r--r-- 1 vscode vscode 1058584 Dec 30 16:29 cs.json
# ...

# 1 minute later

> i18n export
> ls -la app/packs/locales/generated

drwxr-xr-x 4 vscode vscode    4096 Dec 30 16:06 ..
-rw-r--r-- 1 vscode vscode 1532625 Dec 30 16:29 bg.json
-rw-r--r-- 1 vscode vscode 1058584 Dec 30 16:29 cs.json
# ...

What happened instead

Files are being rewritten.

Software:

fnando commented 1 year ago

@oleksii-leonov Just released v4.2.2 with all these changes. https://github.com/fnando/i18n-js/compare/v4.2.1…v4.2.2

oleksii-leonov commented 1 year ago

@fnando , thank you 👍