6

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?

7
  • I wonder, so a plugin is updated and you expect it to keep working with an outdated translation? Commented Apr 14, 2018 at 16:05
  • 2
    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. Commented Apr 15, 2018 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. Commented Apr 15, 2018 at 12:39
  • I like the idea of creating a custom language domain. How is it possible? Commented Apr 15, 2018 at 19:48
  • never tried it myself, but you can tryto change the locale in wp-config.php to something that do not exist.This should revert the UI to english, but let you use tools like loco (based on my limited understanding of it) to create your translations, and if the are useful translations for core and plugins that you like, you can just change the names of those files to mattch your "private" locale Commented Apr 16, 2018 at 1:17

2 Answers 2

1

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.

2
  • I'm trying the first approach and I will get back to you on that. Commented May 1, 2018 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' );} Commented May 2, 2018 at 12:57
3

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 and acknowledge you have read our privacy policy.

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