I'm trying to show different language on front end based on page post meta setting. Mine problem is that I can see that locale is changed, but text still stays in English. Only if I change locale trough 'Settings > General' and set it to desired one, my translations load up and display correctly.
add_filter( 'locale', 'set_my_locale' );
function set_my_locale( $lang ) {
if ( get_field('page_language', get_the_ID() ) ) {
$lang = get_field('page_language', get_the_ID() );
}
return $lang;
}
function load_textdomain(){
$domain = 'textdomain';
load_theme_textdomain( $domain, trailingslashit( WP_LANG_DIR ) . $domain );
load_theme_textdomain( $domain, get_stylesheet_directory() . '/lang' );
load_theme_textdomain( $domain, get_template_directory() . '/lang' );
}
add_action( 'after_setup_theme', 'load_textdomain' );
If I try to print_r( get_locale() );
I can see that correct locale is set, but translations are not displayed, but instead I see original text.
If someone can point me please?
Should I use some different hook, or what I'm doing wrong?