I'm using WordPress in french with the plugin The Events Calendar.
This plugin comes with a bundled french translation but it has some mistakes. I want to fix them but replacing the original file is a bad idea since it's gonna be replaced with the next update. I contacted the developer to submit a fix but it may take some time.
In the meantime, I would like to load a duplicate I did from my template directory. I already tried multiple things like:
load_plugin_textdomain( 'tribe-events-calendar', get_template_directory() . '/languages' );
Or with
add_filter('override_load_textdomain', …)
in my functions.php but it doesn't seem to work. The only thing I was able to do is disabling the load of the original translation file.
Is there any way to replace a plugin translation file on load? I use WPML too but in "Translate with .mo files" mode not in "Translate with WPML" so I can't change plugin translation on the fly. Maybe WPML can load my own translation of The Events Calendar?
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 plugin
unload_textdomain($text_domain);
// Load first the override file
load_textdomain($text_domain, $override_language_file );
// Then load the original translation file
load_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 :
This works only with compiled mo file.
You can only add to your override file the few strings you want to override.