Fix #5652 - Runtime i18n Loading for Theme Translations (no build-time merge for i18n files)#5653
Open
kanasznagyzoltan wants to merge 2 commits into
Conversation
|
Hi @kanasznagyzoltan, thank you for this PR! Since this would probably qualify as an improvement to build process rather than a new user feature, I added it to the 10.0 project to start. However since we're close to the May 22 code freeze, this will likely go towards a later release unless reviews are very quick for it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
References
Description
Make the i18n
TranslateLoadertheme-aware: instead of relying on the build-timemerge-i18nscript, theme-specific translation overrides are now loaded and merged at runtime from each configured theme'sassets/<theme>/i18n/<lang>.json5, following the themeextendschain. This allows a single Docker image to serve multiple customers/themes with their own translations.Instructions for Reviewers
List of changes in this PR:
dist/.../assets/i18n/<lang>.<hash>.json), the loader now overlays every configured theme'sdist/.../assets/<theme>/i18n/<lang>.json5on top, in inheritance order (ancestor first, descendant last, so child theme keys win). The merged map is stored inNGX_TRANSLATE_STATEso the browser does not need to re-fetch theme overrides after SSR.JSON5.parse. Missing override files are tolerated viacatchError.extendschain (usingNamedThemeConfig.extends) up to the root ancestor, then emits themes in ancestor → descendant order with deduplication and cycle protection. The algorithm mirrors the existing component-level inheritance resolution insrc/app/shared/theme-support/themed.component.ts:resolveThemedComponent.assets/<theme>/i18n/*.json5files are simply ignored (non-existing file → empty object → no effect on the merged result). Existing setups that still runmerge-i18ncontinue to work unchanged.How it works
Given a config like:
…and i18n files at:
…the loader merges them at runtime in the order
base → custom-parent→ custom-child, socustom-childkeys overridecustom-parentkeys, which override base keys. Ifcustom-childdoes not define a key, the user falls back tocustom-parent's value, then to base.How to test
src/assets/i18n/<lang>.json5files contain only the upstream/base content (no merged theme content).npm run merge-i18n.src/themes/<theme>/assets/i18n/<lang>.json5./assets/<theme>/i18n/<lang>.json5should fire on the first navigation (the merged map is hydrated fromNGX_TRANSLATE_STATE).npm run start:dev(no SSR) and confirm the loader fetches base + theme files via HTTP and merges them in the browser.extendsan existing one, override a key in the child, leave another key only in the parent — both should resolve correctly when the child theme is active.Checklist
This checklist provides a reminder of what we are going to look for when reviewing your PR. You do not need to complete this checklist prior creating your PR (draft PRs are always welcome).
However, reviewers may request that you complete any actions in this list if you have not done so. If you are unsure about an item in the checklist, don't hesitate to ask. We're here to help!
mainbranch of code (unless it is a backport or is fixing an issue specific to an older branch).npm run lintnpm run check-circ-deps)package.json), I've made sure their licenses align with the DSpace BSD License based on the Licensing of Contributions documentation.