[wp-trac] [WordPress Trac] #58848: `wp_set_script_translations` only sets translations for the default language

WordPress Trac noreply at wordpress.org
Mon Jul 31 08:15:09 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):

 > Not sure I follow. When you use this function, WordPress just loads the
 translations for the currently active locale.
 > If your locale is set to de_CH, WP does not load any French
 translations. That‘s by design.
 I am aware of this but before I installed WordPress >=6.2 changing the
 frontend language through WPML's language switcher also switched the
 script translations prior to the update.

 After some further investigation, I was able to fix this issue by adding
 the action below:

 {{{
 add_action('wpml_language_has_switched', function () {
     global $sitepress;

     $lang = $sitepress->get_current_language();
     $locale = $sitepress->get_locale($lang);

     switch_to_locale($locale);
 });
 }}}

 I am just wondering why this worked before.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/58848#comment:8>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list