translation plugin by Andreas Gohr
Help with translation efforts in a multilingual wiki
Last updated on 2008-08-12. Provides Syntax, Action.
Compatible with DokuWiki 2007-06-26+.
Conflicts with multilingual!
Similar to multilingual, nsrelation, translation2.
This plugin shows a list of available translations for a page. It is very simple and was built with the needs of www.dokuwiki.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:
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.
Similar to the above setting you can also set a regular expression to be matched against pagenames. When it matches, the translation switcher will not be displayed. This can be used to automatically keep out certain namespaces from the translation. The regexp is applied to the full pagename which starts with colon.
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']['skiptrans'] = '^:(plugin|template):'; // what to skip (regexp) $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~~
Hello, I'm using this plugins in my site and it works fine, except for one thing: when you've selected a language and you use the search bar to make a search, the results are shown in the default language, not in the selected one.
You can try this here: http://www.dokuwiki.org/dokuwiki. Just select any language (different from English) and make a search.
Can this be fixed? Thank you. Digna. 2008/12/04
Yes I need that translation, too. Can anyone help? Amy, 2009/04/02
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 configured. 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 now fixed. The arctic template plays well with the translation plugin, there is amain_sidebar_alwayssetting you can turn off to do so. — Guy Brand 2008/08/01 20:56
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
You can define a specific sidebar for each page so there won't be any conflicts between the sidebar's namespace system and the translation namespaces . Here's how i do it :
<?php tpl_sidebar_content("sidebar_".tpl_pagetitle(null,true)); ?>
If you have a page called 'foo' you just have to edit the 'sidebar_foo' page.
Hope this helps !
Daamien / 2008.08.29
I have installed the plugin with the artic template Agitation Free Test Page. But the sidebar switches only one time - from de, the default language, to English. It does not work, when I try to switch back. Has anyone an idea, how to fix that? Bernd M. Radowicz | 2008/09/09
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 languages. 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
In the langnames.php Sveden is connected with 'sv'. If you want to add the 'se' for the Sveden flag the flag is missing…
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.”?
Could the installation PHP code include (above) be changed to conditionally load the translation if found, and otherwise do nothing? (I'm not an expert on PHP so not sure if that's possible).
Or, add an explicit caution that when deleting, one should first remove the include logic. I clicked the “Delete” button on the plugin admin page, and immediately had an “empty” wiki, since my translation block was almost the first thing loaded. An edit to the header file to reverse the installation fixed everything of course.
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 / menus 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
This patch will append the language to the end of the existing page instead of creating a new namespace
Old Style:
translate:project
translate:<lang>:project
Patch Style:
translate:project
translate:project:<lang>
--- lib/plugins/translation/syntax.php.orig 2007-07-15 04:27:36.000000000 -0400 +++ lib/plugins/translation/syntax.php 2008-07-30 15:10:53.000000000 -0400 @@ -97,7 +97,7 @@ global $conf; global $saved_conf; if($lng){ - $link = ':'.$this->tns.$lng.':'.$idpart; + $link = ':'.$this->tns.':'.$idpart.':'.$lng; $name = $lng; }else{ $link = ':'.$this->tns.$idpart; @@ -123,8 +123,10 @@ $meta = p_get_metadata($ID); if($meta['plugin']['translation']['notrans']) return; - $rx = '/^'.$this->tns.'(('.join('|',$this->trans).'):)?/'; - $idpart = preg_replace($rx,'',$ID); + $rxns = '/^'.$this->tns.'/'; + $idnons = preg_replace($rxns,'',$ID); + $rx = '/('.join('|',$this->trans).')$/'; + $idpart = preg_replace($rx,'',$idnons); $out = '<div class="plugin_translation">'; $out .= '<span>'.$this->getLang('translations');
This makes sense for separating translation projects into their own namespaces such as:
Someone should find this useful!
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 preferred 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
- I have problems in showing the Spanish flag: cannot get it, it's showing the Mexican one instead. Same for the US/GB, but I renamed the two files (swapping the names) and solved it. Believe it or not, if I rename the MX.gif in MX.gif.bak and ES.gif in MX.gif, the preview in windows explorer changes to show again the Mexican flag!! this wasn't happening with GB/US, I now have an icon called US.gif but containing the uk flag.. Omar 07/08/08
Is there a way to get a raw text for the translation. Example: I have page documentation:mathascii and I want to translation to say Danish. I click the “DA” tab and DokuWiki tells me the page does not exist (da:documentation:mathascii) . In the toolbar of edit it would now be good to have an icon or link “Add untranslated text” which would then take the original text documentation:mathascii and add to the current text, which I could then translate. In this way any organisation - levels - graphs etc would be maintained and partial translations available. Thanks J.Lauritsen EpiData project
If you are using a Template like monobook there is a square-image before each language-code.
To disable the square-image edit the ~plugins/translation/style.css and
add in line ~14 list-style-image: none !important;
.dokuwiki div.plugin_translation ul li{
float: left;
list-style-type: none;
list-style-image: none !important;
padding: 0;
margin: 0;
}
— Mark Wolfgruber 2009/06/30