How can i get current language in jquery.ajax.cart.js file? Is it possible?
.module file:
drupal_add_js( drupal_get_path('module', 'uc_ajax_cart') .'/js/jquery.ajax.cart.js' );
Maybe parsing the url? I use: base_url() - default language, base_url().'/en' - English language.
Help please...

Comments

Hi "window.location" has

Hi
"window.location" has what's in the address bar of your browser.
If that doesn't work, try window.location.href. you might want to do some parsing in javascript level to get exactly what you need

also you can pass the variable from module file and use it in js file.
e.g.

$js_variables = array(
'first_var' => arg(1),
'second_var' => $url_lang,
);
drupal_add_js(array('modulename' => $js_variables), "setting");

and access it using
var js_first_var = Drupal.settings.modulename.first_var;
var js_second_var = Drupal.settings.modulename.second_var;

thanks,
Shashikant.

I never take right decisions. I take decisions & then make it right

Thanks man I think

Thanks man
I think $js_variables is the best way.
Working now...

http://nexwave.ru
ICQ: 272732793
Skype: gr0mus1
MSN: gromus@live.ru

Another take

I tried this and it worked:

//Get current language and send to js

global $language;
$thelang = $language->language;
$js_variables = array('thelang' => $thelang,);
drupal_add_js(array('mymodulename' => $js_variables), "setting");

I did it this way too - it's goood.

I used the same method but to make the variable available to my theme.

global $language ;

$lang_name = $language->language ;
drupal_add_js(array('swflang' => $lang_name ), 'setting');

Then to pick it up in the javascript on the theme side:

var lang = Drupal.settings.swflang;
alert('lang');

Remove the alert when it works and do your stuff.

Also for non-php people who might want to know what language properties are available, drop

print_r($language);

under the global line.
This will print out all the properties in the global language object so you can see what is happening.
this might be useful if you want the full name instead of the language abbreviation.

I thought I'd mention this as knowing this might help a lot of people out who want something similar but a little different.