DokuWiki

It's better when it's simple

User Tools

Site Tools


plugin:multilingual

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
plugin:multilingual [2010-05-04 18:48] 158.227.0.239plugin:multilingual [2023-10-30 23:09] (current) Klap-in
Line 6: Line 6:
 email      : d.stonier@gmail.com email      : d.stonier@gmail.com
 type       : syntax,action type       : syntax,action
-lastupdate : 2009-02-11 +lastupdate : 2020-12-15 
-compatible : 2008-05-05+compatible : Greebo, Hogfather
 depends    :  depends    : 
 conflicts  : translation conflicts  : translation
 similar    : translation similar    : translation
-tags       : language+tags       : language, translation 
 +downloadurl: https://github.com/stonier/dokuwiki_plugins/raw/master/releases/multilingual-1.0.2.tar.gz 
 +sourcerepo : https://github.com/stonier/dokuwiki_plugins/tree/master/multilingual 
 +bugtracker : https://github.com/stonier/dokuwiki_plugins/issues
 ---- ----
  
 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. 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.
  
-===== Links ===== 
  
-  * [[http://snorriheim.dnsdojo.com/redmine/wiki/multilingual/Instructions|Home Page]] +===== Installation =====
-  * [[http://snorriheim.dnsdojo.com/doku/doku.php/en:cooking:cooking|Demo]] +
-  * [[http://snorriheim.dnsdojo.com/redmine/wiki/multilingual/Installation|Installation]] +
-  * [[http://snorriheim.dnsdojo.com/redmine/wiki/multilingual/Configuration|Configuration]]  +
-  * [[http://snorriheim.dnsdojo.com/redmine/projects/multilingual/boards|Forum]] +
-===== Requests/Issues =====+
  
-You can either use the forum above, or add below for any discussion about problems/requests you might have.+Download and install the plugin using the Plugin Manager using the following url.
  
-== Use browser language for the UI ==+https://github.com/stonier/dokuwiki_plugins/raw/master/releases/multilingual-1.0.2.tar.gz
  
-I couldn't get the //Use browser language for the UI// to workso I figured out the line below is wrong. The brackets and the dot are not escaped.+Use the plugin manageror alternatively, just download and install into the doku/lib/plugins directory.
  
-<code php> +===== Configuration =====
- $languages split(',', preg_replace('/(;q=\d+.\d+)/i', '', getenv('HTTP_ACCEPT_LANGUAGE'))); +
-</code>+
  
-I changed it to the one below and it works.+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'' 
 +<code php 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(); 
 +    } 
 +  } 
 +?> 
 +</code>
  
 +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'' .
 <code php> <code php>
-        $languages = split(',', preg_replace('/\(;q=\d+\.\d+\)/i', '', getenv('HTTP_ACCEPT_LANGUAGE')));+<?php @include(dirname(__FILE__).'/show_languages.html')?>
 </code> </code>
  
--- //Viktor Söderqvist, 2009-08-14 23:34//+===Configuration Manager===
  
-What browser and php version were you using? Neither escaping should strictly be necessarybut have added it to the plugin as it doesn't seem to cause any problems for me.+As adminunder the configuration settings page, there are some important configuration settings that are necessary to be configured before proceeding:
  
--- //Daniel Stonier2009-10-08 23:24//+^Enabled Languages | provide a comma separated list here (no default is assumedso 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.|
  
-Why escape the brackets? +You can test the browser sniffing in Firefox by simply going to edit->preferences->advanced and choose a language other than your system language.
  
-> Actually it was like that for no better reason than I didn't write that part - it inherited from the translation plugin or whatever I was building from (can't recall for sure). I might review it later when I get a chance.+===== Requests/Issues =====
  
-The HTTP_ACCEPT_LANGUAGE variable cannot have literal brackets there. And not used for back referencing either, so the brackets should go away. Current distributed code escapes themwhich will not strip away the priority values. Also the value can be usually in the form of 'en-us' with country code attached and if that doesn't hit, it should look for 'en' or most time, it will miss. And I think that the interface language should inherit the page chosen language instead of the browser language. Here's the little modification to fix them.+You can either use the forum aboveor add below for any discussion about problems/requests you might have.
  
-<code php> 
-   $languages = split(',', preg_replace(array('/;q=\d+\.\d+/i', '/-[a-z]+/i'), '', getenv('HTTP_ACCEPT_LANGUAGE'))); 
-   array_unshift($languages, preg_replace('/^([\w\-]+):.+$/', '\1', $ID)); 
-</code> 
- 
-> Actually, I think choosing the browser for the user interface is better. Most users' will always be more comfortable with their native interface. For instance, I'm rapidly becoming multilingual (english+korean), so I will often read the korean pages, but am much more comfortable having an english interface still. My colleagues at work are the opposite. 
- 
-> -- //Daniel Stonier, 2009-12-26 5:24// 
- 
-> Say, you are not on your usual computer and the language settings differ from your preferred one, you go pick the language you want on the interface, the contents are changed but the interface staying same looks odd. Average use of this is to make it feel as native as it can. I do not see much chance having multilingual users asking for multiple languages of the page with a single language interface but single language speakers asking for their native languages. 
- 
-> -- //h1d, 2009-12-28// 
  
 == Root Page Redirection == == 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') 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...)+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...)
  
 <code php> <code php>
Line 91: Line 92:
 -- //h1d, 2009-11-21// -- //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. 
  
-Hi there,+<code> 
 +// always print the startpage 
 +tpl_pagelink(':'.$conf['start']); 
 +</code>
  
-Is there anyway to make the buttons of the topbar change when i switch to another language? It would be interesting if dokuwiki'title changed aswellHas anyone got any ideas?+Also interface language could be switched to a different one from the document'(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.
  
-Thanks,+<code> 
 +array_unshift($languagespreg_replace('/^([\w\-]+):.+/', '\1', $ID)); 
 +</code> 
 + 
 +before this block, 
 + 
 +<code> 
 +   foreach ($languages as $language) { 
 +       if (in_array($language, $enabled_languages)) { 
 +           $conf['lang'] = $language; 
 +           break; 
 +          
 +      
 +</code> 
 + 
 +A note to developer but there is a small bug in 'function multilingual_ui' in 1.0.1 in this line, 
 +<code> 
 +$languages = preg_split("/,/", preg_replace('/\(;q=\d+\.\d+\)/i', '', getenv('HTTP_ACCEPT_LANGUAGE'))); 
 +</code>
  
-Alex+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.
  
-> OKalready done! +-- //h1d2013-07-08//
-+
-> Thanks!+
plugin/multilingual.1272991707.txt.gz · Last modified: 2010-05-04 18:48 by 158.227.0.239

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