Make WordPress Core

Opened 4 years ago

Closed 4 years ago

Last modified 3 years ago

#49625 closed defect (bug) (wontfix)

load_theme_textdomain() opens local files without domain in their name

Reported by: marekdedic's profile marekdedic Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: I18N Keywords:
Focuses: Cc:

Description (last modified by SergeyBiryukov)


I am developing a theme called crdm-modern and want to add translations for the language cs_CZ. I want to load local .mo files as the translations. In order to do that, I placed a file called in the theme in the languages folder. I tried to use this by calling load_theme_textdomain( 'crdm-modern', get_stylesheet_directory() . '/languages' ). However this failed.

Looking at the source of the function load_theme_textdomain(), I see the following line:

return load_textdomain( $domain, $path . '/' . $locale . '.mo' );

So this would load the file languages/ I think this is a bug and it should instead try to load the file languages/ This would be in line with how the function load_plugin_textdomain() works - that's wha I think it is a bug.

Looking at the code, I think the issue was introduced in [37414] and could be solved by replacing

return load_textdomain( $domain, $path . '/' . $locale . '.mo' );


return load_textdomain( $domain, $path . '/' . $mofile );

Change History (4)

#1 @SergeyBiryukov
4 years ago

  • Description modified (diff)

#2 @ocean90
4 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Status changed from new to closed
  • Version 5.3.2 deleted

Hello @marekdedic, thanks for the report!

It’s correct that the loading of theme translation files differs from plugin files. This was always the case, even before your linked changeset.

Due to backward compatibility we can’t just change it. We the introduction of lazy loading and language packs there also wouldn’t be any benefit in changing it now after so many years. To be honest, plugins should rather not have the text domain.

#3 in reply to: ↑ description @SergeyBiryukov
4 years ago

Hi there, thanks for the ticket!

Replying to marekdedic:

Looking at the code, I think the issue was introduced in [37414]

As noted above, while [37414] rearranged some logic, loading $ instead of {$domain}-{$locale}.mo from the theme's directory is not new, it works this way since the introduction in [1808].

Some history:

This is reflected in load_theme_textdomain() description:

If the current locale exists as a .mo file in the theme's root directory, it will be included in the translated strings by the $domain.

The .mo files must be named based on the locale exactly.

#4 @SergeyBiryukov
3 years ago

#52656 was marked as a duplicate.

Note: See TracTickets for help on using tickets.