1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/dokuwiki_ynh.git synced 2024-09-03 18:26:20 +02:00

[enh] Add translation plugin.

This commit is contained in:
opi 2014-07-20 13:53:07 +02:00
parent 903151280c
commit cb514f120a
314 changed files with 1508 additions and 0 deletions

View file

@ -0,0 +1,25 @@
translation Plugin for DokuWiki
All documentation for this plugin can be found at
http://www.dokuwiki.org/plugin:translation
If you install this plugin manually, make sure it is installed in
lib/plugins/translation/ - if the folder is called different it
will not work!
Please refer to http://www.dokuwiki.org/plugins for additional info
on how to install plugins in DokuWiki.
----
Copyright (C) Andreas Gohr <andi@splitbrain.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
See the COPYING file in your DokuWiki folder for details

View file

@ -0,0 +1,280 @@
<?php
/**
* Translation Plugin: Simple multilanguage plugin
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Andreas Gohr <andi@splitbrain.org>
* @author Guy Brand <gb@isis.u-strasbg.fr>
*/
// must be run within Dokuwiki
if(!defined('DOKU_INC')) die();
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN', DOKU_INC . 'lib/plugins/');
require_once(DOKU_PLUGIN . 'action.php');
class action_plugin_translation extends DokuWiki_Action_Plugin {
/**
* for th helper plugin
* @var helper_plugin_translation
*/
var $hlp = null;
var $locale;
/**
* Constructor. Load helper plugin
*/
function action_plugin_translation() {
$this->hlp =& plugin_load('helper', 'translation');
}
/**
* Registe the events
*/
function register(&$controller) {
// should the lang be applied to UI?
$scriptName = basename($_SERVER['PHP_SELF']);
if($this->getConf('translateui')) {
switch($scriptName) {
case 'js.php':
$controller->register_hook('INIT_LANG_LOAD', 'BEFORE', $this, 'translation_js');
$controller->register_hook('JS_CACHE_USE', 'BEFORE', $this, 'translation_jscache');
break;
case 'ajax.php':
$controller->register_hook('INIT_LANG_LOAD', 'BEFORE', $this, 'translate_media_manager');
break;
case 'mediamanager.php':
$controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, 'setJsCacheKey');
break;
default:
$controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, 'setJsCacheKey');
}
}
if($scriptName !== 'js.php' && $scriptName !== 'ajax.php') {
$controller->register_hook('DOKUWIKI_STARTED', 'BEFORE', $this, 'translation_hook');
$controller->register_hook('MEDIAMANAGER_STARTED', 'BEFORE', $this, 'translation_hook');
}
$controller->register_hook('SEARCH_QUERY_PAGELOOKUP', 'AFTER', $this, 'translation_search');
$controller->register_hook('COMMON_PAGETPL_LOAD', 'AFTER', $this, 'page_template_replacement');
}
/**
* Hook Callback. Make current language available as page template placeholder and handle
* original language copying
*
* @param $event
* @param $args
*/
function page_template_replacement(&$event, $args) {
global $ID;
// load orginal content as template?
if($this->getConf('copytrans') && $this->hlp->istranslatable($ID, false)) {
// look for existing translations
$translations = $this->hlp->getAvailableTranslations($ID);
if($translations) {
// find original language (might've been provided via parameter or use first translation)
$orig = (string) $_REQUEST['fromlang'];
if(!$orig) $orig = array_shift(array_keys($translations));
// load file
$origfile = $translations[$orig];
$event->data['tpl'] = io_readFile(wikiFN($origfile));
// prefix with warning
$warn = io_readFile($this->localFN('totranslate'));
if($warn) $warn .= "\n\n";
$event->data['tpl'] = $warn . $event->data['tpl'];
// show user a choice of translations if any
if(count($translations) > 1) {
$links = array();
foreach($translations as $t => $l) {
$links[] = '<a href="' . wl($ID, array('do' => 'edit', 'fromlang' => $t)) . '">' . $this->hlp->getLocalName($t) . '</a>';
}
msg(
sprintf(
$this->getLang('transloaded'),
$this->hlp->getLocalName($orig),
join(', ', $links)
)
);
}
}
}
// apply placeholders
$event->data['tpl'] = str_replace('@LANG@', $this->hlp->realLC(''), $event->data['tpl']);
$event->data['tpl'] = str_replace('@TRANS@', $this->hlp->getLangPart($ID), $event->data['tpl']);
}
/**
* Hook Callback. Load correct translation when loading JavaScript
*
* @param $event
* @param $args
*/
function translation_js(&$event, $args) {
global $conf;
if(!isset($_GET['lang'])) return;
if(!in_array($_GET['lang'], $this->hlp->trans)) return;
$lang = $_GET['lang'];
$event->data = $lang;
$conf['lang'] = $lang;
}
/**
* Hook Callback. Pass language code to JavaScript dispatcher
*
* @param $event
* @param $args
* @return bool
*/
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'] .= '&lang=' . hsc($this->locale);
}
}
return false;
}
/**
* Hook Callback. Make sure the JavaScript is translation dependent
*
* @param $event
* @param $args
*/
function translation_jscache(&$event, $args) {
if(!isset($_GET['lang'])) return;
if(!in_array($_GET['lang'], $this->hlp->trans)) return;
$lang = $_GET['lang'];
// reuse the constructor to reinitialize the cache key
$event->data->cache(
$event->data->key . $lang,
$event->data->ext
);
}
/**
* Hook Callback. Translate the AJAX loaded media manager
*
* @param $event
* @param $args
*/
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;
}
if(!$lc) return;
$conf['lang'] = $lc;
$event->data = $lc;
}
/**
* Hook Callback. Change the UI language in foreign language namespaces
*/
function translation_hook(&$event, $args) {
global $ID;
global $lang;
global $conf;
global $ACT;
// redirect away from start page?
if($this->conf['redirectstart'] && $ID == $conf['start'] && $ACT == 'show') {
$lc = $this->hlp->getBrowserLang();
if(!$lc) $lc = $conf['lang'];
header('Location: ' . wl($lc . ':' . $conf['start'], '', true, '&'));
exit;
}
// check if we are in a foreign language namespace
$lc = $this->hlp->getLangPart($ID);
// store language in session (for page related views only)
if(in_array($ACT, array('show', 'recent', 'diff', 'edit', 'preview', 'source', 'subscribe'))) {
$_SESSION[DOKU_COOKIE]['translationlc'] = $lc;
}
if(!$lc) $lc = $_SESSION[DOKU_COOKIE]['translationlc'];
if(!$lc) return;
$this->locale = $lc;
if(!$this->getConf('translateui')) {
return true;
}
if(file_exists(DOKU_INC . 'inc/lang/' . $lc . '/lang.php')) {
require(DOKU_INC . 'inc/lang/' . $lc . '/lang.php');
}
$conf['lang_before_translation'] = $conf['lang']; //store for later access in syntax plugin
$conf['lang'] = $lc;
return true;
}
/**
* Hook Callback. Resort page match results so that results are ordered by translation, having the
* default language first
*/
function translation_search(&$event, $args) {
if($event->data['has_titles']) {
// sort into translation slots
$res = array();
foreach($event->result as $r => $t) {
$tr = $this->hlp->getLangPart($r);
if(!is_array($res["x$tr"])) $res["x$tr"] = array();
$res["x$tr"][] = array($r, $t);
}
// sort by translations
ksort($res);
// combine
$event->result = array();
foreach($res as $r) {
foreach($r as $l) {
$event->result[$l[0]] = $l[1];
}
}
} else {
# legacy support for old DokuWiki hooks
// sort into translation slots
$res = array();
foreach($event->result as $r) {
$tr = $this->hlp->getLangPart($r);
if(!is_array($res["x$tr"])) $res["x$tr"] = array();
$res["x$tr"][] = $r;
}
// sort by translations
ksort($res);
// combine
$event->result = array();
foreach($res as $r) {
$event->result = array_merge($event->result, $r);
}
}
}
}
//Setup VIM: ex: et ts=4 :

View file

@ -0,0 +1,18 @@
<?php
/**
* Default options for the translation plugin
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
$conf['translations'] = '';
$conf['translationns'] = '';
$conf['skiptrans'] = '';
$conf['dropdown'] = 0;
$conf['translateui'] = 0;
$conf['redirectstart'] = 0;
$conf['checkage'] = 0;
$conf['about'] = '';
$conf['localabout'] = 0;
$conf['display'] = 'langcode,title';
$conf['copytrans'] = 0;

View file

@ -0,0 +1,20 @@
<?php
/**
* Options for the translation plugin
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
$meta['translations'] = array('string','_pattern' => '/^(|[a-zA-Z\- ,]+)$/');
$meta['translationns'] = array('string','_pattern' => '/^(|[\w:\-]+)$/');
$meta['skiptrans'] = array('string');
$meta['dropdown'] = array('onoff');
$meta['display'] = array('multicheckbox',
'_choices' => array('langcode','name','flag','title','twolines'));
$meta['translateui'] = array('onoff');
$meta['redirectstart'] = array('onoff');
$meta['checkage'] = array('onoff');
$meta['about'] = array('string','_pattern' => '/^(|[\w:\-]+)$/');
$meta['localabout'] = array('onoff');
$meta['copytrans'] = array('onoff');

Binary file not shown.

After

Width:  |  Height:  |  Size: 369 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 370 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 374 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 362 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 368 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 260 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 360 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 364 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 366 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 366 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 371 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 366 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 357 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 366 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 366 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 385 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 371 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 361 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 361 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 369 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 370 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 363 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 368 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 244 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 366 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 365 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 361 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 378 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 365 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 376 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 370 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 363 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 368 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 361 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 359 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 358 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 360 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 367 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 374 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 368 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 367 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 373 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 359 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 351 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 377 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 376 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 364 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 361 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 368 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 376 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 238 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 371 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 243 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 364 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 359 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 332 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 368 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 362 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 364 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 369 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 353 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 359 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 364 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 367 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 367 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 363 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 365 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 362 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 369 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 368 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 362 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 370 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 362 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 363 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 359 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 367 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 361 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 364 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 171 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 370 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 371 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 370 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 372 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 377 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 370 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 359 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 364 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 379 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 366 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 358 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 370 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 368 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 362 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 363 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 357 B

Some files were not shown because too many files have changed in this diff Show more