[dokuwiki] Re: Internationalization in plugin descriptions (via plugin.info.txt)

  • From: Luis Machuca Bezzaza <ryan.chappelle@xxxxxxxx>
  • To: dokuwiki@xxxxxxxxxxxxx
  • Date: Tue, 07 Dec 2010 18:05:45 -0300

Andreas Gohr escribió:
>> I would like to ask what the method is to provide a plugin.info.txt file yet
>> at the same time override specific fields in the loaded array;
> 
> It's quite simple. Implement a getInfo() method as you used to do, but
> load the plugin.info.txt in that function using confToHash(). Then
> override the fields you'd like to translate. Your plugin.info.txt
> should be in english then of course.
> 
> 
> 

----

As it wasn't that hard, I decided to try and hack into the code of the core
plugin handler. Modifying the getInfo() function to achieve what I wanted
wasn't too difficult. By providing the functionality at the core plugin
handler(s), the immediate advantage is that overriding getInfo() in /any/
plugin will become unnecessary (at least for this purpose). The Plugin
Manager will instantly pick the description string from $lang['desc'] if
available or fallback to English as usual.

This is the patch for syntax.php handler only -- similar patches would be
required for the other base handlers -- for the former DW stable "Lemming",
but I suspect that this patch works as well for the "Anteater" release.

Mind a discussion of the i18n'n strategy?


--- syntax.php.old      2010-12-07 17:34:12.000000000 -0300
+++ syntax.php  2010-12-07 17:38:24.000000000 -0300
@@ -38,7 +38,13 @@
     function getInfo(){
         $parts = explode('_',get_class($this));
         $info  = DOKU_PLUGIN.'/'.$parts[2].'/plugin.info.txt';
-        if(@file_exists($info)) return confToHash($info);
+        if(@file_exists($info)) {
+            $arr= confToHash($info);
+            if ( $arr['desc'] == '$desc' && ''!==$this->getLang('desc') ) {
+                $arr['desc'] = $this->getLang('desc');
+            }
+            return $arr;
+        }
         trigger_error('getInfo() not implemented in '.get_class($this).'
and '.$info.' not found', E_USER_WARNING);
     }

----

After-effects: after applying this patch, if plugin.info.txt contains the
following value for the description field:

----
desc   $desc
----

Then DokuWiki will look for a localized description string $lang['desc'] in
the plugin language file (pluginname/lang/??/lang.php). Should such
file/string not be found, the plugin will fallback to the description string
for the English language (ie.: $lang['desc'] in pluginname/lang/en/lang.php).

Obviously, specifying '$desc' as the field value only makes sense if the
plugin makes lang/?? files available to localize content.

The field key 'desc' was chosen merely for symmetry with plugin.info.txt.


-- 
----
Luis Machuca Bezzaza
Secretario (S) GULIX - Grupo de Usuarios de GNU/Linux de la IX Región
http://www.gulix.cl/
----

-- 
DokuWiki mailing list - more info at
http://www.dokuwiki.org/mailinglist

Other related posts: