Changes between Initial Version and Version 1 of Ticket #57079
- Timestamp:
- 11/11/2022 06:46:25 PM (13 months ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #57079
- Property Focuses performance coding-standards removed
-
Ticket #57079 – Description
initial v1 3 3 **Part I** 4 4 5 I am a developer for W3TC and recently diagnosed an issue with our plugin under WP6.0.3/PHP8.1 regarding the use of an admin_print_scripts-{$hook_suffix} not applying under non-english translation due to our plugin's topmost menu page via add_menu_page containing a translated $menu_title parameter. This resulted in the hook's $page_type parameter under get_plugin_page_hooknamebeing translated, thereby not allowing our JS/CSS to print as expected5 I am a developer for W3TC and recently diagnosed an issue with our plugin under WP6.0.3/PHP8.1 regarding the use of an `admin_print_scripts-{$hook_suffix}` not applying under non-english translation due to our plugin's topmost menu page via `add_menu_page` containing a translated `$menu_title` parameter. This resulted in the hook's `$page_type` parameter under `get_plugin_page_hookname` being translated, thereby not allowing our JS/CSS to print as expected 6 6 7 Under es_EStranslation:8 Expected: page hook = performance_page_w3tc_extensions9 Received: page hook = actuacion_page_w3tc_extensions7 Under `es_ES` translation: 8 Expected: page hook = `performance_page_w3tc_extensions` 9 Received: page hook = `actuacion_page_w3tc_extensions` 10 10 11 11 I determined 2 solutions 12 1. Remove the translation from the add_menu_pageresulting in the topmost menu item remaining in English which isn't preferred12 1. Remove the translation from the `add_menu_page` resulting in the topmost menu item remaining in English which isn't preferred 13 13 {{{#!php 14 14 <?php … … 26 26 }}} 27 27 28 2. Apply translations to our $hook_suffix in each use of admin_print_scripts-{$hook_suffix}which is preferred but seems "hackish"28 2. Apply translations to our `$hook_suffix` in each use of `admin_print_scripts-{$hook_suffix}` which is preferred but seems "hackish" 29 29 {{{#!php 30 30 <?php … … 37 37 **Part II** 38 38 39 Additionally with regard to applying translations I discovered that the user's locale/language setting (added in WP 4.7) wasn't applying for our plugin if the core language setting was set to non-english with our translation files automatically copied to wp-content/languages/plugins. My solution to this also felt "hackish" in that we reset the global $l10n and $l10n_unloaded variables before applying our load_plugin_textdomain. I attempted various other solutions I found during my research but non resolved the issue despite documentation seeming fairly straightforward and simple. My question here is whether the default behavior when applying translations to a plugin via load_plugin_textdomaintakes the user's locale/language setting into account and/or if additional code is required for it to apply? Additionally the documentation for internationalizing themes/plugins doesn't appear to mention or reference the user locale/language setting so perhaps this needs to be updated?39 Additionally with regard to applying translations I discovered that the user's locale/language setting (added in WP 4.7) wasn't applying for our plugin if the core language setting was set to non-english with our translation files automatically copied to `wp-content/languages/plugins`. My solution to this also felt "hackish" in that we reset the global `$l10n` and `$l10n_unloaded` variables before applying our `load_plugin_textdomain`. I attempted various other solutions I found during my research but non resolved the issue despite documentation seeming fairly straightforward and simple. My question here is whether the default behavior when applying translations to a plugin via `load_plugin_textdomain` takes the user's locale/language setting into account and/or if additional code is required for it to apply? Additionally the documentation for internationalizing themes/plugins doesn't appear to mention or reference the user locale/language setting so perhaps this needs to be updated? 40 40 41 41 Via init hook: