Skip to content

Instantly share code, notes, and snippets.

@tormjens
Last active August 29, 2015 14:07
Show Gist options
  • Save tormjens/ac9adbdf83e23375f27f to your computer and use it in GitHub Desktop.
Save tormjens/ac9adbdf83e23375f27f to your computer and use it in GitHub Desktop.
Replaces a .mo-file based on a text domain. In this case from within a theme. Two different methods. One replacing the plugin text domain all together, and one that just switches the .mo-file.
add_action( 'after_setup_theme', 'myplugin_load_textdomain' );
function myplugin_load_textdomain() {
load_plugin_textdomain( 'my-plugin', false, get_template_directory() . '/my-plugin-lang-dir-in-theme/' );
}
add_filter( 'load_textdomain_mofile', 'myplugin_new_mo', 20, 2 );
function myplugin_new_mo($mo, $domain) {
if( $domain === 'my-plugin-textdomain' ) {
$dir = get_template_directory() . '/my-plugin-lang-dir-in-theme/';
$mo = $dir . 'coolfile.mo';
}
return $mo;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment