Permalink
Browse files

Merge branch 'master' of https://github.com/cosmocode/dokuwiki-plugin…

…-translation into pull-request-19

* 'master' of https://github.com/cosmocode/dokuwiki-plugin-translation:
  added missing global
  use new INIT_LANG_LOAD event and correct js language
  • Loading branch information...
2 parents 9c7d2c3 + 1797705 commit 9a1beee0029569b7f669c830b96d568f00f692d9 @splitbrain committed Feb 8, 2012
Showing with 61 additions and 3 deletions.
  1. +61 −3 action.php
View
@@ -20,6 +20,8 @@ class action_plugin_translation extends DokuWiki_Action_Plugin {
*/
var $hlp = null;
+ var $locale;
+
/**
* Constructor. Load helper plugin
*/
@@ -33,11 +35,67 @@ function action_plugin_translation(){
function register(&$controller) {
// should the lang be applied to UI?
if($this->getConf('translateui')){
- $controller->register_hook('DOKUWIKI_STARTED', 'BEFORE', $this, 'translation_hook');
+ $scriptName = basename($_SERVER['PHP_SELF']);
+
+ switch ($scriptName) {
+ case 'js.php':
+ $controller->register_hook('INIT_LANG_LOAD', 'BEFORE', $this, 'translation_js');
+ break;
+
+ case 'ajax.php':
+ $controller->register_hook('INIT_LANG_LOAD', 'BEFORE', $this, 'translate_media_manager');
+ break;
+
+ case 'mediamanager.php':
+ $controller->register_hook('MEDIAMANAGER_STARTED', 'BEFORE', $this, 'translation_hook');
+ $controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, 'setJsCacheKey');
+ break;
+
+ default:
+ $controller->register_hook('DOKUWIKI_STARTED', 'BEFORE', $this, 'translation_hook');
+ $controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, 'setJsCacheKey');
+ }
}
$controller->register_hook('SEARCH_QUERY_PAGELOOKUP', 'AFTER', $this, 'translation_search');
}
+ function setJsCacheKey(&$event, $args) {
+ if (!isset($this->locale)) return false;
+ $count = count($event->data['script']);
+ for ($i = 0; $i<$count; $i++) {
+ if (strpos($event->data['script'][$i]['src'], '/lib/exe/js.php') !== false) {
+ $event->data['script'][$i]['src'] .= "&cacheKey=$this->locale";
+ }
+ }
+
+ return false;
+ }
+
+ function translation_js(&$event, $args) {
+ global $conf;
+ if (!isset($_GET['cacheKey'])) return false;
+
+ $key = $_GET['cacheKey'];
+ $event->data = $key;
+ $conf['lang'] = $key;
+ return false;
+ }
+
+ function translate_media_manager(&$event, $args) {
+ global $conf;
+ if (isset($_REQUEST['ID'])) {
+ $id = getID();
+ $lc = $this->hlp->getLangPart($id);
+ } elseif (isset($_SESSION[DOKU_COOKIE]['translationlc'])) {
+ $lc = $_SESSION[DOKU_COOKIE]['translationlc'];
+ } else {
+ return false;
+ }
+ $conf['lang'] = $lc;
+ $event->data = $lc;
+ return false;
+ }
+
/**
* Change the UI language in foreign language namespaces
*/
@@ -46,7 +104,6 @@ function translation_hook(&$event, $args) {
global $lang;
global $conf;
global $ACT;
-
// redirect away from start page?
if($this->conf['redirectstart'] && $ID == $conf['start'] && $ACT == 'show'){
$lc = $this->hlp->getBrowserLang();
@@ -70,6 +127,7 @@ function translation_hook(&$event, $args) {
}
$conf['lang_before_translation'] = $conf['lang']; //store for later access in syntax plugin
$conf['lang'] = $lc;
+ $this->locale = $lc;
return true;
}
@@ -119,4 +177,4 @@ function translation_search(&$event, $args) {
}
-//Setup VIM: ex: et ts=4 enc=utf-8 :
+//Setup VIM: ex: et ts=4 :

0 comments on commit 9a1beee

Please sign in to comment.