Locale woes

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Locale woes

Jamie Talbot
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

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...


Thanks,

Jamie.

- --
http://jamietalbot.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (MingW32)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFD4xe5rovxfShShFARAlQGAJwPvQBJ2zLlFoQyp8ytdwoaK845WwCfaKA3
+rx6ENxGyblg+vPHh5nZev0=
=gzY5
-----END PGP SIGNATURE-----
_______________________________________________
wp-hackers mailing list
[hidden email]
http://lists.automattic.com/mailman/listinfo/wp-hackers
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Locale woes

Jamie Talbot
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Jamie Talbot wrote:

> 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.
>

The solution after all is pretty simple, I think.  streams.php is not being included if WPLANG is
set to '', so as long as it is set to something in wp-config.php, there isn't a problem.

I know you were worried, but you can all relax now :)

Jamie.

- --
http://jamietalbot.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (MingW32)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFD4x0LrovxfShShFARAh13AJ9kpwQDwr//e2gyLXQR6ZqYOnvcOwCgh0FR
qCzDzwSSOdS8AkrxfklobUw=
=B+EZ
-----END PGP SIGNATURE-----
_______________________________________________
wp-hackers mailing list
[hidden email]
http://lists.automattic.com/mailman/listinfo/wp-hackers
Loading...