xref: /plugin/autotranslation/action.php (revision 0a7415d3673cb5dd41bdf22b0d3a58fb23c6490e)
1*0a7415d3SAndreas Gohr<?php
2*0a7415d3SAndreas Gohr/**
3*0a7415d3SAndreas Gohr * Info Plugin: Simple multilanguage plugin
4*0a7415d3SAndreas Gohr *
5*0a7415d3SAndreas Gohr * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
6*0a7415d3SAndreas Gohr * @author     Andreas Gohr <andi@splitbrain.org>
7*0a7415d3SAndreas Gohr * @author     Guy Brand <gb@isis.u-strasbg.fr>
8*0a7415d3SAndreas Gohr */
9*0a7415d3SAndreas Gohr
10*0a7415d3SAndreas Gohr// must be run within Dokuwiki
11*0a7415d3SAndreas Gohrif(!defined('DOKU_INC')) die();
12*0a7415d3SAndreas Gohr
13*0a7415d3SAndreas Gohrif(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
14*0a7415d3SAndreas Gohrrequire_once(DOKU_PLUGIN.'action.php');
15*0a7415d3SAndreas Gohr
16*0a7415d3SAndreas Gohrclass action_plugin_translation extends DokuWiki_Action_Plugin {
17*0a7415d3SAndreas Gohr
18*0a7415d3SAndreas Gohr    /**
19*0a7415d3SAndreas Gohr     * return some info
20*0a7415d3SAndreas Gohr     */
21*0a7415d3SAndreas Gohr    function getInfo(){
22*0a7415d3SAndreas Gohr        return confToHash(dirname(__FILE__).'/info.txt');
23*0a7415d3SAndreas Gohr    }
24*0a7415d3SAndreas Gohr
25*0a7415d3SAndreas Gohr    /**
26*0a7415d3SAndreas Gohr     * Registe the events
27*0a7415d3SAndreas Gohr     */
28*0a7415d3SAndreas Gohr    function register(&$controller) {
29*0a7415d3SAndreas Gohr        // should the lang be applied to UI?
30*0a7415d3SAndreas Gohr        if($this->getConf('translateui')){
31*0a7415d3SAndreas Gohr            $controller->register_hook('DOKUWIKI_STARTED', 'BEFORE', $this, 'translation_hook');
32*0a7415d3SAndreas Gohr        }
33*0a7415d3SAndreas Gohr    }
34*0a7415d3SAndreas Gohr
35*0a7415d3SAndreas Gohr    /**
36*0a7415d3SAndreas Gohr     * Change the UI language in foreign language namespaces
37*0a7415d3SAndreas Gohr     */
38*0a7415d3SAndreas Gohr    function translation_hook(&$event, $args) {
39*0a7415d3SAndreas Gohr        global $ID;
40*0a7415d3SAndreas Gohr        global $lang;
41*0a7415d3SAndreas Gohr        global $conf;
42*0a7415d3SAndreas Gohr
43*0a7415d3SAndreas Gohr        // get an instance of the syntax plugin
44*0a7415d3SAndreas Gohr        $translation = &plugin_load('syntax','translation');
45*0a7415d3SAndreas Gohr
46*0a7415d3SAndreas Gohr        // check if we are in a foreign language namespace
47*0a7415d3SAndreas Gohr        $lc = $translation->_currentLang();
48*0a7415d3SAndreas Gohr        if(!$lc) return;
49*0a7415d3SAndreas Gohr
50*0a7415d3SAndreas Gohr        if(file_exists(DOKU_INC.'inc/lang/'.$lc.'/lang.php')) {
51*0a7415d3SAndreas Gohr          require(DOKU_INC.'inc/lang/'.$lc.'/lang.php');
52*0a7415d3SAndreas Gohr        }
53*0a7415d3SAndreas Gohr        $conf['lang_before_translation'] = $conf['lang']; //store for later access in syntax plugin
54*0a7415d3SAndreas Gohr        $conf['lang'] = $lc;
55*0a7415d3SAndreas Gohr
56*0a7415d3SAndreas Gohr        return true;
57*0a7415d3SAndreas Gohr    }
58*0a7415d3SAndreas Gohr}
59*0a7415d3SAndreas Gohr
60*0a7415d3SAndreas Gohr//Setup VIM: ex: et ts=4 enc=utf-8 :
61