[wp-hackers] Multilanguage: how to redefine locale on the fly
Rafael Ehlers
rafaehlers at gmail.com
Thu Mar 7 22:27:37 UTC 2013
Set global $post; first?
2013/3/7 Manuel Schmalstieg <webdev at ms-studio.net>
> Almost working, but I am still hitting an obstacle with the sequence of
> actions:
>
> - Registering the "language" taxonomy very early on, calling
> register_taxonomy() on the "plugins_loaded" or "setup_theme" action:
> works.
> - Running a filter that redefines the locale: works.
> - Applying the language switch only if taxonomy_exists(): works.
>
> What doesn't work: conditionally testing if the current post has a
> specific language, using has_term().
> Actually, even a conditional test for is_single() doesn't return
> anything at that step.
>
> So I'm worried that the locale filter is triggered too early in the
> initialization process, before any post content is there.
>
> Here is this very simple piece of code, that almost works:
>
> function mimu_redefine_locale($locale) {
> if ( taxonomy_exists( 'mimu_language' )) {
> if ( has_term( 'fr', 'mimu_language' )) {
> $locale = 'fr_FR';
> }
> }
> return $locale;
> }
> add_filter('locale','mimu_redefine_locale',10);
>
> Any ideas how that function could access the taxonomy parameters of
> the current post?
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
More information about the wp-hackers
mailing list