translation plugin by Andreas Gohr
Help with translation efforts in a multilingual wiki
Last updated on 2008-04-01. Provides Syntax, Action.
Compatible with DokuWiki 2007-06-26+.
Similar to nsrelation.
This plugin shows a list of available translations for a page. It is very simple and was built with the needs of wiki.splitbrain.org in mind and is used for documentation translation efforts here. There are a few limitations:
Use this URL to download the file manually or through the plugin manager:
Recent Changes:
main.php (or put it in a dokuwiki\lib\tpl\default\pageheader.html file for the default template)<?php $translation = &plugin_load('syntax','translation'); echo $translation->_showTranslations(); ?>
Note: add this piece of code not at the top or the bottom of main.php but instead in-between where it makes the best optical impression. You need to experiment a bit to find the best spot.
If you have several themes or skins installed you need to add this piece of code into each main.php to allow the translation-plugin for every skin.
There are several config options, all accessible through the config manager.
You can define a namespace in which translation should be done (used here to enable the plugin in the wiki namespace only). This is optional, leaving it empty will enable the plugin for the whole wiki.
You need to setup the languages you want your pages be translated to. Separate each language with a comma or space. The default language will be added automatically, so do not add it here.
You can optionally choose to let the plugin translate the whole user interface of DokuWiki too when a non-default language page is selected. Just enable the option accordingly.
You might want to explain how the translations work on your wiki to your users. To make this description easily accessible from the language selector, enter the pagename of your description in the configuration.
If you don't use the Config Manager and prefer configuring your wiki editing the config file, the useful lines which have to be added to your local.php configuration file are:
$conf['plugin']['translation']['translations'] = 'en,fr,de,it'; // available languages $conf['plugin']['translation']['translationns'] = 'wiki'; // namespace where to activate translation $conf['plugin']['translation']['translateui'] = 1; // translate the wiki user interface too $conf['plugin']['translation']['about'] = 'wiki:translation:about'; // page describing the translation process to users
Skip your default language! So if your dokuwiki starts with english, set
$conf['plugin']['translation']['translations'] = 'fr,de,it'; // available languages
Otherwise the language menu will show 'en' twice.
The plugin does its work automatically by being called from the template (see installation), but you can disable it for a certain page by adding the following code to the top of the page:
~~NOTRANS~~
I´ve installed the plugin, it works, but only for the content (and the user interface - if selected) - not for the sidebar which is defined in sidebar.txt-file in the translation-namespace (en).
I´m using the arctic-Template with left sidebar configueres. If I set in the configuration the content of the sidebar to “main” and “namespace” this shows on translated pages both, the sidebar in the original language (German) (this comes from the “main”-sidebar) and the translated (english) which is the sidebar in the “en”-namespace. In the original language it´s only the German-sidebar (“main”-sidebar). I guess, I have to switch off the “main”-sidebar if a translated page is used.
How could I manage this?
Thanks - Bernhard Henselmann / 27.1.2008
This is a fix that i did on a site, its not for arctic but for the Better Navigation
Lets say you have english and german languages on your dokuwiki, and english is default, in this case all the pages in german would be in the namespace de.
The default sidebar for english would be sidebar. And the default for german would be within de namespace like so de:sidebar
hope you get some ideas from this, good luck
Could you add some national flags instead of the iso codes? At least for the most used languages. — scy
Please don't or at least combine the two. Flags for languages is a very European view of the world. We use a wiki in South Africa which has 11 official language. Which flag should we use? — dwayneOh, ok. I recommend both versions anyway. — scy
I've created a flag based translation modification. Andy, if you want, please add this to the next release. See Flags Demonstration
A dropdown menu would be much more easy to integrate in a template than a huge horizontal list of codes ! Most sites provide language selection through a dropdown menu. It would be great if we could have this option. — manu
In case of a drop-down menu you'll be unable to see to which languages the page has been already translated. —wojtek
Some namespaces are probably not suitable for translation (e.g., users' wiki pages, the playground, or wiki pages for the localised translation, etc.). Could we have something similar to the exact opposite of “If you only want translations below a certain namespace, put it here.”?
I have made a german translation for this plugin. Where can I place it? — Uwe Koloska
Save following lines as ./de/lang.php.
<?php $lang['translations'] = 'Übersetzungen dieser Seite';
Save following lines as ./de/settings.php.
<?php /** * German language file */ $lang['translations'] = "Liste der Sprachen (ISO codes), mittels Leerzeichen separiert. Die Default-Sprache nicht angeben."; $lang['translationns'] = "Wenn die Übersetzung nur unterhalb eines Namensraumes gelten soll, hier angeben."; $lang['translateui'] = "Soll die Sprache der Benutzerschnittstelle auch in die jeweilige Fremdspache umgeschaltet werden?"; $lang['about'] = "Geben Sie hier eine Seite an, welche den Mechanismus der Übersetzung erklärt. Sie wird vom Sprachumschalter verlinkt.";
I put mine here. StinkyWinky 2008/07/08 13:46
I seem to have found a way to get the content of a page to fallback to the default language if no translation is available. the rest of the page refers to the (non-existing) translated page, so the bottom of the page still says “create this page”, and any sidebar / tabs / menuus will still refer to the 'current' language. But the content shows the untranslated version, without edit options.
In lib/plugins/translation/syntax.php, add
/**
* returns fallback html if the current page does not exists
**/
function _fallbackContent() {
global $ACT,$ID;
if ($ACT=="show" && $this->_currentLang()) {
resolve_pageid(getNS($ID),noNS($ID),$exists);
if (!$exists) {
//see if the default lang exists
$rx = '/^'.$this->tns.'(('.join('|',$this->trans).'):)?/';
$defid = preg_replace($rx,'',$ID);
resolve_pageid(getNS($defid),noNS($defid),$exists);
if ($exists) {
return p_wiki_xhtml($defid);
}
}
}
return "";
}
.. in your main template, where you would write
tpl_content();
now write
$transplug = &plugin_load('syntax','translation');
$fallback = $transplug->_fallbackContent();
if ($fallback) print $fallback;
else tpl_content();
I'm pretty sure that code can be improved. nevertheless, it seems to work sofar.
$2c, *-pike
This patch will just disable the untranslated page links from the translation menu. It's useful for those who don't want search engine on the untranslated pages.
--- lib/plugins/translation/syntax.php.orig 2008-02-26 15:02:31.000000000 +0100 +++ lib/plugins/translation/syntax.php 2008-02-26 15:02:12.000000000 +0100 @@ -135,7 +135,8 @@ $out .= '<ul>'; $out .= ' <li><div class="li">'.$this->_buildTransLink('',$idpart).'</div></li>'; foreach($this->trans as $t){ - $out .= ' <li><div class="li">'.$this->_buildTransLink($t,$idpart).'</div></li>'; + resolve_pageid(getNS($t.':'.$idpart),$page = noNS($idpart),$exists); + if ($exists) $out .= ' <li><div class="li">'.$this->_buildTransLink($t,$idpart).'</div></li>'; } $out .= '</ul>'; $out .= '</div>';
Hope this will help somebody! – Stéphane Gully
I found that this line in lib/plugins/translation/style.css:
list-style-type: none; needs to be changed to list-style: none; - otherwise Firefox will still display the bullets which will disturb the language link left of it. // Bernd
rtl.css does not seem to work with translation plugin. Also it would be better to load rtl.css as a separate file than as part of css.php. Andy, can this be done by the ?s=rtl get string? Or maybe loading rtl as a separate css is prefered behavior. Can someone help with this?
i was unable to install the plugin via the plugin-manager so i just extracted the folder per hand into the plugins directory. Worked very fine. To make the plugin work with the dokucms-theme i had to edit the file: /lib/tpl/dokucms/main.php and add those lines:
<?php $translation = &plugin_load('syntax','translation'); echo $translation->_showTranslations(); ?>
before this line:
<div class="clearer"></div>
-Thank you for this great plugin, i really love it. -Horst, 2008-07-17