[wp-hackers] Improvements to the WordPress l10n framework

Nikolay Bachiyski nbachiyski at developer.bg
Sun May 13 09:19:24 GMT 2007


2007/5/12, Omry Yadan <omry at yadan.net>:
> Nikolay Bachiyski wrote:
> >
> > We cannot do this. What happens if the plugin function calls a core
> > function and then it calls other plugin function? It is possible that
> > either core strings are being searched for in the plugin domain or,
> > worse, one plugin\s string is being looked for in other plugin's
> > domain.
>
> Good point.
> it can be solved (I think) by using a stack.
> instead of setting and unsetting the current plugin_id, push it and pop
> it from a global stack.
>

Using a stack we can only reassure we are not in the wrong plugin.
However we cannot intercept the switch between a plugin and the core.
Here is an example:
wp-content/plugins/our.php:
    function f() {
        ....
        $x = comments_number();
        ....
    }

In the comments_number function there are some i18n-ed strings and we
expect their translations to be taken from the default domain. However
the current context will point us to our plugin and the translation
will be searched for in its domain, not in the default.

In most of the cases we can solve this problem by searching not only
in the plugin namespace, but on failure -- also in the default one. Of
course, this will work only if we are sure that one string has the
same translation everywhere.

Happy hacking,
Nikolay.

[0] http://trac.wordpress.org/browser/branches/2.2/wp-includes/comment-template.php#L164


More information about the wp-hackers mailing list