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

enh: Split translations by components to only include needed strings in app bundles #4861

Merged
merged 3 commits into from Dec 26, 2023

Conversation

susnux
Copy link
Contributor

@susnux susnux commented Nov 21, 2023

☑️ Resolves

On build time:

  1. Translations are extracted
  2. Not translated strings are discarded (fallback to English)
  3. Translation objects are compressed
  4. Translations are split by files that use that translation string

Then a vite plugin will intercept all imports for 'src/l10n.js' and replace the content with a wrapper that only injects the used translations of the importing file.

Results

Tested with logreader app:

Before
Building logreader for production
vite v4.5.0 building for production...
✓ 1367 modules transformed.
./css/logreader-main.css       99.63 kB │ gzip:  16.69 kB
./js/Splitter-9140b094.mjs      0.97 kB │ gzip:   0.59 kB │ map:     3.29 kB
./js/logreader-main.mjs     1,645.71 kB │ gzip: 390.74 kB │ map: 5,876.41 kB
After
Building logreader for production
vite v4.5.0 building for production...
✓ 1366 modules transformed.
./css/logreader-main.css      100.89 kB │ gzip:  16.89 kB
./js/Splitter-9140b094.mjs      0.97 kB │ gzip:   0.59 kB │ map:     3.29 kB
./js/logreader-main.mjs     1,492.89 kB │ gzip: 371.30 kB │ map: 6,063.92 kB

🏁 Checklist

  • ⛑️ Tests are included or are not applicable
  • 📘 Component documentation has been extended, updated or is not applicable

@susnux susnux added enhancement New feature or request l10n Localization labels Nov 21, 2023
@susnux susnux force-pushed the feat/split-translations-by-component branch 4 times, most recently from ef12361 to 89ba852 Compare November 21, 2023 15:40
@susnux susnux marked this pull request as ready for review November 21, 2023 15:40
@susnux susnux added the 2. developing Work in progress label Nov 21, 2023
@susnux susnux marked this pull request as draft November 21, 2023 16:40
@susnux susnux force-pushed the feat/split-translations-by-component branch from 89ba852 to 814f9c0 Compare November 21, 2023 16:56
@susnux susnux added 3. to review Waiting for reviews and removed 2. developing Work in progress labels Nov 21, 2023
@susnux susnux marked this pull request as ready for review November 21, 2023 16:56
@ShGKme

This comment was marked as resolved.

@ShGKme

This comment was marked as resolved.

@susnux

This comment was marked as resolved.

@susnux

This comment was marked as resolved.

@ShGKme

This comment was marked as resolved.

ShGKme

This comment was marked as resolved.

@susnux

This comment was marked as resolved.

@susnux susnux force-pushed the feat/split-translations-by-component branch from 814f9c0 to 5fde15e Compare November 24, 2023 00:54
@susnux susnux requested a review from ShGKme November 24, 2023 00:54
@susnux susnux dismissed ShGKme’s stale review November 27, 2023 13:23

Fixed the build issue

@susnux susnux force-pushed the feat/split-translations-by-component branch from 5fde15e to 432e3a3 Compare November 27, 2023 13:23
@susnux
Copy link
Contributor Author

susnux commented Nov 27, 2023

I fixed the issue with vite internal modules being present in output bundle, so it now also works if your app uses webpack ✔️

Copy link
Contributor

@ShGKme ShGKme left a comment

Choose a reason for hiding this comment

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

The dist looks good and correct without any extra translations, the translations on server and Talk work fine. Doesn't change a lot in size for 1 app, but multiplies for every app and library.

build/l10n-plugin.mts Outdated Show resolved Hide resolved
@ShGKme
Copy link
Contributor

ShGKme commented Nov 28, 2023

Thank you @susnux, awesome work!

@susnux susnux modified the milestones: 8.3.0, 8.4.0 Nov 28, 2023
…in app bundles

Translations are extracted, not translated strings are discarded (fallback to english) and compressed.
On build time the translations are then injected by a vite plugin depending on the importing files so only used translations are imported.

Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
…plitting

Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
… longer needed

Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
@susnux susnux force-pushed the feat/split-translations-by-component branch from 432e3a3 to a966985 Compare December 6, 2023 18:54
@susnux susnux requested review from skjnldsv and removed request for skjnldsv December 6, 2023 18:54
@skjnldsv skjnldsv merged commit 76cc5de into master Dec 26, 2023
16 checks passed
@skjnldsv skjnldsv deleted the feat/split-translations-by-component branch December 26, 2023 07:52
@ShGKme ShGKme mentioned this pull request Dec 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3. to review Waiting for reviews enhancement New feature or request l10n Localization
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Split translations by component
4 participants