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.

This topic contains 3 replies, has 2 voices.

Last updated by Michael 2 years, 3 months ago.

Assigned support staff: Joanna.

Author Posts
September 4, 2017 at 5:59 am #1356873

Michael

I have what's probably a different scenario where I need to be able to set the default language and avaialble languages in my WordPress system based on a GeoIP lookup. Users also have to be able to choose a different anguage if multiple are allowed for that region. As an example, anyone in Australia will only see 'en_AU', but someone in Canada will need to choose from 'en_CA' and 'fr_CA'.

So far I have been able to get the available languages using the 'wpml_active_languages' filter so I can set up a language selector myself, but the 'wpml_default_language' filter doesn't get called (at least by the time that my theme loads) so I can't use that to set a default language myself. I haven't been able to find another filter or function that I can use to set this myself.

Is there any internal functions/actions/filters/etc that I can use to set a default languge myslf?

September 4, 2017 at 8:50 am #1357079

Joanna

Hello @michaelb-115,

If I understood you correctly, you have only one site where you want to change the default language depending on the user's location. Am I correct? If so, it's a really bad idea because the default language will change globally for all users and you'll get tons of URL and other issues.

However, what I can think of in this case would be to set the language directory for all languages and create a root page that will show available languages based on the location. The root page will be displayed on the main domain (without the language directory) and will be the same for all users.
When you have the language directory enabled for the default language, the user won't even know which language is the default one and it won't matter anymore.
As you already mentioned, you can use the "wpml_active_languages" hook to create your own language switcher based on the user's location.

You may read more about the "Use directory for default language" option and creating the root page at https://wpml.org/documentation/getting-started-guide/language-setup/directory-default-language/.

September 4, 2017 at 10:29 pm #1358743

Michael

I do appreciate that idea, but I am tied in how it's got to be done. My management has already told the client that it will be done this way, so I'm stuck with making it work. I have asked to change that part of the project, and been refused.

I guess I'll keep looking through the code and see if there's anything else that I can find that might help out.

September 5, 2017 at 4:24 am #1358893

Michael

I have found a way to do this... but it's not anywhere near optimal.

I've been able to get this to work I've had to set up a must-use plugin that adds a filter for 'option_icl_sitepress_settings' in for the settings so that the settings values can be run through that filter before being passed back.

It's not elegant, it's not even good, but for what I need, it does seem to work at the moment.