Sorry for the lengthy explanation but I am having a heck of a time trying to get a client’s WordPress website to switch from English to Korean and vice versa (from the front end public side) ever since I upgraded from WordPress 3.8 to WordPress 4.1.
I understand WordPress 4.0 now uses the “language selector” in the Dashboard settings to determine what language the site is displayed in globally, however the client needs the site to switch languages based on the visitors preference, not what is set in the Dashboard. The client only wants admin-level users to access the dashboard, which means all other (regular) users will be kept out of their own Dashboard.
I’ve implemented a simple public language toggle that was working great with WordPress 3.8 and a plugin called qTranslate that looks like this (they’re simply links that one can click to change the language):
English | íêµì´
Since upgrading to WP 4.0, I’ve had to stop using qTranslate (incompatible with WP 4.0) and started using qTranslate Plus (https://wordpress.org/plugins/qtranslate-xp/).
But now WP 4.0 ignores what qTranslate Plus is trying to do, particularly with big plugins like BBPress.
I use a handy function many times across the website that allows me to determine what language the user has currently selected. The URL is also changed accordingly. For example:
English version – example.com/
Korean version – example.com/KO/ (A simple “KO/” is added after the domain name if the user clicks on the Korean link described above)
The function I use to determine what language the user has currently enabled looks like this:
$current_lang = ppqtrans_getLanguage(); // function is from qTranslate Plus
if ($current_lang == "KO") {
// do what I need to do here in Korean
} else if ($current_lang == "en") {
// do what I need to do here in English
}
The above works great on custom pages, but I’m also using BBPress and Event Espresso (an event registration software and payment gateway) which are no longer switching to Korean after upgrading to WordPress 4.1, which has my client raging right now.
I tried using a function like this in the theme’s functions.php file but it doesn’t seem to be working:
add_filter('locale', 'change_lang');
function change_lang( $locale ) {
$current_lang = ppqtrans_getLanguage();
if ($current_lang == "KO") {
$locale = "ko_KR";
} else if ($current_lang == "en") {
$locale = "en_US";
}
return $locale;
}
Sorry if the above looks totally wrong. I’m still trying to get the hang of hooks and filters.
Anyhow, if anyone has any insight on how to get plugins like BBPress and Event Espresso to heed a dynamically changed locale, that would be amazing! Even the Event Espresso staff has been less than knowledgable on how to get this working. I just don’t understand why something that would seem so simple is so hard to accomplish!
Thanks so much for your time!
TL;DR: I’m trying to dynamically change WordPress 4.0 language locale, depending on what the URL looks like. example.com/ should set the site to English. example.com/KO/ should set the site to Korean â without using the setting in the language selector in the Dashboard.