[wp-trac] [WordPress Trac] #58848: `wp_set_script_translations` only sets translations for the default language
WordPress Trac
noreply at wordpress.org
Fri Jul 28 15:48:41 UTC 2023
#58848: `wp_set_script_translations` only sets translations for the default
language
-------------------------------+------------------------------
Reporter: dathix | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: I18N | Version: 6.2
Severity: normal | Resolution:
Keywords: reporter-feedback | Focuses:
-------------------------------+------------------------------
Comment (by dathix):
I can happily provide some more information but unfortunately, there is
not much to say in addition to my previous message. Down below you will
find the code that we are using to load the script translations. The site
uses a ''Sage 10'' theme and ''acorn'' to bundle the scripts. We want to
register the translations to all our scripts so therefore the loop.
{{{lang_path()}}} is a helper function from acorn that provides us with
the path of the language folder inside our theme. This folder contains two
sets of JSON language files (German & French) generated by the i18n CLI
command. But as I said this setup works fine with WordPress <6.2.
{{{
add_action('wp_enqueue_scripts', function () {
$app = bundle('app')->enqueue();
foreach (array_keys($app->js()->keys()->toArray()) as $handle) {
wp_set_script_translations("app/$handle", 'default', lang_path());
}
}, 100);
}}}
Without the call of {{{wp_set_script_translations()}}} I am getting my
default strings in English inside my scripts. The function seems to only
registers the German translations from the JSON files. As a test, I
deleted the JSON files for the German translation and tried to only
register the French ones but in this case, the function returns false and
I am still getting the English strings. The default language of the site
is set to German (de_CH) and the site uses WPML. But as I already said
nothing else was updated except WordPress.
Thanks in advance and appreciate your effort!
--
Ticket URL: <https://core.trac.wordpress.org/ticket/58848#comment:6>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list