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