• Hi,

    I am encountering an issue where translations for my plugin Custom Order Numbers for WooCommerce are not working as expected with Loco Translate when using the “Author” or “Custom” translation location options.

    Here’s a brief overview of my setup:
    Plugin Text Domain: custom-order-numbers-for-woocommerce
    WordPress 6.7
    Translation Loading Code as below: Basically this is the patch I have done after the WordPress 6.7 to correct the translation issue where the notice is being displayed for translation loading too early.

    add_action( 'plugins_loaded', array( &$this, 'con_load_textdomain' ) );

    public function con_load_textdomain() {
    $domain = 'custom-order-numbers-for-woocommerce';
    $locale = apply_filters( 'plugin_locale', get_locale(), $domain );
    $loaded = load_textdomain( $domain, trailingslashit( WP_LANG_DIR ) . $domain . '-' . $locale . '.mo' );

    if ( $loaded ) {
    return $loaded;
    } else {
    load_plugin_textdomain( $domain, false, __DIR__ . '/langs/' );
    }
    }

    Translation Files: .po and .mo files are present in /langs/ and are correctly named.

    Issue: When using Loco Translate:

    1. The translations work with the System location but fail with the Author or Custom options.
    2. Despite having the correct file structure and permissions, the translations from these locations are not being applied.

    Troubleshooting Steps Taken:

    • Verified the .mo and .po files are generated correctly.
    • Checked the locale using get_locale(), and it matches the file names.
    • Tested with the default WordPress theme and no other plugins activated.
    • Enabled debugging, but no errors related to translation loading are logged.

    Also, checked with the init and after_setup_theme but it didn’t help.

    Could this be an issue with how the load_textdomain and load_plugin_textdomain functions are used in my code? Or does Loco Translate require additional adjustments for plugins that load translations manually?

    You can take this patch copy to check the issue.

    Any guidance or insights would be greatly appreciated!

    Thank you for your time.

    Regards,
    Kartik Parmar

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Tim W

    (@timwhitlock)

    Thanks for the detail. This is a very frustrating situation, and I’m not holding out for hope that the proposed fix in WP 6.7.1 will actually work when GlotPress translations have been early loaded. You can track my attempts to convince the WordPress core team that this is a real thing, but I suspect they’ll reject the notion because it’s not a direct concern for GlotPress translation.

    Moving on…

    There are a couple of reasons your patch doesn’t work. Firstly, the path to the system file you reference is actually wrong (it needs "plugins/" in the middle. With this it will work for the “custom” location.

    Separately, your load_plugin_textdomain function doesn’t actually load anything. I don’t want to get into that, because it’s a disaster, and only needed for “author” locations anyway. I’d recommend against using the author location in your particular situation.

    ANYWAY I don’t recommend you hack the plugin this way at all. I’ll post back shortly with a better solution that works for everyone.

    Plugin Author Tim W

    (@timwhitlock)

    Try the following code. Put it into a plugin, and enable it. Or put in anywhere it will run.

    function_exists('add_action') and add_action('setup_theme',function(){
    global $l10n, $l10n_unloaded;
    if( is_array($l10n) ){
    foreach( $l10n as $domain => $value ){
    unload_textdomain($domain);
    unset($l10n_unloaded[$domain]);
    }
    }
    });

    This unloads all text domains that have been loaded too early. You can modify this to just unload the domains you’re concerned with.

    Thread Starter kartikparmar

    (@kartikparmar)

    Hi,

    First of all, thank you for your prompt response.

    I checked the provided solution and the “Custom” option started working after adding "plugins/" But there is still an issue with the “Author” option. Its not working even after adding the provided custom snippet.

    Plugin Author Tim W

    (@timwhitlock)

    Don’t use the author location. Your plugin has no author translations, and adding your own here is unsafe from updates.

    The code I provided works for me when using a custom location and the original plugin (not your patched version).

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