I have translated the po file and uploaded the mo and po files in the languages folder with the language code file name. But translation is not loading Here is the function file code:
if( is_dir( get_stylesheet_directory() . '/languages' ) ) {
load_theme_textdomain('adifier', get_stylesheet_directory() . '/languages');
} else{
load_theme_textdomain('adifier', get_template_directory() . '/languages');
}
I have translated the po file and uploaded the mo and po files in the languages folder with the language code file name. But translation is not loading Here is the function file code:
if( is_dir( get_stylesheet_directory() . '/languages' ) ) {
load_theme_textdomain('adifier', get_stylesheet_directory() . '/languages');
} else{
load_theme_textdomain('adifier', get_template_directory() . '/languages');
}
Share
Improve this question
edited Jan 7, 2020 at 5:39
leemon
2,0324 gold badges25 silver badges51 bronze badges
asked Jan 6, 2020 at 23:31
Viral UniverseViral Universe
11 bronze badge
1
- Is your code inside the after_setup_theme action hook? – leemon Commented Jan 6, 2020 at 23:41
2 Answers
Reset to default 0Make sure you put your function inside after_setup_theme
action hook
add_action( 'after_setup_theme', 'load_translation' );
function load_translation() {
if( is_dir( get_stylesheet_directory() . '/languages' ) ) {
load_theme_textdomain('adifier', get_stylesheet_directory() . '/languages');
} else {
load_theme_textdomain('adifier', get_template_directory() . '/languages');
}
Also, you have to make sure your theme domain is matched with the translated file.
For an easier method, I'd recommend you to use Loco Translate
, with that plugin you can translate for themes nor plugins directly from wp-admin
Loco Translate Plugin
Salam, I had the same problem but I solved it, You should change the name of the file as you have in wordpress/wp-content-language For exemple me I had just : 'ar.po' not 'ar-Ma.po'