WordPress.org

Forums

Loco Translate
[resolved] Loco Translate & Woocommerce: Selection of translation files (9 posts)

  1. EA10
    Member
    Posted 1 year ago #

    I have a problem when using Loco Translate with WooCommerce, with having the translated files update-save in /wp-content/languages/plugins/.

    WooCommerce has it's translations in /wp-content/plugins/woocommerce/i18n/languages/
    In this folder there are 2 .pot files, woocommerce.pot and woocommerce-admin.pot and po/mo files for each language.
    On the Loco management page only one .pot file is shown, woocommerce.pot, none of the files for admin translations show up. That's ok for me as I only need to change translations in the frontend.

    I copied the po and mo file of the language I want to translate to the global folder /wp-content/languages/plugins/, it is recognized by Loco and changes to the file are saved correctly through Loco.

    But when viewing the site, translations are still loaded from the standard language file in WooCommerce plugins folder and not from the custom file in the global folder.

    Only when I delete the original file from Woocommerce folder, the custom/global file gets loaded. But this would have to be done every time there comes an update for WooCommerce.

    Is there any way to change this, so translations always get loaded from the global folder if they exist there?

    Many thanks in advance!

    PS all language folders and files involved are chmod 777

    https://wordpress.org/plugins/loco-translate/

  2. timwhitlock
    Member
    Plugin Author

    Posted 1 year ago #

    There are two issues here.

    1. The second POT file:
    Loco can't currently handle multiple text domains per plugin. This is a restriction that will hopefully be resolved in the future, but you say for now this is not a problem for you.

    2. Files not loading from global languages folder:
    Loco does not control what files are loaded, or in what order - it controls only where they are saved and will always try to save them where you've already placed them.

    WordPress always checks the global languages directory second, so if a file is matched in your plugin folder for the same languages, it will be used. Look at the load_plugin_textdomain to see how this works.

  3. EA10
    Member
    Posted 1 year ago #

    Thank you!

    What is the recommended way to keep custom translations at plugin updates?

    Or shouldn't I create languages files at all when the desired language already exists and I only need to change several wordings?

  4. timwhitlock
    Member
    Plugin Author

    Posted 1 year ago #

    I suggest you try to use a filter to fix the problem of the default loading order.

    Take a look at the filters in the load_textdomain function -- override_load_textdomain seems like a good candidate for avoiding the load of the plugin's own language files. Returning true looks like it would then cause WordPress to load from the global languages directory.

  5. EA10
    Member
    Posted 1 year ago #

    Thanks, I tried adding
    add_filter( 'override_load_textdomain', '__return_true' );
    to functions.php but now it displays the original english strings instead of any translations. Any idea?

  6. timwhitlock
    Member
    Plugin Author

    Posted 1 year ago #

    I'm afraid not, no. It was just a suggestion.

  7. EA10
    Member
    Posted 1 year ago #

    Ok thanks... may I ask how you handle to keep translations from being overridden during plugin updates?

    If the normal way really is to restore them from backup after any update, it would be a killer feature for Loco Translate to automate this somehow.

  8. timwhitlock
    Member
    Plugin Author

    Posted 1 year ago #

    The same way you've already tried - using the global languages directory.

  9. EA10
    Member
    Posted 1 year ago #

    And then delete the original file from the plugins folder after any update?

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Loco Translate
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic