Ad Label
Hello,
I am having trouble in trying to change the language in my code , just like this thread:
http://wpml.org/forums/topic/set-language-in-code-before-page-loads/
I have trien following the stepf here but no luck. Here's my code:
add_action('after_setup_theme', 'my_icl_set_current_language');
function my_icl_set_current_language() {
$lang = $_GET['lang'];
global $sitepress;
$sitepress->switch_lang($lang);
die(ICL_LANGUAGE_CODE );
}
The ICL_LANGUAGE_CODE constant never changes to the desired language.
Can you please provide some help?
Thanks in advance,
Luis
Andreas Neuber
Supporter
Languages:
English (English )
German (Deutsch )
Hello AdLabel,
The code looks altogether correct. The constant ICL_LANGUAGE_CODE will have as its value the default language set.
So for your tests you would rather need to use a...
die($sitepress->get_current_language());
Do you need this function for AJAX?
Ad Label
Hi,
Yes, this is to be used in ajax.
In your documentation it reads that ICL_LANGUAGE_CODE holds the current language, shouldn't it reflect the language we chose?
Andreas Neuber
Supporter
Languages:
English (English )
German (Deutsch )
Hello AdLabel,
The problem here is that the value of constant ICL_LANGUAGE_CODE is set when the instance of the sitepress class is created. Or in other words, its value changes only with a new page call.
plugins/sitepress-multilingual-cms/inc/template-constants.php:
<?php
// part of SitePress class definition
if(!defined('ICL_LANGUAGE_CODE')){
define('ICL_LANGUAGE_CODE', $this->this_lang);
}
However, with AJAX you are not calling the website new in the browser, just a part of it (the basic concept of AJAX).