Default Language - use admin setting instead of browser language

Hello, I need to change the default CS-Cart way of setting the default language instead of checking the browser settings to be set as the default language from admin settings. Can anyone help me? I have the 3.0.3 Ultimate version.

Hi there!



In the /core/fn.init.php find this code (in my version lines 446-459):


if (!empty($params['sl']) && !empty($avail_languages[$params['sl']])) {
fn_define('CART_LANGUAGE', $params['sl']);
} elseif (!fn_get_session_data('cart_language' . AREA) && $_lc = fn_get_browser_language($avail_languages)) {
fn_define('CART_LANGUAGE', $_lc);
} elseif (!fn_get_session_data('cart_language' . AREA) && !empty($avail_languages[Registry::get('settings.Appearance.' . AREA_NAME . '_default_language')])) {
fn_define('CART_LANGUAGE', Registry::get('settings.Appearance.' . AREA_NAME . '_default_language'));
} elseif (($_c = fn_get_session_data('cart_language' . AREA)) && !empty($avail_languages[$_c])) {
fn_define('CART_LANGUAGE', $_c);
} else {
reset($avail_languages);
fn_define('CART_LANGUAGE', key($avail_languages));
}


and replace with:


if (!empty($params['sl']) && !empty($avail_languages[$params['sl']])) {
fn_define('CART_LANGUAGE', $params['sl']);
} elseif (!fn_get_session_data('cart_language' . AREA) && !empty($avail_languages[Registry::get('settings.Appearance.' . AREA_NAME . '_default_language')])) {
fn_define('CART_LANGUAGE', Registry::get('settings.Appearance.' . AREA_NAME . '_default_language'));
} elseif (!fn_get_session_data('cart_language' . AREA) && $_lc = fn_get_browser_language($avail_languages)) {
fn_define('CART_LANGUAGE', $_lc);
} elseif (($_c = fn_get_session_data('cart_language' . AREA)) && !empty($avail_languages[$_c])) {
fn_define('CART_LANGUAGE', $_c);
} else {
reset($avail_languages);
fn_define('CART_LANGUAGE', key($avail_languages));
}




I hope it will work for you. (before you test the settings, please clear all browser cache and cookie data).

You SIR are a life saver. Thanks, it works like a charm. I don't know why this is not the default setting in CS-Cart. Thank you again!

[quote name=‘minute’ timestamp=‘1349682543’ post=‘146597’] You SIR are a life saver. Thanks, it works like a charm. I don’t know why this is not the default setting in CS-Cart. Thank you again! [/quote]

Hi! I am very happy to help you. It is my pleasure. (btw reputation points will be appreciated :grin: )

yaaa i like to use my primary language instead of browser language first .



great MOD



thanks

works like a charm in 2.2.5 :) thanks man

[quote name='DarkMan' timestamp='1362597807' post='157137']

yaaa i like to use my primary language instead of browser language first .



great MOD



thanks

[/quote]



I'm interested as to why you think this? Wouldn't your browser language be set to your primary language?



I only ask because I'm soon to roll out additional languages on our website, and I've been considering my approach. For example, Facebook, Twitter and Pinterest look at the browser language and display their sites in that language. Whereas sites like apple.com make you choose your language manually…

I think cs-carts standard behavior works well (after 2.2x I believe). It redirects to customers language if it can see it. If not it shows default language. If customer changes language, he will be redirected to his language of choice again the next time he visits.



I don't see anything that can be improved there.

Thanks Flow, you rock. :lol:

This modification works also in v4

But

/core/fn.init.php is now > /app/functions/fn.init.php



I was wrong, is not working, the code is a little changed, and I am not a programmer. I did someting to fix this strange behavior: I clone English language and defined as eg (not en) an disable en language and not it dows not know how to interpret that language, but I think for SEO is bad… anyone can came with a fix?

Can anyone help with 4.1.1 version?

BUMP!



Need same solution for cs-cart v. 4.2.4. Ultimate.

Please!

Hey, guys!



Sorry for bumping an old post, but I need a similar solution for Multi Vendor 4.3.2.



I do not want CS-Cart to use my browser language, instead I want to set a default language for everybody and give them the option to change it, if the want.



Thanks in advance!



Best Regards,

Cristian

comment these lines:

// elseif (!fn_get_session_data('cart_language' . $area) && $_lc = fn_get_browser_language($avail_languages)) {
        // fn_define('CART_LANGUAGE', $_lc);
    //}

There isn't any option / setting in the admin panel to disable that? Only modifying the source code?

There isn't any option / setting in the admin panel to disable that? Only modifying the source code?

Hello!

I am afraid, there is no setting for this.

There isn't any option / setting in the admin panel to disable that? Only modifying the source code?

It is possible to do it with the My changes module, please check our answer in the other thread.

Take a look at the GeoIP Languages add-on.