DokuWiki

It's better when it's simple

User Tools

Site Tools


plugin:multilingual

This is an old revision of the document!


Multilingual Plugin

Compatible with DokuWiki

  • 2024-02-06 "Kaos" unknown
  • 2023-04-04 "Jack Jackrum" unknown
  • 2022-07-31 "Igor" unknown
  • 2020-07-29 "Hogfather" yes

plugin Collects mechanisms that converts DokuWiki into a multilingual wiki.

Last updated on
2020-12-15
Provides
Syntax, Action
Repository
Source
Conflicts with
translation

This plugin tries to collect and improve on a few multilingual plugins and tips that are floating around and collate them into a single plugin that provides a consistent interface for multilingual capabilities.

Installation

Download and install the plugin using the Plugin Manager using the following url.

https://github.com/stonier/dokuwiki_plugins/raw/master/releases/multilingual-1.0.2.tar.gz

Use the plugin manager, or alternatively, just download and install into the doku/lib/plugins directory.

Configuration

You'll need to hack your template a little to get it to show the plugin's flags.

Template

Without hacking your template too much, the cleanest way is to create a file in your template directory called /lib/tpl/_template_/show_languages.html

show_languages.html
<?php 
  $multi_lingual_plugin = &plugin_load('syntax','multilingual');
  if ( $multi_lingual_plugin ) {
    if ( !plugin_isdisabled($multi_lingual_plugin->getPluginName() ) ) {
      print $multi_lingual_plugin->_showTranslations();
    }
  }
?>

Note that the if conditions check first that the plugin both exists and is enabled - this allows your template to function, even if you do not currently have the plugin installed. Then add the following line somewhere in your template's main.php .

<?php @include(dirname(__FILE__).'/show_languages.html')?>

Configuration Manager

As admin, under the configuration settings page, there are some important configuration settings that are necessary to be configured before proceeding:

Enabled Languages provide a comma separated list here (no default is assumed, so include
all languages you wish to enable).
Use Flags enables graphics for the language items.
Utilise Browser UI Preference use the browser's language preference to set the language used by
the wiki's UI
Start page redirection when logging in, redirect the user to the start page corresponding to
their language.

You can test the browser sniffing in Firefox by simply going to edit→preferences→advanced and choose a language other than your system language.

Requests/Issues

You can either use the forum above, or add below for any discussion about problems/requests you might have.

Root Page Redirection

Also, I figured I wanted the user to be redirected to a language page instead of page not found when visiting the top site without explicitly specifying the language namespace. (ex : http://my.org/wiki/doku.php) The following code (should go before 'return true' in 'multilingual_ui' within 'action.php' of this plugin) will look for browser preference language first and then list of enabled languages in this plugin and check if any of the language page exists and if it does, redirects there. This only redirects the top page, since it's hard to determine if the initial part of the namespace of other pages refers to a language or not. (Maybe unless it goes through the list of ISO codes.) But then again, other pages should be linked with language preference prepended. (This does not honor the RFC for 'Location' header by not being an absolute URL, but browsers do handle these anyway…)

  if($ID == $conf['start'])
   {
      array_unshift($enabled_languages, $conf['lang']);
 
      foreach(array_unique($enabled_languages) as $language)
      {
         if(file_exists("{$conf['savedir']}/pages/$language/$ID.txt"))
         {
            header("Location: {$_SERVER['PHP_SELF']}?id=$language:$ID");
            exit;
         }
      }
   }

Anyone using 'sidebar' template can create the sidebar page at 'en:sidebar' and the likes to have separate languages displayed for sidebars. Using 'indexmenu' inside the sidebar will also automatically limit the pages shown for that particular language as well.

h1d, 2009-11-21

To remove redundant 'start' link without language prefix (which switches back to the browser preferred language if above modification was done, even if the user is reading on another language than that) from the 'You are here' in the header, you can comment the following line in the 'function tpl_youarehere' in 'inc/template.php' of DokuWiki.

// always print the startpage
tpl_pagelink(':'.$conf['start']);

Also interface language could be switched to a different one from the document's (if browser preference is in Japanese, but the content is in English, it will show the interface in Japanese, which looks odd) but by adding the following line in 'function multilingual_ui' in 'action.php' of this plugin, it keeps the languages of interface and the content in sync.

array_unshift($languages, preg_replace('/^([\w\-]+):.+/', '\1', $ID));

before this block,

   foreach ($languages as $language) {
       if (in_array($language, $enabled_languages)) {
           $conf['lang'] = $language;
           break;
       }   
   }   

A note to developer but there is a small bug in 'function multilingual_ui' in 1.0.1 in this line,

$languages = preg_split("/,/", preg_replace('/\(;q=\d+\.\d+\)/i', '', getenv('HTTP_ACCEPT_LANGUAGE')));

First parameter of 'preg_replace' is supposed to be '/;q=\d+\.\d+/i'. It is not stripping the 'q' parameter from the browser accepted languages as is.

h1d, 2013-07-08

plugin/multilingual.1638977373.txt.gz · Last modified: 2021-12-08 16:29 by Nafpart

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
CC Attribution-Share Alike 4.0 International Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki