• There are sometimes problems with get_locale so also with __() and _e(), etc.

    My problem was for example when calling:
    add_action( 'wpcf7_before_send_mail', 'SOME_FUNCTION_THAT_USE_TRANSLATED_STRING' );
    and SOME_FUNCTION_THAT_USE_TRANSLATED_STRING returns always EN translation

    This is fix that works for me:

    add_filter( 'locale', 'pll_locale', 999, 1 );
    function pll_locale( $locale ){
    	if( isset( $_COOKIE['pll_language'] ) ){
    		$pll_language = $_COOKIE['pll_language'];
    		$pll_languages_list = get_transient('pll_languages_list');
    		if( is_array( $pll_languages_list ) ){
    			foreach( $pll_languages_list as $lang ){
    				if( $lang['slug'] == $pll_language ){
    					$locale = $lang['locale'];
    					break;
    				}
    			}
    		}
    	}
    	return $locale;
    }
    • This topic was modified 6 years, 1 month ago by kubiq.
  • The topic ‘Wrong locale if early access’ is closed to new replies.