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

i18n hashes invalidation #2464

Merged

Conversation

alexandrevryghem
Copy link
Member

@alexandrevryghem alexandrevryghem commented Aug 27, 2023

References

Description

In this PR I added hashes to the translation files & ensured that the translation files are retrieved with those hashes in production mode.

Instructions for Reviewers

List of changes in this PR:

  • Created a function to calculate the hashes of the json5 files and stored them using the EnvironmentPlugin to be able to retrieve them in the app using process.env.languageHashes
  • Customised the CopyWebpackPlugin to add the hash to the json file name (only in production mode)
  • Customised the TranslateBrowserLoader & TranslateServerLoader to retrieve the language file with the hash saved in process.env.languageHashes (only in production mode)
  • Fixed an error with the build:prod command where the NODE_ENV was not being set. This made it impossible to know whether you were building webpack in prod mode or dev mode.

Guidance for how to test & review this PR:
Test the following in both dev & prod mode:

  • Start your angular and check that all the translation keys are correctly displayed in both the default language (by default en.json5) & other random language (the reason you also need to test this in another random language is because in prod mode the default language is already included in the TransferState so both mechanisms need to be tested)
  • Make a change to a certain key in both the default language json5 file and one other random language file
  • By refreshing the page you should still be able to see the changes directly in dev mode. In prod mode you should now be able to see the changes directly in both languages without hard refreshing the page.
  • Remove a translation key from the random language and check that in prod mode the english translationkey is used when you disable javascript

Checklist

  • My PR is small in size (e.g. less than 1,000 lines of code, not including comments & specs/tests), or I have provided reasons as to why that's not possible.
  • My PR passes ESLint validation using yarn lint
  • My PR doesn't introduce circular dependencies (verified via yarn check-circ-deps)
  • My PR includes TypeDoc comments for all new (or modified) public methods and classes. It also includes TypeDoc for large or complex private methods.
  • My PR passes all specs/tests and includes new/updated specs or tests based on the Code Testing Guide.
  • If my PR includes new libraries/dependencies (in package.json), I've made sure their licenses align with the DSpace BSD License based on the Licensing of Contributions documentation.
  • If my PR includes new features or configurations, I've provided basic technical documentation in the PR itself.
  • If my PR fixes an issue ticket, I've linked them together.

@alexandrevryghem alexandrevryghem self-assigned this Aug 27, 2023
@alexandrevryghem alexandrevryghem added i18n / l10n Internationalisation and localisation, related to message catalogs new feature performance / caching Related to performance, caching or embedded objects medium priority labels Aug 27, 2023
@alexandrevryghem alexandrevryghem force-pushed the i18n-cache-busting_contribute-7.6 branch from ec48d37 to b471265 Compare August 27, 2023 20:49
@alexandrevryghem alexandrevryghem force-pushed the i18n-cache-busting_contribute-7.6 branch from b471265 to 07a2e33 Compare August 28, 2023 19:24
@alexandrevryghem alexandrevryghem added improvement ux User Experience related works high priority and removed medium priority labels Sep 2, 2023
@alexandrevryghem alexandrevryghem changed the title Implemented i18n cache busting i18n production improvements Sep 2, 2023
@alexandrevryghem alexandrevryghem force-pushed the i18n-cache-busting_contribute-7.6 branch from a5e0bda to a9353e4 Compare September 3, 2023 10:23
@alexandrevryghem alexandrevryghem changed the base branch from main to dspace-7_x October 12, 2023 08:30
@alexandrevryghem alexandrevryghem added the port to main This PR needs to be ported to `main` branch for the next major release label Oct 12, 2023
Copy link
Member

@artlowel artlowel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @alexandrevryghem!

The hashing thing works great, however I'd leave out the syncing of the i18n files during production builds. I'd rather see #2340 fixed using a github workflow task for example, where every time a PR is merged that changes an i18n message, a new PR is generated that syncs all i18n files

I don't like the fact that with this PR, the i18n files used in production don't contain the exact same messages as the ones in the src folder.

@hutattedonmyarm
Copy link
Contributor

We gave this a quick test, as we're interested in that and it works for us as suggested. We're still on DSpace 7.5 and were able to apply the changes as they are

@tdonohue
Copy link
Member

@alexandrevryghem : I wanted to briefly note that I agree with @artlowel 's feedback above. I'd recommend we remove any automatic syncing of i18n files from this PR and solve it later in a separate PR. This PR could then just concentrate on the new hashed files for i18n.

@alexandrevryghem
Copy link
Member Author

@tdonohue I removed the commit, and updated the PR description, but I can't unlink issue #2340, can you please fix this 🙏

@tdonohue
Copy link
Member

@alexandrevryghem : I cannot seem to remove the link to the other ticket (#2340) either 😞 It appears to be a GitHub bug. We'll just need to reopen that ticket if it ends up closing automatically when this PR is merged. (Or maybe GitHub will eventually correct itself)

@Leano1998
Copy link
Contributor

Hej,
thank you @alexandrevryghem for the PR. I tested it as well and it worked perfectly for me!

Copy link
Member

@artlowel artlowel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

@tdonohue tdonohue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Thanks @alexandrevryghem ! This looks great, and I've verified this also works well when running the UI in production mode on Windows.

@tdonohue tdonohue added this to the 7.6.1 milestone Oct 26, 2023
@tdonohue tdonohue merged commit 673f817 into DSpace:dspace-7_x Oct 26, 2023
16 checks passed
@dspace-bot
Copy link
Contributor

Successfully created backport PR for main:

@tdonohue tdonohue removed the port to main This PR needs to be ported to `main` branch for the next major release label Oct 26, 2023
@tdonohue tdonohue changed the title i18n production improvements i18n production improvements (i18n hashes) Jan 23, 2024
@alexandrevryghem alexandrevryghem changed the title i18n production improvements (i18n hashes) i18n hashes invalidation Jul 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
high priority i18n / l10n Internationalisation and localisation, related to message catalogs improvement new feature performance / caching Related to performance, caching or embedded objects ux User Experience related works
Projects
Development

Successfully merging this pull request may close these issues.

Keep i18n text in sync more consistently Add hash/fingerprint to the translation files
6 participants