[wp-hackers] Locale woes

Jamie Talbot wphackers at jamietalbot.com
Fri Feb 3 08:43:37 GMT 2006

Hash: SHA1


I'm having difficulty trying to dynamically set the $locale from within a localised plugin.  I have
a filter, 'locale' which should replace the current locale with a plugin specified one and is
registered in the constructor.

function locale($locale)
	return $this->my_locale;

I've also localised the plugin and call load_plugin_textdomain() in the constructor.

The problem:

Calling load_plugin_textdomain() before add_filter('locale', array(&$this, 'locale')) causes
get_locale() to be executed before my filter is registered, which means that the locale remains as
it is.  This would not necessarily be a problem as get_locale() is executed again for
load_default_textdomain() except that in get_locale(), if the $locale is already set, it is simply
returned, rather than being refiltered (wp-l10n.php line 12).

If I call add_filter before load_plugin_textdomain() I get this error:

Fatal error: Cannot instantiate non-existent class: cachedfilereader in
/path/to/wp/wp-includes/wp-l10n.php on line 67

That's this line:

$input = new CachedFileReader($mofile);

where $mofile is the locale that my filter returns.

This error only occurs if $this->my_locale matches an existant .mo file, which is not defined as
WPLANG.  Setting it to 'de_DE', for example, if that language pack is not installed, causes no
error.  Of course, because no 'de_DE' language pack is installed, it's pretty pointless.  If I have
the language pack 'ja_JP' and my filter returns 'ja_JP', if WPLANG is defined as 'ja_JP' then all is
well.  If WPLANG is defined as something else, I get that error.

Can anybody shed some light on what is happening here?  I've looked around and seen this problem
discussed before, but the best solution was just to delete all the .mo files, which isn't
particularly useful in my case...



- --
Version: GnuPG v1.2.5 (MingW32)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org


More information about the wp-hackers mailing list