Created
July 2, 2015 10:21
-
-
Save mariusvetrici/1a15713f34a2e2d92f86 to your computer and use it in GitHub Desktop.
Translate Plugin From Child Theme - ever needed to translate some strings from a plugin so as to be able to further upgrade the main plugin without loosing your translations?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action( 'after_setup_theme', 'load_custom_translations'); | |
function load_custom_translations(){ | |
load_child_theme_textdomain( 'woocommerce-bookings', get_stylesheet_directory() . '/translations' ); | |
load_child_theme_textdomain( 'woocommerce-social-login', get_stylesheet_directory() . '/translations' ); | |
} | |
add_filter( 'load_textdomain_mofile', 'filter_custom_translation_paths', 10, 2); | |
/** | |
* Update the path for loading custom translations for plugins | |
* @param $mofile Original mo file; | |
* @param $domain The plugin domain | |
* | |
* @return mixed The new filtered path | |
*/ | |
function filter_custom_translation_paths($mofile, $domain) { | |
// If the mofile to be translated is not our default child theme file | |
if (false === strpos($mofile, '/wp-content/themes/my_theme/translations/ro_RO.mo')) { | |
return $mofile; | |
} | |
else { | |
return trailingslashit(dirname( $mofile )) . $domain . '-' . basename( $mofile ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This helped me. Thanks :)