#50999 closed defect (bug) (fixed)
Scripts loaded through concatenation don't print their translations.
Reported by: | herregroen | Owned by: | ocean90 |
---|---|---|---|
Milestone: | 5.5.1 | Priority: | high |
Severity: | major | Version: | 5.0 |
Component: | I18N | Keywords: | has-patch needs-testing needs-unit-tests commit |
Focuses: | accessibility, javascript | Cc: |
Description
If a script is loaded through load-scripts.php then it's translations aren't loaded as the translation logic is only called after the handle is added to the $concat
variable has been appended and function returns.
To fix this the same exception should be made for translations as has been made for handles, namely that these are never included in load-scripts.php.
Attachments (2)
Change History (32)
This ticket was mentioned in Slack in #core-editor by tacoverdo. View the logs.
4 years ago
This ticket was mentioned in Slack in #core-editor by bobbingwide. View the logs.
4 years ago
This ticket was mentioned in Slack in #core by joostdevalk. View the logs.
4 years ago
#11
@
4 years ago
- Severity changed from normal to major
Hi,
I tested the proposed patch and it fixes the issue on all place I checked. Media modal, auto-updates screens, customizer, add new plugin screen…
In y opinion this is a major issue and I'm in favor of a quick 5.5.1 release because of that one.
#12
@
4 years ago
- Focuses accessibility added
- Keywords has-patch added
Adding has-patch
workflow keyword and accessibility
focus as this is an accessibility issue as well. Indeed, those unexpected language changes can be considered as an accessibility issue.
This ticket was mentioned in Slack in #core by david.baumwald. View the logs.
4 years ago
#15
in reply to:
↑ 7
@
4 years ago
Replying to bobbingwide:
This patch also fixes #50993.
Gutenberg 8.8.0 also resolves the issue reported in #50993.
This ticket was mentioned in Slack in #core by clorith. View the logs.
4 years ago
This ticket was mentioned in Slack in #forums by otto42. View the logs.
4 years ago
#18
@
4 years ago
I'm still trying to determine exactly what caused this regression. The code being changed in translations-no-concat.patch has been pretty much untouched since it was merged into core in 5.0, so a change elsewhere is most likely the culprit.
I am currently trying to confirm a suspicion that I have that the changes associated with #20491 made in 5.5 are the reason this is happening.
When a script is localized to a handle that is concatenated, the localized script is printed to the page through $print_code
in the WP_Scripts
class. Because they are printed out in the page source, the script can still be loaded through load-scripts.php
.
Switching the JavaScript strings to use wp.i18n
would cause these translations to no longer be printed to the page through WP_Scripts->print_extra_scripts()
because the new method of JS string localization manually prints out the translations after the script is concatenated.
If this thinking is correct, the patch I am attaching should allow scripts with JS translations to continue to be concatenated without the issue. Some testing/sanity checking would be much appreciated.
#19
@
4 years ago
Also, just for completeness, these are some changesets I believe may be causing this issue: [47884,48266,48270,48274,48285,48340,47347-47348,48375,48383-48385,48391-48392,48394-48396].
#20
@
4 years ago
Related: #51123.
I don't think a commonL10n
back-compat shim would fix this specific issue, but definitely related.
This ticket was mentioned in Slack in #core by desrosj. View the logs.
4 years ago
#23
follow-up:
↓ 25
@
4 years ago
I'm struggling to reproduce this before I look into the cause.
Can someone provide steps to reliably reproduce? Maybe @herregroen ? Cheers!
#25
in reply to:
↑ 23
;
follow-ups:
↓ 26
↓ 27
@
4 years ago
Replying to johnbillion:
Can someone provide steps to reliably reproduce? Maybe @herregroen ? Cheers!
- Run
LOCAL_DIR=build npm run env:start
- Run
npm run grunt
- Make sure
SCRIPT_DEBUG
is set to false in wp-config.php - Download and activate https://downloads.wordpress.org/plugin/wordpress-seo.14.8.zip
- Go to http://localhost:8889/wp-admin/options-general.php and select Deutsch/German as site language
- Go to http://localhost:8889/wp-admin/site-health.php
- Notice that the subtitle changes from "Die Ergebnisse werden noch geladen…" to "Should be improved". Correct would be the existing translation "Sollte verbessert werden".
Inspecting the source I see this without the plugin and this with the plugin activated.
50999.diff doesn't work for me, it seems to print raw JS on the page due to missing <script>
tags. translations-no-concat.patch looks better.
#26
in reply to:
↑ 25
@
4 years ago
Replying to ocean90:
Inspecting the source I see this without the plugin and this with the plugin activated.
The difference is caused by the wp-polyfill
script which prevents concatenation due to the inline scripts. In core, it's always enqueued in the footer, thus no concatenation is enabled for most of the scripts. With Yoast SEO activated, wp-polyfill
gets already loaded in the header and disables concatenation only for the header scripts, meaning concatenation is enabled for all footer scripts, making the issue visible.
#27
in reply to:
↑ 25
@
4 years ago
- Keywords commit added
- Version changed from 5.5 to 5.0
Replying to ocean90:
50999.diff doesn't work for me, it seems to print raw JS on the page due to missing
<script>
tags. translations-no-concat.patch looks better.
For 50999.diff you have to keep the part where $translations
gets wrapped with the <script>
tags at the current position because $print_code
gets printed by _print_scripts()
which already adds the <script>
tags. But this still doesn't work as expected because the translation script requires wp.i18n
to be defined which is not the case.
tldr; translations-no-concat.patch should be the way to go here. It's also kind of covered by the Tests_Dependencies_Scripts::test_wp_add_inline_script_before_after_concat_with_core_dependency()
test.
We might want to explore in a separate ticket to re-enable concatenation after a script has been printed which previously prevented concatenation.
Thanks for the report @herregroen !
Does your patch remove all the concatenation for all scripts though?
I wanted to note that a side-effect of the concatenation change in 5.5 is that now that
media-editor.js
is being concatenated (looks like it wasn't in 5.4 by default?), it's causing some issues when using another concat plugin in conjunction like: https://github.com/Automattic/nginx-http-concat/The patch in this ticket does fix our problems though because it removes things like
media-editor.js
from being concatenated.I'm curious about the reasoning to start concatenating
media-editor.js
and other scripts like that and if we're seeing other problems like the one I mentioned.