[wp-hackers] Multilanguage: how to redefine locale on the fly

Manuel Schmalstieg webdev at ms-studio.net
Fri Mar 8 18:54:36 UTC 2013

Just tried that, but I don't get it to work.

When executing the filter on "template_redirect", I notice that the
"has_term()" does return a result, and the language switch is showing
up in the header's language_attributes() – but some of the _e()
strings and all of the dates are left unlocalized on the frontend, so
it's not a workable solution.

> Since you're just switching from English to one other language, you can
> consider filtering 'locale' once the post is loaded (on template_redirect).
> The key is to re-load the default textdomain after filtering 'locale'.
> add_filter( 'template_redirect', function() {
>     add_filter( 'locale', ... );
>     load_default_textdomain();
> });
> This won't quite result in every string translated, as some will be
> translated before template_redirect, but you are unlikely to notice on the
> frontend.
> Nacin

More information about the wp-hackers mailing list