Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include new translations by clearing cache and precompiling assets #901

Closed
wants to merge 1 commit into from

Conversation

DuldR
Copy link

@DuldR DuldR commented Jan 25, 2023

Fixes #856

Currently, we're relying on the i18n-js gem and utilizing it through the asset pipeline for our translations. When adding a new locale, these changes aren't being reflected on the front end. Only after changing any of the existing yml files will the fingerprint for the assets be updated and trigger a refresh.

After doing some digging, this is actually the intended design by Sprockets.

Relevant issue: #213 within i18n-js
Provided Workarounds: https://github.com/fnando/i18n-js/tree/v3#missing-translations-in-precompiled-files-after-adding-any-new-locale-file

For this PR, I went with the first option of calling rake tasks on the rails container after it's spun up. These commands clear the cache and force a precompile of all the assets. Because the cache has been cleared, it picks up all existing locales(old and new) and provides them to the front end. I've tested on both offline and dev profiles with the following steps:

  1. bin/setup
  2. docker compose --profile dev up or docker compose --profile offline up
  3. Load localhost:3000 and confirm splash page with translations
  4. Add a new locale: inside of config/locales, cp -r en/ it/ then modify all yml files within the new directory from the en to it key
  5. Kill docker compose with ctrl+c and rerun the command from step 2
  6. Load localhost:3000 and new it translations will be present

While this won't "hot load" new translations, it will ensure anything new will be included at the start of the rails container.

Option 2 from the i18n-js docs is what we're already doing.
Option 3 from the i18n-js docs might be an easier and better solution, but wanted to discuss on path forward.

@rudokemper
Copy link
Member

Thanks for this work @DuldR, and sorry for the long delay in getting back to this. But we ended up handling our i18n differently and are no longer using i18n-js, so we have to close this one. Nevertheless, thank you for putting in this work and research.

@rudokemper rudokemper closed this Sep 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants