• Resolved Kim Hornung

    (@keepmovingdk)


    I think I might have discovered a bug in how the l10n.php localization files that are supported since WP 6.5 are generated (alternatively how they are processed).

    When calling __() or other translation functions on a string that does not yet have a translation, the function is supposed to return the original string. Instead, it returns an empty string.

    Here is my scenario:

    1. I have a custom theme with a text domain. I use wp i18n make-pot to generate a .pot file and also use WP-CLI to update the .po files and generate .mo files.
    2. I use wp i18n make-php to also generate the more performant .l10n.php files
    3. We are in the process of adding an extra language to our website, so we have created a new .po file for that language which (at the moment) only have a few strings translated

    For the untranslated strings, the generated PHP file contains entries such as:
    'Log in'=>''

    I’ve debugged the issue, and I can see that the problem is that the locate_translation function in the WP_Translation_Controller class contains the following lines:

    // Find the translation in all loaded files for this text domain.
    foreach ( $this->get_files( $textdomain, $locale ) as $moe ) {
    $translation = $moe->translate( $singular );
    if ( false !== $translation ) {
    return array(
    'entries' => explode( "\0", $translation ),
    'source' => $moe,
    );
    }

    The code expects missing translations to be false, not an empty string. So in this case it will return the empty string as the translation.

    This looks like a bug to me.

    P.S.: I have already implemented a workaround for my theme. I’ve made a gettext hook that checks for such empty translations and returns the original string instead.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi there

    For the untranslated strings, the generated PHP file contains entries such as:

    This is a bug, and was fixed in version 2.6.1 of the wp i18n command. Please update WP-CLI to the latest version (2.11.0 at the time of writing). If you have installed wp-cli/i18n-command separately on top of WP-CLI, use wp package update to update it to the latest version. Then, delete the .l10n.php file and generate it again.

    Thread Starter Kim Hornung

    (@keepmovingdk)

    Excellent! Will do so.
    Thank you for the quick reply.

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.