4

There are two ways that WordPress updates translation files inside Languages folder: 1. Automatic updates whenever it gets triggered. 2. Manually when user requests it on "Updates" page.

Is there a way to disable both of them, so no changes can apply to Languages folder?

  • I wonder, so a plugin is updated and you expect it to keep working with an outdated translation? – Mark Kaplun Apr 14 '18 at 16:05
  • ... maybe you should ask the actual question that bothers you instead of asking about a solution which might not be a good idea to implement – Mark Kaplun Apr 14 '18 at 16:06
  • 1
    To answer the question, Yes! WordPress translations for my language is very poor and I need a very fast solution (like using loco translate) to fix them. The problem is, they get updated constantly. I know changing the language files is not a good practice and there are functions to overwrite the translations. That question is asked and answered before. I'm looking for this specific way. And I find it very hard to believe that there are no way of doing it. – Rahmat Baghdadi Apr 15 '18 at 12:29
  • it should be possible to do in the same way that you disable plugin update. actually never looked at the language update code therfor I do not have an actual answer, but maybe a workaround is to invent your own language domain (which is what you are kind of doing), this way the update will always fail in getting "updated" versions. – Mark Kaplun Apr 15 '18 at 12:39
  • I like the idea of creating a custom language domain. How is it possible? – Rahmat Baghdadi Apr 15 '18 at 19:48
0

You've already given the answer using auto_update_translation. I wasn't aware this didn't work after manual updates (and haven't tried it) but perhaps also look at async_update_translation which according the documentation "Asynchronously upgrades language packs after other upgrades have been made".


Regardless of the above, I recommend a different approach whereby the community translations are still installed, but your own custom translations override when (and only when) they exist.

This means you have the advantage of improving the translations you dislike, while still benefiting from any new translations appearing before you know about them. (i.e. source strings changing after plugin updates).

To do this you'll have two copies of each language file and force WordPress to load them on top of each other with yours taking precedence.

(1) Mimic the languages folder structure in a parallel directory, and move your own custom translation files so you have paths like this for whatever your language is:

wp-content/my-translations/plugins/foo-en_GB.mo

(2) Add the following code as a must-use plugin to ensure it's ready before anything else tries to bootstrap its translations.

<?php
/*
Plugin Name: Custom Translations
Description: Merges translations under my-languages on top of those installed.
*/

function my_custom_load_textdomain_hook( $domain = '', $mofile = '' ){
    $basedir = trailingslashit(WP_LANG_DIR);
    $baselen = strlen($basedir);
    // only run this if file being loaded is under WP_LANG_DIR
    if( $basedir === substr($mofile,0,$baselen) ){
        // Our custom directory is parallel to languages directory
        if( $mofile = realpath( $basedir.'../my-languages/'.substr($mofile,$baselen) ) ){
            load_textdomain( $domain, $mofile );
        }
    }
}

add_action( 'load_textdomain', 'my_custom_load_textdomain_hook', 10, 2 );

Note that your custom files need only contain the strings you want to change. This relies on WordPress's current merging strategy. In the code above your file actually completes first, then is merged on top of the installed file.

  • I'm trying the first approach and I will get back to you on that. – Rahmat Baghdadi May 1 '18 at 16:08
  • That actually worked. For noobies like me, you need to add this to your child theme's function.php: if( function_exists('add_filter') ){add_filter( 'auto_update_translation', '__return_false' ); add_filter( 'async_update_translation', '__return_false' );} – Rahmat Baghdadi May 2 '18 at 12:57
1

I have this snippet that disables automatic translation update:

if( function_exists('add_filter') ){add_filter( 'auto_update_translation', '__return_false' );}

That's one problem solved. But if I update plugins manually, WordPress updates translations afterward. How to fix this part too? Any ideas?

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.