Skip Navigation

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.

This topic contains 25 replies, has 2 voices.

Last updated by Shane 5 years, 2 months ago.

Assigned support staff: Shane.

Author Posts
February 11, 2016 at 11:54 am #810289

thomasC-4

Hi,

Is there a way to make the default language that a user gets dynamic, i.e. it should be based his/her country or browser settings? Or is this already happening?

Cheers,
Thomas

February 11, 2016 at 7:30 pm #810868

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Thomas,

Thank you for contacting our support forum.

We actually have a feature for this in our plugin called Language Redirect and it is done based on the language of the user's browser.

To find out how to set this up please have a look at the link below.
https://wpml.org/documentation/getting-started-guide/language-setup/automatic-redirect-based-on-browser-language/

Please let me know if this was able to help you as soon as possible 🙂

Thanks,
Shane

February 11, 2016 at 10:07 pm #810998

thomasC-4

Hi Shane,

OK, I got that solution to work. However I think it would be even better to use the users country (I think a lot of people by default have this the browser set to English). I tried a the plugin WPML Country Detector, but it didn't work. Any other suggestions? Should be doable only with a couple of lines of code.

Thanks,
Thomas

February 11, 2016 at 10:17 pm #811003

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Thomas,

This would require some geolocation to do.

Unfortunately this would require some form of custom coding.

Custom coding is out of the scope of our support forum.

To get assistance with this I would recommend that you contact one of our certified partners for assistance with this.

You can see our consultants from the link below.
https://wpml.org/documentation/support/wpml-contractors/

Thanks,
Shane

February 12, 2016 at 10:12 am #811313

thomasC-4

Hi again,

I found another thread:
https://wpml.org/forums/topic/the-function-switch_lang-doesnt-work-icl_language_code-stays-the-same/
where this code seemed to work:

add_action('after_setup_theme', 'my_icl_set_current_language');
function my_icl_set_current_language($lang) {
    global $sitepress;
    $lang = 'en';
    $sitepress->switch_lang($lang, true);
    echo $sitepress->get_current_language();
}

However it did not work for me. Any ideas?

Cheers,
Thomas

February 12, 2016 at 9:28 pm #811976

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Thomas,

The issue I see with the script is that the language will always be set to English because of the variable $lang = 'en';

The code is to essentially set programatically a default language for the website on page load.

This is what I gather that the code is doing. If you were to change the $lang variable value to lets say 'es' or 'fr'

You should notice a redirect occurring.

Please let me know if this helps.
Thanks,
Shane

February 13, 2016 at 12:03 am #812033

thomasC-4

Hi Shane,

My default language is Swedish so I expect code to override the default to display the site in English instead. The "echo $sitepress->get_current_language();" displays 'en' which is fine but when I echo from somewhere else in my theme 'sv' is displayed. Only one thing works - the text on the Add to cart button, which comes from a shortcode.

Cheers,
Thomas

February 15, 2016 at 8:31 pm #813534

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Thomas,

Would you mind providing me with admin access so I can check on this issue for you ?

The private fields will be enabled for your next response.

Thanks,
Shane

February 16, 2016 at 7:41 pm #814648

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Thomas,

To not leave you in the dark, i'm currently looking at this but there is a high volume of tickets in the forums currently so this will take some time 🙁

Please have some patience with me 🙂

Thanks,
Shane

February 16, 2016 at 7:51 pm #814657

thomasC-4

OK, I will comment out the filter (on row 10), but you can reactivate it whenever you need to try something out.

Cheers,
Thomas

February 17, 2016 at 11:54 pm #815896

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Thomas,

Sorry to keep you waiting 🙁

I'm taking a look at this now.

Thanks,
Shane

February 18, 2016 at 12:58 am #815900

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Thomas,

I'm not sure if something like this is even possible.

What I did was to consult with our 2nd tier supporters for advise on this.

Hopefully there will be a solution for this.

If not then it would require custom work that is out of the scope of our forum support.

Thanks,
Shane

February 18, 2016 at 2:10 pm #816777

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Thomas,

I've received word from our 2nd tier supporters.

As mentioned previously to get this implemented would require extensive amount of customisation that is out of the scope of our forum support.

What I would recommend that you do is to get it touch with one of our certified partners to get this level of customisation done for you.
https://wpml.org/documentation/support/wpml-contractors/

Also we went ahead and created a feature request for this, however it does not mean that this will get implemented but our developers will get a chance to look at it.

If there are any other questions please let me know.

Thanks,
Shane

February 18, 2016 at 3:01 pm #816930

thomasC-4

Hi Shane,

To me it sounds more like a bug. If you have a function called $sitepress->switch_lang I assume the point is that the whole language should switch (not switch back in a different function). It works better on my dev site travelwaxer.de/dev that I have now set to nb (norwegian) with switch_lang, at least parts of the first page is in Norwegian (the English text is there because of unfinished development). The dev site has WPML Multilingual CMS version 3.7.2, but the production one is 3.3.6. Maybe the bug was introduced between those versions.

Cheers,
Thomas

February 19, 2016 at 7:00 pm #818756

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Thomas,

I'm a bit confused as currently the latest version of WPML that we have available is version 3.3.6.

I'm not aware of a 3.7.2

Could you provide me with the debug information on your website so I can see the version of the plugins that you have?

https://wpml.org/faq/provide-debug-information-faster-support/

I'll be enabling the debug fields for your next response.

Thanks,
Shane

The topic ‘[Closed] Dynamic default language’ is closed to new replies.