[wp-trac] [WordPress Trac] #52438: Theme translations in WP_LANG_DIR are loaded twice, no (logical) way to override from a (child) theme.

WordPress Trac noreply at wordpress.org
Wed Nov 27 18:02:26 UTC 2024


#52438: Theme translations in WP_LANG_DIR are loaded twice, no (logical) way to
override from a (child) theme.
---------------------------------------+-------------------------
 Reporter:  captain.crash              |       Owner:  (none)
     Type:  defect (bug)               |      Status:  closed
 Priority:  normal                     |   Milestone:
Component:  I18N                       |     Version:  5.6
 Severity:  minor                      |  Resolution:  worksforme
 Keywords:  needs-patch needs-testing  |     Focuses:
---------------------------------------+-------------------------

Comment (by captain.crash):

 > Note that I am closing this again, but conversation can continue on
 closed tickets as well.

 Sorry about that. Will leave it closed now.

 ----

 > So if the loading is successful, that next condition will be true.

 Right, ok, that makes sense, although that condition still looks very
 confusing.

 ----

 Finally, about the code for my child theme's `functions.php`:

 The code you provided is pretty much exactly the code I was using and what
 I described under 1) of my original post.

 This loads the desired MO file, but it loads **''instead''** the parent
 theme's translations which means nothing else (!) but the few strings I'm
 trying to override are translated.

 Back when I opened the ticket (WP 5.6) the child theme's MO file loaded
 **''additionally''** to the parent theme's MO files causing all strings of
 one text domain to truely merge.

 Furthermore, back then, downloaded parent theme translations within
 `WP_LANG_DIR` were loaded twice (once always before my child theme MO file
 - what I described under 2) of my original post).

 Now, the parent theme MO file doesn't load ''at all'' with the code you
 provided. The parent theme translations inside the child theme ''override
 nothing'', they are the ''only'' translations loaded for the text domain.

 So, my questions remain (they only need to adapt as this seems to work
 differently now):


 **A)** What I initially meant with "a (logical) way to override from a
 (child) theme" is this. Given functions like `load_theme_textdomain` or
 even `load_child_theme_textdomain`, there should be a clearer way to
 achieve what I'm trying to do than using the code you provided, maybe
 `load_parent_theme_textdomain`?

 **B)** How can I override some translation strings of a parent theme from
 within a child theme **without losing all the other already translated
 strings from the parent theme?**

 I'm using this code logging the loaded MO files:

 {{{
 add_action( 'load_textdomain', function( $domain, $mofile ) {
     echo 'loading file "' . $mofile . '" on domain "' . $domain . '"<br>';
 }, 10, 2);
 }}}

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


More information about the wp-trac mailing list