Revision history for MultiLanguageMenus


Revision [23221]

Last edited on 2016-05-20 07:38:47 by WigAnt [Replaces old-style internal links with new pipe-split links.]
Additions:
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]]""## --- --- --- ');
Deletions:
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]]""## --- --- --- ');


Revision [19192]

Edited on 2008-01-28 00:14:43 by WigAnt [Modified links pointing to docs server]

No Differences

Revision [16967]

Edited on 2007-05-31 23:27:31 by WigAnt [Reverted]
Additions:
'<input type="button" value="Cancel" onClick="history.back();" style="width: 120px" /><p> </p>';
print $this->FormOpen("","","post");
print $formdelete;
print $this->FormClose();
case "Confirm Deletion":
$this->DeleteMenu($_POST["name"]);
echo $this->Format("<<**Thanks!** --- Menu \"".$_POST["name"]."\" has been deleted<<::c:: --- ");
case "Rename Menu":
echo $this->Format("<<**Sorry!** --- A menu named \"".$_POST["newname"]."\" already exists. --- Please choose another name<<::c:: --- --- ");
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> </p>';
print $this->FormOpen("","","post");
print $formrename;
print $this->FormClose();
case "Confirm Rename":
$this->RenameMenu($_POST["oldname"], $_POST["newname"]);
echo $this->Format("<<**Thanks!** --- Menu has been renamed as \"".$_POST["newname"]."\"<<::c:: --- --- ");
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:: --- --- ");
}
// 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> </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##===
==Language Cookie==
Grab the following code and put it in ##wikka.php## above the code for the menus. The cookie will be know as ##wikkalang##.
// LANGUAGE COOKIES
// For use with multi-language menus. Version 1.0, Written by Cornelis Wiebering
function SetLanguage($lng) {
$this->SetPersistentCookie("wikkalang", $lng);
return $lng;
}
function GetLanguage() {
if ($lang = $this->GetCookie("wikkalang")) { return $lang; }
else { return $this->SetLanguage("en"); }
}
==Menu Functions==
Grab the following code and put it in place of the menu functions code in ##wikka.php##.
// MENU FUNCTIONS
// Edited to be able to handle multi-language menus. Version 1.0, Written by Cornelis Wiebering
function LoadMenu($name) {
$content = $this->LoadSingle("SELECT * FROM ".$this->config["table_prefix"]."menus WHERE name = '".$name."'");
return $content;
}
function LoadAllMenus() {
$menurow = $this->LoadAll("SELECT * FROM ".$this->config["table_prefix"]."menus");
return $menurow;
}
function SaveMenu($name, $lng1, $lng2, $lng3, $cont, $cont2, $cont3) {
$this->Query("UPDATE ".$this->config["table_prefix"]."menus SET lng1 ='".mysql_real_escape_string(trim(str_replace("\r", "", $lng1)))."' WHERE name = '".$name."' LIMIT 1");
$this->Query("UPDATE ".$this->config["table_prefix"]."menus SET lng2 ='".mysql_real_escape_string(trim(str_replace("\r", "", $lng2)))."' WHERE name = '".$name."' LIMIT 1");
$this->Query("UPDATE ".$this->config["table_prefix"]."menus SET lng3 ='".mysql_real_escape_string(trim(str_replace("\r", "", $lng3)))."' WHERE name = '".$name."' LIMIT 1");
$this->Query("UPDATE ".$this->config["table_prefix"]."menus SET content ='".mysql_real_escape_string(trim(str_replace("\r", "", $cont)))."' WHERE name = '".$name."' LIMIT 1");
$this->Query("UPDATE ".$this->config["table_prefix"]."menus SET content2 ='".mysql_real_escape_string(trim(str_replace("\r", "", $cont2)))."' WHERE name = '".$name."' LIMIT 1");
$this->Query("UPDATE ".$this->config["table_prefix"]."menus SET content3 ='".mysql_real_escape_string(trim(str_replace("\r", "", $cont3)))."' WHERE name = '".$name."' LIMIT 1");
}
function MenuExists($name) {
if ($this->LoadMenu($name)){
return true;
}
}
function RenameMenu($oldname, $newname) {
$this->Query("UPDATE ".$this->config["table_prefix"]."menus SET name = '".$newname."' WHERE name = '".$oldname."' LIMIT 1");
}
function DeleteMenu($name) {
$this->Query("DELETE FROM ".$this->config["table_prefix"]."menus WHERE name = '".$name."' LIMIT 1");
}
function CreateMenu($name, $css_class) {
$this->Query("INSERT INTO ".$this->config["table_prefix"]."menus SET name = '".mysql_real_escape_string($name)."', content = '', content2 = '', content3 = '', lng1 = '', lng2 = '', lng3 = '', css_class = '".mysql_real_escape_string($css_class)."'");
}
function TrimMenu($list) {
foreach (explode("\n", $list) as $line) {
$line = trim($line);
$trimmed_list .= $line."\n";
}
return $trimmed_list;
}
function PrintMenu($name) {
if ($menurow = $this->LoadMenu($name)) {
$lang = $this->GetLanguage();
$lng1 = $menurow["lng1"];
$lng2 = $menurow["lng2"];
$lng3 = $menurow["lng3"];
$menu = "<ul class=\"".$menurow["css_class"]."\">";
switch($lang) {
case $lng1:
foreach (explode("\n", $menurow["content"]) as $menuitem) { $menu .="<li>".$this->Format($menuitem)."</li>\n"; }
break;
case $lng2:
foreach (explode("\n", $menurow["content2"]) as $menuitem) { $menu .="<li>".$this->Format($menuitem)."</li>\n"; }
break;
case $lng3:
foreach (explode("\n", $menurow["content3"]) as $menuitem) { $menu .="<li>".$this->Format($menuitem)."</li>\n"; }
break;
default:
foreach (explode("\n", $menurow["content"]) as $menuitem) { $menu .="<li>".$this->Format($menuitem)."</li>\n"; }
break;
}
$menu .= "</ul>\n";
return $menu;
}
==Notes==
~- Please let me know if the code does not comply to standards used in other extensions. I will change it accordingly.
~- The code is provided as is. It works for my site, but that does not necessarily mean it works for you. Use at own risk.
~- You can see the code at work on [[wiki.views-and-vision.org]]. Click on the language links in the upper right corner.
-- WigAnt
CategoryUserContributions
Deletions:
'<input type="button" value="Cancel" onClick="history.back();" style="width: 120px" /><p>


Revision [16766]

Edited on 2007-05-31 10:45:37 by IaePx6 [Reverted]
Additions:
'<input type="button" value="Cancel" onClick="history.back();" style="width: 120px" /><p>
Deletions:
'<input type="button" value="Cancel" onClick="history.back();" style="width: 120px" /><p> </p>';
print $this->FormOpen("","","post");
print $formdelete;
print $this->FormClose();
case "Confirm Deletion":
$this->DeleteMenu($_POST["name"]);
echo $this->Format("<<**Thanks!** --- Menu \"".$_POST["name"]."\" has been deleted<<::c:: --- ");
case "Rename Menu":
echo $this->Format("<<**Sorry!** --- A menu named \"".$_POST["newname"]."\" already exists. --- Please choose another name<<::c:: --- --- ");
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> </p>';
print $this->FormOpen("","","post");
print $formrename;
print $this->FormClose();
case "Confirm Rename":
$this->RenameMenu($_POST["oldname"], $_POST["newname"]);
echo $this->Format("<<**Thanks!** --- Menu has been renamed as \"".$_POST["newname"]."\"<<::c:: --- --- ");
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:: --- --- ");
}
// 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> </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##===
==Language Cookie==
Grab the following code and put it in ##wikka.php## above the code for the menus. The cookie will be know as ##wikkalang##.
// LANGUAGE COOKIES
// For use with multi-language menus. Version 1.0, Written by Cornelis Wiebering
function SetLanguage($lng) {
$this->SetPersistentCookie("wikkalang", $lng);
return $lng;
}
function GetLanguage() {
if ($lang = $this->GetCookie("wikkalang")) { return $lang; }
else { return $this->SetLanguage("en"); }
}
==Menu Functions==
Grab the following code and put it in place of the menu functions code in ##wikka.php##.
// MENU FUNCTIONS
// Edited to be able to handle multi-language menus. Version 1.0, Written by Cornelis Wiebering
function LoadMenu($name) {
$content = $this->LoadSingle("SELECT * FROM ".$this->config["table_prefix"]."menus WHERE name = '".$name."'");
return $content;
}
function LoadAllMenus() {
$menurow = $this->LoadAll("SELECT * FROM ".$this->config["table_prefix"]."menus");
return $menurow;
}
function SaveMenu($name, $lng1, $lng2, $lng3, $cont, $cont2, $cont3) {
$this->Query("UPDATE ".$this->config["table_prefix"]."menus SET lng1 ='".mysql_real_escape_string(trim(str_replace("\r", "", $lng1)))."' WHERE name = '".$name."' LIMIT 1");
$this->Query("UPDATE ".$this->config["table_prefix"]."menus SET lng2 ='".mysql_real_escape_string(trim(str_replace("\r", "", $lng2)))."' WHERE name = '".$name."' LIMIT 1");
$this->Query("UPDATE ".$this->config["table_prefix"]."menus SET lng3 ='".mysql_real_escape_string(trim(str_replace("\r", "", $lng3)))."' WHERE name = '".$name."' LIMIT 1");
$this->Query("UPDATE ".$this->config["table_prefix"]."menus SET content ='".mysql_real_escape_string(trim(str_replace("\r", "", $cont)))."' WHERE name = '".$name."' LIMIT 1");
$this->Query("UPDATE ".$this->config["table_prefix"]."menus SET content2 ='".mysql_real_escape_string(trim(str_replace("\r", "", $cont2)))."' WHERE name = '".$name."' LIMIT 1");
$this->Query("UPDATE ".$this->config["table_prefix"]."menus SET content3 ='".mysql_real_escape_string(trim(str_replace("\r", "", $cont3)))."' WHERE name = '".$name."' LIMIT 1");
}
function MenuExists($name) {
if ($this->LoadMenu($name)){
return true;
}
}
function RenameMenu($oldname, $newname) {
$this->Query("UPDATE ".$this->config["table_prefix"]."menus SET name = '".$newname."' WHERE name = '".$oldname."' LIMIT 1");
}
function DeleteMenu($name) {
$this->Query("DELETE FROM ".$this->config["table_prefix"]."menus WHERE name = '".$name."' LIMIT 1");
}
function CreateMenu($name, $css_class) {
$this->Query("INSERT INTO ".$this->config["table_prefix"]."menus SET name = '".mysql_real_escape_string($name)."', content = '', content2 = '', content3 = '', lng1 = '', lng2 = '', lng3 = '', css_class = '".mysql_real_escape_string($css_class)."'");
}
function TrimMenu($list) {
foreach (explode("\n", $list) as $line) {
$line = trim($line);
$trimmed_list .= $line."\n";
}
return $trimmed_list;
}
function PrintMenu($name) {
if ($menurow = $this->LoadMenu($name)) {
$lang = $this->GetLanguage();
$lng1 = $menurow["lng1"];
$lng2 = $menurow["lng2"];
$lng3 = $menurow["lng3"];
$menu = "<ul class=\"".$menurow["css_class"]."\">";
switch($lang) {
case $lng1:
foreach (explode("\n", $menurow["content"]) as $menuitem) { $menu .="<li>".$this->Format($menuitem)."</li>\n"; }
break;
case $lng2:
foreach (explode("\n", $menurow["content2"]) as $menuitem) { $menu .="<li>".$this->Format($menuitem)."</li>\n"; }
break;
case $lng3:
foreach (explode("\n", $menurow["content3"]) as $menuitem) { $menu .="<li>".$this->Format($menuitem)."</li>\n"; }
break;
default:
foreach (explode("\n", $menurow["content"]) as $menuitem) { $menu .="<li>".$this->Format($menuitem)."</li>\n"; }
break;
}
$menu .= "</ul>\n";
return $menu;
}
==Notes==
~- Please let me know if the code does not comply to standards used in other extensions. I will change it accordingly.
~- The code is provided as is. It works for my site, but that does not necessarily mean it works for you. Use at own risk.
~- You can see the code at work on [[wiki.views-and-vision.org]]. Click on the language links in the upper right corner.
-- WigAnt
CategoryUserContributions


Revision [15355]

Edited on 2006-09-25 02:30:29 by WigAnt [Reverted]

No Differences

Revision [15354]

Edited on 2006-09-25 02:29:32 by WigAnt [Reverted]
Deletions:
==To Do==
~-Move some code and descriptions on this page to: LanguageAction, LanguageActionInfo, MultiLanguageMenuAction and MultiLanguageMenuActionInfo


Revision [15334]

Edited on 2006-09-16 09:30:30 by WigAnt [Reverted]

No Differences

Revision [15333]

Edited on 2006-09-16 09:24:43 by WigAnt [Reverted]
Additions:
**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.


Revision [15331]

Edited on 2006-09-15 04:34:11 by WigAnt [Reverted]
Additions:
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.


Revision [15321]

Edited on 2006-09-14 05:25:22 by WigAnt [Reverted]
Additions:
~- does not change the UI messages generated by ##wikka.php##. They will still be in English.
Deletions:
~- does not change the IU messages generated by ##wikka.php##.


Revision [15319]

Edited on 2006-09-14 04:56:41 by WigAnt [Reverted]
Deletions:
CategoryDevelopmentArchitecture


Revision [15317]

Edited on 2006-09-14 04:51:46 by WigAnt [Reverted]
Additions:
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 following code and put it in ##wikka.php## above the code for the menus. The cookie will be know as ##wikkalang##.
Deletions:
===Description and Use===
""{{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 code and put it in ##wikka.php## above the code for the menus.


Revision [15316]

Edited on 2006-09-14 04:45:48 by WigAnt [Reverted]
Additions:
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:
~- changes the menu languages and the pages the menus link to according to the language chosen.
~- switches to a default language if the specified language does not exist for a certain menu item.
~- does not change the IU messages generated by ##wikka.php##.
Installation requires:
~-prior installation of WikkaMenus
~-extension of the menu database table
~-installation of two actions
~-two changes in ##wikka.php##
~- You can see the code at work on [[wiki.views-and-vision.org]]. Click on the language links in the upper right corner.
CategoryUserContributions
CategoryDevelopmentArchitecture
Deletions:
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.
~- You can see the code at work on [[http://wiki.views-and-vision.org]]. Click on the language links in the upper right corner.
~-Add some Categories to this page


Revision [15315]

Edited on 2006-09-14 04:34:27 by WigAnt [Reverted]
Additions:
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##.
~- Please let me know if the code does not comply to standards used in other extensions. I will change it accordingly.
~- The code is provided as is. It works for my site, but that does not necessarily mean it works for you. Use at own risk.
~- You can see the code at work on [[http://wiki.views-and-vision.org]]. Click on the language links in the upper right corner.
~-Move some code and descriptions on this page to: LanguageAction, LanguageActionInfo, MultiLanguageMenuAction and MultiLanguageMenuActionInfo
Deletions:
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'.
~- Please let me know if the code does not comply to standards used in other extension. I will change it accordingly. -- WigAnt
~-LanguageAction & LanguageActionInfo
~-MultiLanguageMenuAction & MultiLanguageMenuActionInfo


Revision [15314]

Edited on 2006-09-14 04:12:43 by WigAnt [Reverted]
Additions:
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.
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.
""{{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.
Note that the original ""{{menu}}"" can still be used, but it will only show and update ##content##.
// LANGUAGE COOKIES
// For use with multi-language menus. Version 1.0, Written by Cornelis Wiebering
function SetLanguage($lng) {
$this->SetPersistentCookie("wikkalang", $lng);
return $lng;
function GetLanguage() {
if ($lang = $this->GetCookie("wikkalang")) { return $lang; }
else { return $this->SetLanguage("en"); }
Grab the code and put it in ##wikka.php## above the code for the menus.
Grab the following code and put it in place of the menu functions code in ##wikka.php##.
// MENU FUNCTIONS
// Edited to be able to handle multi-language menus. Version 1.0, Written by Cornelis Wiebering
function LoadMenu($name) {
$content = $this->LoadSingle("SELECT * FROM ".$this->config["table_prefix"]."menus WHERE name = '".$name."'");
return $content;
function LoadAllMenus() {
$menurow = $this->LoadAll("SELECT * FROM ".$this->config["table_prefix"]."menus");
return $menurow;
function SaveMenu($name, $lng1, $lng2, $lng3, $cont, $cont2, $cont3) {
$this->Query("UPDATE ".$this->config["table_prefix"]."menus SET lng1 ='".mysql_real_escape_string(trim(str_replace("\r", "", $lng1)))."' WHERE name = '".$name."' LIMIT 1");
$this->Query("UPDATE ".$this->config["table_prefix"]."menus SET lng2 ='".mysql_real_escape_string(trim(str_replace("\r", "", $lng2)))."' WHERE name = '".$name."' LIMIT 1");
$this->Query("UPDATE ".$this->config["table_prefix"]."menus SET lng3 ='".mysql_real_escape_string(trim(str_replace("\r", "", $lng3)))."' WHERE name = '".$name."' LIMIT 1");
$this->Query("UPDATE ".$this->config["table_prefix"]."menus SET content ='".mysql_real_escape_string(trim(str_replace("\r", "", $cont)))."' WHERE name = '".$name."' LIMIT 1");
$this->Query("UPDATE ".$this->config["table_prefix"]."menus SET content2 ='".mysql_real_escape_string(trim(str_replace("\r", "", $cont2)))."' WHERE name = '".$name."' LIMIT 1");
$this->Query("UPDATE ".$this->config["table_prefix"]."menus SET content3 ='".mysql_real_escape_string(trim(str_replace("\r", "", $cont3)))."' WHERE name = '".$name."' LIMIT 1");
function MenuExists($name) {
if ($this->LoadMenu($name)){
return true;
function RenameMenu($oldname, $newname) {
$this->Query("UPDATE ".$this->config["table_prefix"]."menus SET name = '".$newname."' WHERE name = '".$oldname."' LIMIT 1");
function DeleteMenu($name) {
$this->Query("DELETE FROM ".$this->config["table_prefix"]."menus WHERE name = '".$name."' LIMIT 1");
function CreateMenu($name, $css_class) {
$this->Query("INSERT INTO ".$this->config["table_prefix"]."menus SET name = '".mysql_real_escape_string($name)."', content = '', content2 = '', content3 = '', lng1 = '', lng2 = '', lng3 = '', css_class = '".mysql_real_escape_string($css_class)."'");
function TrimMenu($list) {
foreach (explode("\n", $list) as $line) {
$line = trim($line);
$trimmed_list .= $line."\n";
return $trimmed_list;
function PrintMenu($name) {
if ($menurow = $this->LoadMenu($name)) {
$lang = $this->GetLanguage();
$lng1 = $menurow["lng1"];
$lng2 = $menurow["lng2"];
$lng3 = $menurow["lng3"];
$menu = "<ul class=\"".$menurow["css_class"]."\">";
switch($lang) {
case $lng1:
foreach (explode("\n", $menurow["content"]) as $menuitem) { $menu .="<li>".$this->Format($menuitem)."</li>\n"; }
break;
case $lng2:
foreach (explode("\n", $menurow["content2"]) as $menuitem) { $menu .="<li>".$this->Format($menuitem)."</li>\n"; }
break;
case $lng3:
foreach (explode("\n", $menurow["content3"]) as $menuitem) { $menu .="<li>".$this->Format($menuitem)."</li>\n"; }
break;
default:
foreach (explode("\n", $menurow["content"]) as $menuitem) { $menu .="<li>".$this->Format($menuitem)."</li>\n"; }
break;
$menu .= "</ul>\n";
return $menu;
Deletions:
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.
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.
""{{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.
two functions to deal with the language cookie
changes in the menufunctions


Revision [15313]

Edited on 2006-09-14 04:01:40 by WigAnt [Reverted]
Additions:
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.
===Extended ##wikka_menus## Database Table===
The database table ##wikka_menus## needs to be extended. Here's the description:
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==
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.
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 />
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> </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> </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> </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##===
Deletions:
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 the wikka.php code. It will also install a cookie for storing the user language. Installation of this extension, requires prior installation of WikkaMenus.
===Database Table===
The database table 'wikka_menus' needs to be extended. Here's the description:
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.
===New Actions===
==Language switch and redirection==
Grab the text and save as 'language.php' in your action directory.
multilangmenu
===Changes in wikka.php===


Revision [15312]

Edited on 2006-09-14 03:44:59 by WigAnt [Reverted]
Additions:
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.
==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'.
<?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;
?>
Grab the text and save as 'language.php' in your action directory.
==Menu editor==
~- Please let me know if the code does not comply to standards used in other extension. I will change it accordingly. -- WigAnt
Deletions:
Note that the 'content' is not renamed with respect to WikkaMenu, it ensures that 'menu' action can still be used to change the menu in the default language.
language


Revision [15311]

Edited on 2006-09-14 03:36:43 by WigAnt [Reverted]
Additions:
The database table 'wikka_menus' needs to be extended. Here's the description:
Note that the 'content' is not renamed with respect to WikkaMenu, it ensures that 'menu' action can still be used to change the menu in the default language.
Deletions:
The database table 'wikka_menus' needs to be extended.


Revision [15310]

Edited on 2006-09-14 03:34:02 by WigAnt [Reverted]
Additions:
This extension has been designed for three languages, but it can easily be changed into a version for more languages.
The database table 'wikka_menus' needs to be extended.
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;
Deletions:
database description


Revision [15309]

Edited on 2006-09-14 03:28:11 by WigAnt [Reverted]
Additions:
~-WikkaMenus>>::c::
%%
database description
%%
%%
language
%%
%%
multilangmenu
%%
==Language Cookie==
%%
two functions to deal with the language cookie
%%
==Menu Functions==
%%
changes in the menufunctions
%%
~-Add some Categories to this page
~-MultiLanguageMenuAction & MultiLanguageMenuActionInfo
Deletions:
~-WikkaMenus
~-MultiLanguageMenuAction & MultiLanguageMenuActionInfo>>::c::
===CSS-styles===


Revision [15308]

Edited on 2006-09-14 03:17:23 by WigAnt [Reverted]
Additions:
~-MultiLanguageMenuAction & MultiLanguageMenuActionInfo>>::c::
Deletions:
~-MultiLanguageMenuAction & MultiLanguageMenuActionInfo>>


Revision [15306]

Edited on 2006-09-13 18:14:47 by WigAnt [Reverted]
Additions:
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 the wikka.php code. It will also install a cookie for storing the user language. Installation of this extension, requires prior installation of WikkaMenus.
===Changes in wikka.php===
Deletions:
MultiLanguageMenus is an extention of the menu solution described in WikkaMenus. The extension needs a larger database table for the menus, two new actions and some changes in the wikka.php code. It will also install a cookie for storing the user language. Installation of this extension, requires prior installation of WikkaMenus.
===Wikka hacks===


Revision [15303]

Edited on 2006-09-13 18:05:32 by WigAnt [Reverted]
Additions:
~-LanguageAction & LanguageActionInfo
~-MultiLanguageMenuAction & MultiLanguageMenuActionInfo>>
MultiLanguageMenus is an extention of the menu solution described in WikkaMenus. The extension needs a larger database table for the menus, two new actions and some changes in the wikka.php code. It will also install a cookie for storing the user language. Installation of this extension, requires prior installation of WikkaMenus.
Deletions:
~-WikkaMenulets
~-LanguageAction
~-LanguageActionInfo
~-MultiLanguageMenuAction
~-MultiLanguageMenuActionInfo>>
MultiLanguageMenu is an extention of the menu solution described in WikkaMenus. The extension needs a larger database table for the menus, two new actions and some changes in the wikka.php code. It will also install a cookie for storing the user language. Installation of this extension, requires prior installation of WikkaMenus.


Revision [15302]

The oldest known version of this page was created on 2006-09-13 18:04:46 by WigAnt [Reverted]
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki