Skip to content

Instantly share code, notes, and snippets.

@mikejolley
Last active August 13, 2021 02:27
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save mikejolley/84779259d3629edb7543 to your computer and use it in GitHub Desktop.
Save mikejolley/84779259d3629edb7543 to your computer and use it in GitHub Desktop.
Load a custom translation file from the WP_LANG directory
// Code to be placed in functions.php of your theme or a custom plugin file.
add_filter( 'load_textdomain_mofile', 'load_custom_plugin_translation_file', 10, 2 );
/*
* Replace 'textdomain' with your plugin's textdomain. e.g. 'woocommerce'.
* File to be named, for example, yourtranslationfile-en_GB.mo
* File to be placed, for example, wp-content/lanaguages/textdomain/yourtranslationfile-en_GB.mo
*/
function load_custom_plugin_translation_file( $mofile, $domain ) {
if ( 'textdomain' === $domain ) {
$mofile = WP_LANG_DIR . '/textdomain/yourtranslationfile-' . get_locale() . '.mo';
}
return $mofile;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment