Revision [16766]

This is an old revision of MultiLanguageMenus made by IaePx6 on 2007-05-31 10:45:37.

 

Multi Language Menus

Last edited by IaePx6
Thu, 31 May 2007 10:45 UTC [diff]

See also:
 

MultiLanguageMenus is an extension of the menu solution described in WikkaMenus. Installation of this extension requires prior installation of WikkaMenus.

This extension provides a possibility to have a link on a page to change the language of menu items. The menu items and their corresponding language codes are stored in a table. A cookie is installed to check the language chosen by the user.

The multi language menu system:

Installation requires:

This extension has been designed for three languages, but it can easily be changed into a version for more languages.

Note:
There is actually an easier solution to this, as was pointed out to me by EmeraldIsland in the notes to this page. Using the original version of WikkaMenus, it requires merely one action (similar to the language action below), adding a small function to wikka.php to deal with a language cookie, using suffixes in the menuname corresponding to the language, and some recoding of the header action. Rather quick and easy, and doesn't require dealing with the database :)

The only reason to choose a more elaborate version as described in this document is for admin purposes. It provides a better overview of corresponding menus in different languages.


Extended wikka_menus Database Table


The database table wikka_menus needs to be extended. Here's the description:

CREATE TABLE `wikka_menus` (
  `name` varchar(20) NOT NULL default '',
  `lng1` char(2) NOT NULL default '',
  `lng2` char(2) NOT NULL default '',
  `lng3` char(2) NOT NULL default '',
  `content` varchar(255) NOT NULL default '',
  `content2` varchar(255) NOT NULL default '',
  `content3` varchar(255) NOT NULL default '',
  `css_class` varchar(20) NOT NULL default '',
UNIQUE KEY `name` (`name`)
) TYPE=MyISAM;


The field lng1 is the language code corresponding to the menu description in content, lng2 corresponds to content2 and lng3 to content3. Note that the content is not renamed with respect to WikkaMenus, it ensures that its {{menu}} action can still be used to change the menu in the default language.

The new action {{multilangmenu}} (see below) provides an interface to edit all the fields. The interface is similar to the one in WikkaMenus, the content fields are next to each other, so you can easily see how menus if different languages correspond.


Two New Actions


Language Switch and Redirection

This action installs a cookie in which the language code is stored. This code is typically a two-letter language code, like de or en.
The action takes two arguments. The first states the new language to be used for the menus, the second states to from which page the new language version will start.

The action {{language nl MyDutchPage}} will change menu language to Dutch (nl) and will redirect to MyDutchPage. It's typical use would be in a language link somewhere in the menus.

Grab the text and save as language.php in your action directory.

<?php
	if (empty($wikka_vars)) { $wikka_vars="en HomePage"; }
	$pieces = explode(" ", $wikka_vars, 2);
	setcookie("wikkalang", $pieces[0]);
	header("Location: wikka.php?wakka=".$pieces[1]."");
	exit;
?>


Menu editor

The following text is the code for the action {{multilangmenu}}. It shows a similar interface as in WikkaMenus but extended to fit the extra table entries. Grab the text and save as multilangmenu.php in your action directory. It's typical use would be to put {{multilangmenu}} on a single page.

Note that the original {{menu}} can still be used, but it will only show and update content.

%%
<!-- Multi Language Menu Configuration Interface -->
<!-- Version 1.0, by Cornelis Wiebering -->
<!-- Based on Menu Configuration Interface 1.0 -->

<h2>Multilanguage Menu Configuration</h2>
<br />

<?php
if ($this->IsAdmin()) {
switch ($_POST["operation"]) {
case "Create Menu":
if ($this->MenuExists($_POST["newname"])) {
echo $this->Format("
Sorry!
A menu named \.$_POST["newname"]."\" already exists. --- Please choose another name<<::c::--- --- "); } else { $this->CreateMenu($_POST["newname"], $_POST["css"]); echo $this->Format("<<**Thanks!** --- Menu \.$_POST["newname"]."\" has been created
 

");
}
break;

case "Delete Menu":
echo $this->Format("
Confirmation required
 

Do you really want to delete ".$_POST["name"]."?

");
$formdelete = '<input type="hidden" name="name" value="'.$_POST["name"].'" />'.
'<input type="submit" name="operation" value="Confirm Deletion" style="width: 120px" accesskey="s" />'.
'<input type="button" value="Cancel" onClick="history.back();" style="width: 120px" /><p>
There are 2 comments on this page. [Show comments]
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki