Translation Plugin

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.

Tagged with language, translation.

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:

  • separate namespaces are used to store translations
  • the configured default language is used as the main language
  • no namespace is used for the main language
  • translated pages need to have the same pagename as the main language page

Download

Use this URL to download the file manually or through the plugin manager:

Recent Changes:

  • 2008-04-01 – print.css and more translations added
  • 2007-10-17 – Brasilian Portugues and Chinese Translations added
  • 2007-07-15 – another config problem fixed, support for optional UI language switch
  • 2007-06-13 – fixed problems with config and when using without namespace restriction
  • 2007-06-03 – initial upload

Installation

  1. Download and install the plugin through the Plugin Manager.
  2. Configure it through the Config Manager
  3. Add the following code in your template's 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.

Configuration

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.

Manual 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.

Usage

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~~

Requests

Sidebar translation?

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

Flags

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? — dwayne
Oh, 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

Dropdown menu

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

No translation zone

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.”?

Discussion

german translation

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'] = '&Uuml;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 &Uuml;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 &Uuml;bersetzung erkl&auml;rt. Sie wird vom Sprachumschalter verlinkt.";


I put mine here. StinkyWinky 2008/07/08 13:46

fallback language

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

hide the untranslated page links

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

Bullets in Firefox

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

Right to Left (rtl) css

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?

install problems and dokuwiki

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

 
plugin/translation.txt · Last modified: 2008/07/17 08:27 by 84.114.149.87
 
Imprint Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki
WikiForumIRCBugsTranslate