Override a WordPress plugin translation file on load Override a WordPress plugin translation file on load wordpress wordpress

Override a WordPress plugin translation file on load


You can add this few lines in your functions.php theme file

$text_domain = 'the-events-calendar';$original_language_file = ABSPATH . DIRECTORY_SEPARATOR . 'wp-content' . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'the-events-calendar' . DIRECTORY_SEPARATOR . 'languages' . DIRECTORY_SEPARATOR . 'the-events-calendar-fr_FR.mo';$override_language_file = ABSPATH . DIRECTORY_SEPARATOR . 'wp-content' . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . 'your-own-theme' . DIRECTORY_SEPARATOR . 'languages' . DIRECTORY_SEPARATOR . 'the-events-calendar-fr_FR.override.mo'; // Unload the translation for the text domain of the pluginunload_textdomain($text_domain);// Load first the override fileload_textdomain($text_domain, $override_language_file );// Then load the original translation fileload_textdomain($text_domain, $original_language_file );

You'll have to replace the two file variables with the actual language file.

But we'll suppose that the french language file is in the plugin language folder and your override language file is in the language theme folder.

The idea is to :

  • Un load the language that has already been loaded automatically by WP
  • Load your override file first. This is important to load it first, because already defined translations will be skipped when you'll load another language file for this text domain (see WP core).
  • Load the original translation file, which will in fact load all the untranslated strings of the override file.

This works only with compiled mo file.

You can only add to your override file the few strings you want to override.


I am the author of the Transposh plugin,

Your answer actually is in the following four filters:

   add_filter('gettext', ......, 3);   add_filter('gettext_with_context', ......, 3);   add_filter('ngettext', ......, 4);   add_filter('ngettext_with_context', ....., 4);

(Naturally, you need to add the function and the priority instead of the .....)

Those functions will get the strings and the domain, and you can use those to do functions like:

function gettext_filter($translation, $orig, $domain) {    if ($domain == 'plugin_domain') {        if ($orig == 'some text') {            return "some translation";        }    }    return $translation;}


This solution uses wordpress's automatic loaders to override the plugin and doesn't need additional programming logic, instead it lets the CMS do the override.

Let's say you want to translate a plugin called my-plugin. A properly built plugin would have two translated file in the directory wp-content/languages/plugins/ called my-plugin-fr_FR.po and my-plugin-fr_FR.mo.

If your plugin has this structure, the steps below will override the translations, if not you can try and see anyway:

  1. Copy the .po and .mo files mentioned above into the directory wp-content/languages/my-plugin. If the directory doesn't exist, create it.
  2. Edit the translation files as you wish and save them.