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

feat: speed up fallback translations plugin #688

Closed oleksii-leonov closed 1 year ago

oleksii-leonov commented 1 year ago
PR Checklist ### PR Structure - [x] This PR has reasonably narrow scope (if not, break it down into smaller PRs). - [x] This PR avoids mixing refactoring changes with feature changes (split into two PRs otherwise). - [x] This PR's title starts is concise and descriptive. ### Thoroughness - [x] This PR adds tests for the most critical parts of the new functionality or fixes. - [x] I've updated any docs, `.md` files, etc… affected by this change.

What

Speed up the fallback translations plugin. deep_merge code extracted from i18n-js v3.

Why

Current versions with Glob became too slow on large localization files. For our use case (20 locales, 20000 keys each), I wait ~20 minutes and kill the process.

deep_merge versions from v3 works instantly. So, I have extracted the deep_merge from v3 into v4.

Known limitations

N/A

fnando commented 1 year ago

This is great. Thank you! I did just a few synthetic tests with no more than a hundred translations and it's okay, but your real use case caught the performance introduced by glob (i'm pretty sure there's an opportunity for optimization there).

fnando commented 1 year ago

@oleksii-leonov just pushed to your repo with some changes related to uncovered code (just to make sure those mergers were working as expected).