[wp-trac] [WordPress Trac] #62337: i18n: Translation is not applied in load_theme_textdomain() function

WordPress Trac noreply at wordpress.org
Wed Nov 13 10:45:13 UTC 2024


#62337: i18n: Translation is not applied in load_theme_textdomain() function
--------------------------------------+-------------------------
 Reporter:  wildworks                 |       Owner:  swissspidy
     Type:  defect (bug)              |      Status:  reviewing
 Priority:  normal                    |   Milestone:  6.7.1
Component:  I18N                      |     Version:  6.7
 Severity:  normal                    |  Resolution:
 Keywords:  has-patch has-unit-tests  |     Focuses:
--------------------------------------+-------------------------

Comment (by stimul):

 We found a workaround, maybe not the best solution but it seems to be
 working fine. Maybe this can help debug the issue.

 Before:

 {{{#!php
 <?php
 add_action('after_setup_theme', function() {
   load_theme_textdomain('our_theme_name_domain', get_template_directory()
 . '/languages');
 });
 }}}


 After:

 {{{#!php
 <?php
 add_action('init', function() {
   global $l10n, $wp_textdomain_registry;
   $domain = 'our_theme_name_domain';
   $locale = get_locale();
   $wp_textdomain_registry->set($domain, $locale, get_template_directory()
 . '/languages');
   if ( isset( $l10n[ $domain ] )) {
     unset( $l10n[ $domain ] );
   }
   load_theme_textdomain($domain, get_template_directory() . '/languages');
 });
 }}}

 One interesting thing is that the workaround only works on "init" and not
 with the "after_setup_theme" callback.

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


More information about the wp-trac mailing list