[Closed] switch_lang and load_textdomain does not work in ajax request

Home Support English Support [Closed] switch_lang and load_textdomain does not work in ajax request

This topic contains 6 replies, has 2 voices, and was last updated by  Arian 11 months ago. The support staff assigned to this topic is brooks.

Viewing 7 posts - 1 through 7 (of 7 total)
Author Posts
Author Posts
June 22, 2012 at 11:50 am #64342

Arian

Hi there,

I have a similar problem as the following topic: http://wpml.org/forums/topic/wpml-loads-wrong-mo-file-in-ajax-response/
I have tried many things but is still won't work. It just shows the default.

I use the following code:

<?php 
require_once('../../../wp-load.php');

global $sitepress;

$sitepress->switch_lang('en', true);
$loaded = load_textdomain( 'blueprint', ABSPATH .'wp-content/languages/BlackBerry/'. get_locale() .'.mo');
// when i echo $sitepress->get_current_language() here, it displays 'en'
// when i echo get_locale() here, it displays 'en_US'

// the following file holds the translation fields
require_once('buildTicket.php');

I have tried the following:
- I have loaded the buildTicket.php file from within the template, then everything works fine, the file is perfectly translated in all languages i have. (So the .mo file is correct)
- I made some checkpoints in the load_txtdomain function (wp-includes/I10n.php) to check if the .mo file i am loading is the right one. The function starts loading the en_US.mo and it merges but after that, we still have the default language.

I have the problem in wp 3.3.2 with wpml 2.4.3. I have upgraded to wp 3.4 and wpml 2.5.1 but the problem is still there..

Can anyone tell me what the next step can be in the debugging process

June 25, 2012 at 11:34 am #64652

brooks

Dear Arian,
Is the ICL_LANGUAGE_CODE constant is changing ?

June 26, 2012 at 8:50 am #64850

Arian

Dear brooks,

A constant is designed to be constant, it stays the same in the execution time of the script.

June 26, 2012 at 11:39 am #64895

brooks

$loaded = load_textdomain( 'blueprint', ABSPATH .'wp-content/languages/BlackBerry/'. get_locale() .'.mo');
what does $loaded have? because it seems its not loading the mo file

June 26, 2012 at 2:54 pm #64948

Arian

Dear brooks,

var_dump($loaded); says: bool(true)
So it should be loaded, but it is not..

I have tried to print the global that holds the values:
print_r($l10n['blueprint']);

But all the fields have the (default) 'de_DE' values, not the 'en_US' that i have requested.

June 27, 2012 at 2:38 pm #65094

brooks

here http://codex.wordpress.org/Function_Reference/load_textdomain it says that:
If the domain already exists, the inclusion will fail. If the MO file is not readable, the inclusion will fail.

So maybe we need to unload_textdomain('blueprint');

June 29, 2012 at 11:48 am #65446

Arian

Hi Brooks,

I have tested the unload function and it seems to work!
I had examined the i10n.php file and i expcet it would overwrite the language but it doesn't, it only merges withoud overwrite.

Thanks!

Viewing 7 posts - 1 through 7 (of 7 total)

The topic ‘[Closed] switch_lang and load_textdomain does not work in ajax request’ is closed to new replies.