1<?php 2 3/** 4 * DokuWiki Plugin Localization (Action Component) 5 * @link https://github.com/kondurake/dokuwiki-plugin-localization 6 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 7 * @author kondurake <kvp@live.com> 8 */ 9// must be run within Dokuwiki 10defined('DOKU_INC') || die(); 11 12class action_plugin_localization extends DokuWiki_Action_Plugin 13{ 14 15 /** 16 * @param Doku_Event_Handler $controller 17 * @return void 18 */ 19 public function register(Doku_Event_Handler $controller) 20 { 21 $controller->register_hook('DOKUWIKI_STARTED', 'AFTER', $this, 'handle_init_lang_load', null, 3999); 22 } 23 24 /** 25 * @param Doku_Event $event 26 * @return null 27 */ 28 public function handle_init_lang_load() 29 { 30 global $conf; 31 32 if (empty($conf['lang']) || empty($conf['lang_before_translation'])) { 33 return; // Languages are not defined 34 } 35 36 if ($conf['lang'] == $conf['lang_before_translation']) { 37 return; // Current language is the same as the default language 38 } 39 40 // Overwrite settings 41 $local = $this->load($conf['lang']); 42 if ($local) { 43 $conf = array_replace_recursive($conf, $local); 44 } 45 } 46 47 /** 48 * @param string $lang 49 * @return array|null 50 */ 51 private function load($lang) 52 { 53 $file = __DIR__ . "/locales/{$lang}/conf.php"; 54 if (is_file($file)) { 55 $conf = null; 56 include $file; 57 58 if ($conf && is_array($conf)) { 59 return $conf; 60 } 61 } 62 } 63 64} 65