This repository has been archived by the owner on Feb 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 219
Handle translations in lazy loaded files by injecting them into the page #4897
Merged
Conversation
This file contains 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
Size Change: 0 B Total Size: 1.23 MB ℹ️ View Unchanged
|
opr
approved these changes
Oct 6, 2021
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is much cleaner than the first try. To me the code looks good, and it works as advertised. 👍🏼
Thanks for the detailed code comments too, really helpful!
@youknowriad, i18n is an interesting challenge when using lazy loading for JavaScript in general, but it gets even more fun to reason about in the ES Modules world. |
mikejolley
force-pushed
the
fix/4019-inject-lazy-translations
branch
from
October 11, 2021 10:56
18318c0
to
c5bd552
Compare
mikejolley
force-pushed
the
fix/4019-inject-lazy-translations
branch
from
October 11, 2021 13:58
c5bd552
to
f0179e8
Compare
After fixing the vendors file, I have tests running and passing locally now. Merging. |
opr
added
focus: i18n
The issue/PR is related to internationalization.
type: bug
The issue/PR concerns a confirmed bug.
labels
Oct 11, 2021
jonny-bull
pushed a commit
to jonny-bull/woocommerce-gutenberg-products-block
that referenced
this pull request
Dec 14, 2021
…age (woocommerce#4897) * Formalise chunk names * register_chunk_translations() * Rename handle * Include fileSuffix * Remove .chunk prefix- it broke the vendors chunk
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Labels
focus: i18n
The issue/PR is related to internationalization.
type: bug
The issue/PR concerns a confirmed bug.
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.
This is an alternative, simpler fix for #4019 (replaces #4392) inspired by Automattic/jetpack#20926.
#4392 worked, however, it introduced complex webpack plugins, the need to calculate translation hashes to get the correct translation files, and ultimately I think would be difficult to maintain without a more in-depth knowledge of webpack.
Therefore, I've created this alternative approach which injects translations before the blocks script is output to the page.
Where #4392 required a list of
$translated_chunks
, this one just needs a list ofwebpackChunkName
as defined when initializing the lazy components. Everything else is derived from that.Fixes #4019
Closes #4392
Screenshots
Testing
e330894bce4582a6969137e88a76105c
is generated from the path to the chunk script. This PR changes the chunk name, so changee330894bce4582a6969137e88a76105c
tobff28bb492f099ecaf7494b1201c4e46
. This is the md5 hash ofbuild/atomic-block-components/sale-badge.chunk.js
.Changelog