[wp-hackers] Multilanguage: how to redefine locale on the fly
    Manuel Schmalstieg 
    webdev at ms-studio.net
       
    Thu Mar  7 22:23:20 UTC 2013
    
    
  
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?
    
    
More information about the wp-hackers
mailing list