Please make sure to update to WPML 4.3.5 and check our list of Known Issues before reporting

Hi, Amit here, I am the WPML Support Manager, our current ticket queue is high, update your WPML plugins and make sure you meet the minimal requirements for running WPML before reporting an issue please - many tickets are resolved doing that

Please look at our updated list of Known Issues and you can also use our support search to find helpful information and of course review our documentation before opening a ticket.

If you do need to open a ticket please make sure to provide us with all the needed information as described in this page

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

Our next available supporter will start replying to tickets in about 9.68 hours from now. Thank you for your understanding.

This topic contains 3 replies, has 2 voices.

Last updated by Andreas Neuber 6 years, 10 months ago.

Assigned support staff: Andreas Neuber.

Author Posts
January 25, 2013 at 3:52 pm #99414

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

January 25, 2013 at 5:20 pm #99455

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?

January 29, 2013 at 4:50 pm #100271

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?

January 30, 2013 at 8:17 am #100401

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).

The topic ‘[Closed] Change language programaticly’ is closed to new replies.