[wp-hackers] Multilanguage: how to redefine locale on the fly
Manuel Schmalstieg
webdev at ms-studio.net
Fri Mar 8 16:03:28 UTC 2013
Update: I'm now inclined to use a workaround based on the post slug.
This makes the language switch as simple as this:
function wpsx89972_redefine_locale($locale) {
$wpsx_url = $_SERVER['REQUEST_URI'];
$wpsx_url_lang = substr($wpsx_url, -4);
if ( $wpsx_url_lang == "-fr/") {
$locale = 'fr_FR';
} else if ( $wpsx_url_lang == "-en/") {
$locale = 'en_US';
} else { // fallback to default
$locale = 'de_DE';
}
return $locale;
}
add_filter('locale','wpsx89972_redefine_locale',10);
Still a bit disappointed as I would prefer a fully taxonomy-based
method... but at least I now have a working multi-language solution in
13 lines of code, not that bad \o/
Thanks again for the great advice!
- Manu
More information about the wp-hackers
mailing list