Revision [15313]

This is an old revision of MultiLanguageMenus made by WigAnt on 2006-09-14 04:01:40.

 

Multi Language Menus

Last edited by WigAnt
Thu, 14 Sep 2006 04:01 UTC [diff]

See also:
 

Note: this text is unfinished. I just started typing it up. -- WigAnt

MultiLanguageMenus is an extension of the menu solution described in WikkaMenus. The extension needs a larger database table for the menus, two new actions and some changes in wikka.php. It will also install a cookie for storing the user language. Installation of this extension, requires prior installation of WikkaMenus.


Description and Use


This extension has been designed for three languages, but it can easily be changed into a version for more 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.


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.

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

<!-- 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<<::c:: --- ");
		}
		break;

	case "Delete Menu":
		echo $this->Format("<<**Confirmation required**<<::c:: --- 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>&nbsp;</p>';
		print $this->FormOpen("","","post");
		print $formdelete;
		print $this->FormClose();
		break;

	case "Confirm Deletion":
		$this->DeleteMenu($_POST["name"]);
			echo $this->Format("<<**Thanks!** --- Menu \"".$_POST["name"]."\" has been deleted<<::c:: --- ");
		break;

	case "Rename Menu":	
		if ($this->MenuExists($_POST["newname"])) {
			echo $this->Format("<<**Sorry!** --- A menu named \"".$_POST["newname"]."\" already exists. --- Please choose another name<<::c:: --- --- ");
		} else {
			echo $this->Format("<<**Confirmation required**<<::c:: --- Do you really want to rename **".$_POST["name"]."** as **".$_POST["newname"]."**? --- --- ");
			$formrename =  '<input type="hidden" name="oldname" value="'.$_POST["name"].'" />'.
				'<input type="hidden" name="newname" value="'.$_POST["newname"].'" />'.
				'<input type="submit" name="operation" value="Confirm Rename" style="width: 120px" accesskey="s" />'.
				'<input type="button" value="Cancel" onClick="history.back();" style="width: 120px" /><p>&nbsp;</p>';  
			print $this->FormOpen("","","post");
			print $formrename;
			print $this->FormClose();
		}
		break;

	case "Confirm Rename":
		$this->RenameMenu($_POST["oldname"], $_POST["newname"]);
		echo $this->Format("<<**Thanks!** --- Menu has been renamed as \"".$_POST["newname"]."\"<<::c:: --- --- ");
		break;

	case "Update Menu":
		$this->SaveMenu($_POST["name"], $_POST["lng1"], $_POST["lng2"], $_POST["lng3"],
						$this->TrimMenu($_POST["content"]),
						$this->TrimMenu($_POST["content2"]),
						$this->TrimMenu($_POST["content3"]));
		echo $this->Format("<<**Menu configuration stored** --- Thanks for updating \"".$_POST["name"]."\"!<<::c:: --- --- ");
		break;
	}

	// load stored menus and print menu forms
	echo $this->Format('Please enter menu items on separate lines. --- You can either use //""CamelCase"" links// like ##""PageIndex""## --- or //forced links// like: ##""[[http://www.mydomain.com External Link]]""## --- --- --- '); 
	$allmenus = $this->LoadAllMenus();
	foreach ($allmenus as $item) {
		$formarray[$item["name"]] = 'Menu name: <strong>'.$item["name"].'</strong><br />'.
			'<input type="hidden" name="name" value="'.$item["name"].'" />'.
			'<table><tr>'.
			'<td>language 1</td><td>language 2</td><td>language 3</td>'.
			'</tr><tr>'.
			'<td><input type="text" name="lng1" value="'.$item["lng1"].'"></td>'.
			'<td><input type="text" name="lng2" value="'.$item["lng2"].'"></td>'.
			'<td><input type="text" name="lng3" value="'.$item["lng3"].'"></td>'.
			'</tr><tr>'.
			'<td><textarea name="content" rows="6" cols="30">'.$item["content"].'</textarea></td>'.
			'<td><textarea name="content2" rows="6" cols="30">'.$item["content2"].'</textarea></td>'.
			'<td><textarea name="content3" rows="6" cols="30">'.$item["content3"].'</textarea></td>'.
			'</tr></table>'.
			'<input type="submit" name="operation" value="Update Menu" style="width: 120px" accesskey="s" />'.
			'<input type="submit" name="operation" value="Delete Menu" style="width: 120px" /><br />'.
			'<input type="text" name="newname" value="'.$item["name"].'" style="width: 120px">'.
			'<input type="submit" name="operation" value="Rename Menu" style="width: 120px" /><p>&nbsp;</p>';
		print $this->FormOpen("","","post"); 
		echo $formarray[$item["name"]];
		print($this->FormClose());
	}

	// "Create menu" form
	$newmenuform = '<table><tr>'.
		'<td>Menu name:</td><td><input type="text" name="newname" value="new_menu_name" style="width: 120px"></td></tr>'.
		'<tr><td>CSS class:</td><td> <input type="text" name="css" value="css_class" style="width: 120px"><td></tr></table>'.
		'<input type="submit" name="operation" value="Create Menu" style="width: 120px" /><br />';
	echo $this->Format("== Create a new menu ==");
	print $this->FormOpen("","","post");
	echo $newmenuform;
	print($this->FormClose());
	
} else {
	print("<em>Sorry, only Wikka Administrators can modify the Menu configuration.</em>");
}

?>


Changes in wikka.php



two functions to deal with the language cookie


Menu Functions

changes in the menufunctions





Notes

To Do


-- WigAnt
There are 2 comments on this page. [Show comments]
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki