0

I have plugin and theme translations for my language and they work great.

I had to change some translations in a few plugins and theme per customer needs.

Today I updated WooCommerce and I lost my custom translations.

My questions is, is there a way to make whole wp-content/languages folder safe for updating? Is there a way to add it to child theme or something to make my custom translations update secure?

Thanks & Regards.

0

The short answer is to use the location wp-content/languages/woocommerce/ to store custom translations.

See WooCommerce documentation.

This location should be safe from all WordPress updates. Folders parallel to languages/plugins and languages/themes will not be modified.


To your specific questions:

is there a way to make whole wp-content/languages folder safe for updating?

You can control automatic translation updates with the auto_update_translation filter. e.g.

add_filter( 'auto_update_translation', '__return_false' );

However, this hook does not fire when doing manual updates from wp-admin. This will only protect the folder when doing automatic updates and will stop all your other plugins benefiting from translation updates.

Is there a way to add it to child theme or something to make my custom translations update secure?

Adding translations of a plugin into a child theme suggests a common expectation that WordPress will search your theme for alternative plugin localizations. It won't.

However, you can use filters to change the MO file paths that are loaded. Here's a really simple example:

function filter_load_textdomain_mofile( $mopath, $domain ){
  if( 'woocommerce' === $domain ){
    $mopath = str_replace('/languages/plugins/','/languages/other/',$mopath);
  }
  return $mopath;
}
add_filter('load_textdomain_mofile','filter_load_textdomain_mofile',999,2);

You can use this filter to do all sorts of stuff, like merge translations together etc.. You might find this useful if you need to do this to another plugin that doesn't provide an alternative, safe location.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.