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.
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
⚠️ Load later for i18n (Enhance i18n of attendees-email...) #752
⚠️ Load later for i18n (Enhance i18n of attendees-email...) #752
Changes from 11 commits
67c5ff7
ba03e38
4fec728
da57071
eb20906
6ffc797
4d012cf
65905e8
8867db1
bd0fdb7
02358ab
7e5aae7
38c9f07
3b9a063
3c2230a
41681fe
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
You really don't need this. It's pointless and only has downsides. And saying "A call to load_plugin_textdomain() is ABSOLUTELY NEEDED" is purely WRONG.
The just-in-time translation loading in WordPress handles everything for you and only loads the translations when needed.
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.
Hmm... a little bit strange.
I absolutely trust you in translation stuff, because I know you have been advocating and coding a lot for that topic.
From my long doc-comment you can imagine that I read & tried a lot to come up with my solution and the UPPERCASE comment. But unfortunately I can not make this work, without that line of code. Or maybe I have the wrong expectations.
How to test
Set site language to English in
wp-admin/options-general.php
Set user prefered language to German in
wp-admin/profile.php
Comment out
load_plugin_textdomain( 'gatherpress', false, false )
Check that the Admin-UI is German now, except everything GatherPress
Re-Enable
load_plugin_textdomain( 'gatherpress', false, false )
Check that the Admin-UI is German now, including everything GatherPress
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.
The issue is that you are triggering just-in-time translation loading too early.
WordPress tries to load the translations automatically as soon as you call
__()
. In your case, this happens somewhere before the current user is loaded, thus the admin won't be in German.With this manual
load_plugin_textdomain()
call you're just papering over this issue, causing WP to try to load the translations twice.The proper fix is to initialize your plugin later. This in the main plugin file works:
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.
Ok, thank you very much Pascal, once again your explanation is better than any docs (I know) about that.
I followed your advise:
add_action( 'plugins_loaded', array( '\GatherPress\Core\Setup', 'get_instance' ));
// add_action( 'init', array( $this, 'load_gatherpress_textdomain' ), 0 );
Assets->localize()
, which calls'timezoneChoices' => Utility::timezone_choices(),
and seems to be the culprit. Disabling this line brings all translations back into shape; having this enabled messes things up.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.
Hello @mauteri ,
do we really need all possible timezones
https://github.com/carstingaxion/gatherpress/blob/02358ab60318a7464e31865ffea0f3bb8c961809/includes/core/classes/class-assets.php#L306
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.
Isn't
Assets::localize()
only called inAssets::add_global_object()
which is hooked towp_head
? So that should be late enough.Aside: just adding a script tag like this is usually not a good idea. You should at least use
wp_print_inline_script_tag
. Even better, attach it to a specific script withwp_add_inline_script
.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.
Bildschirmaufzeichnung.vom.05.09.2024.16.08.52.mp4
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.
Found it: 🎉
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.
As expected, a change like to the load order will break things. At least the unit tests.
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.
Thanks for taking the time again @swissspidy !
And on
admin_print_scripts
, which is the problematic trace.👍 I wanted to suggest the same, even that the relevant data - the timezones, in this case - are only used for the Event Date Block (#684)