[wp-hackers] Couple of quick questions: restrict access to plugin file and loading of l10n

Jennifer Hodgdon yahgrp at poplarware.com
Fri Oct 19 18:24:59 GMT 2007


Andrew Ozz wrote:
> 2. I'm providing .pot file for easy translation and (of course) using 
> load_plugin_textdomain to load the translations.
> 
> How "late" can I call it? I see some plugins use the "init" or 
> "plugins_loaded" hooks but that would load the translation on every run 
> - another 25-30KB - whether it's needed or not.

As the maintainer of a multilingual plugin, which changes the locale 
based on URLs/cookies, I have a couple of thoughts on this:

a) Never call load_plugin_textdomain in the main text of your plugin 
file (i.e. outside of a WP filter/action). It might get loaded before 
a multilingual plugin has properly decided which language to use (the 
load command loads a particular language).

b) During the init or loaded hook is fine, from the multilingual 
plugin point of view, because the language should be decided on by then.

c) In one of my plugins (not the multilingual one), I used a scheme 
like this:
    - define a function called myplugin_setup, which calls 
load_plugin_textdomain and then sets a global "setup_done" flag 
variable to true. At the top of that function, check the flag, and if 
it is true, just return.
    - make sure that each function that actually needs localization 
calls setup at the top.

It's not beautiful, but it does save loading text domains if they 
aren't needed, especially if they are only needed by one or two screen 
functions.

d) It is wonderful that you decided to internationalize your plugin 
properly!!!! Many plugin authors do not even consider that WP is used 
all over the world. I have put instructions on my multilingual plugin 
site on how to internationalize plugins, because of this... and 
believe me, it is not much fun for an average non-plugin-developer WP 
user who just wants to set up a blog.

    --Jennifer

-- 
Jennifer Hodgdon

Poplar ProductivityWare * www.poplarware.com
Web Databases/Scripts * Modeling/Analysis/Palm OS Software



More information about the wp-hackers mailing list