I’m using Codestyling Localization and I want to translate a plugin and I want the translation files to be saved in the translation directory in the theme I’m building and not in the plugins directory.
Is this possible?
I have tried load_plugin_textdomain
and load_textdomain
but that doesn’t seem to work.
// Add localization
load_theme_textdomain( 'my_theme', $translation_directory );
$domain = 'other_plugin';
$locale = apply_filters('plugin_locale', get_locale(), $domain);
load_textdomain( $domain, WP_LANG_DIR."https://wordpress.stackexchange.com/".$domain.'/languages/'.$domain.'-'.$locale.'.mo');
load_plugin_textdomain( $domain, FALSE, $translation_directory );
First of all, I’d strongly recommend against storing translations for a plug-in in your theme. It has no reason to be there, and you’ll loose the translations when you change/update the theme.
The correct place to store translations is wp-content/languages/plugins/
.
This code does that, and targets the domain ‘other_plugin’:
function wpse159536_override_mofile_path( $mofile, $domain ){
if( 'other_plugin' == $domain ){
$mofile = WP_LANG_DIR . '/plugins/' . basename( $mofile );
}
return $mofile;
}
add_filter( 'load_textdomain_mofile', 'wpse159536_override_mofile_path', 10, 2 );
Of course, an even better solution would be to send the translation file to the developer to include in the next release (if this is appropriate).