The idea is to create content blocks for each language within the template. I'm going to use "fr" as another language here
My template looks like this
Code: Select all
{getlang} (you'll see below)
{if $weblang == "fr"}
{content block="content_fr"}
{else}
{content}
{/if}
...
{if $weblang == "fr"}
{content block="title_fr" oneline="true" wysiwyg="false"}
{else}
{title}
{/if}
... and something like this to ensure that the template has blocks for menu entries in various languages, although they are not displayed on the template directly...
{if 0}
{content block="menu_fr" oneline="true" wysiwyg="false"}
{/if}
If you set it once in the URL and don't use it anymore afterwards, the system will default to this language using a cookie.
Here is my tag (getlang)
Tag: getlang
Code: Select all
/* assigns the variable {$weblang} */
global $gCms;
if (isset($_GET["lang"])) { /* Passed in the url: lang= ... */
$gCms->smarty->assign('weblang', $_GET["lang"]);
setcookie("MYlang", $_GET["lang"]);
} elseif (isset($_COOKIE["MYlang"])) {
$gCms->smarty->assign('weblang', $_COOKIE["MYlang"]);
} else {
setcookie("MYlang", "en");
$gCms->smarty->assign('weblang', "en");
}
Tag: general_menu_title
Code: Select all
/* param: pageid, assigns {$current_menu_text} */
global $gCms;
$manager =& $gCms->GetHierarchyManager();
/* $thisPage = $gCms->variables['content_id']; */
$thisPage = intval($params['pageid']);
$currentNode = &$manager->sureGetNodeById($thisPage);
$currentContent =& $currentNode->getContent();
if ($smarty->get_template_vars('weblang') == "en") {
$t_ =$currentContent->MenuText();
} else {
$t_ =$currentContent->GetPropertyValue('menu_' . $smarty->get_template_vars('weblang'));
}
$gCms->smarty->assign('current_menu_text', $t_);
Now, in your menu template, replace $node->menutext by this. In order to get the current pageID, I'm gonna use the capture trick.
the code snippet looks like that
Code: Select all
{capture name=MENUNODE}
{$node->id}
{/capture}
{general_menu_title pageid=$smarty.capture.MENUNODE}
Code: Select all
{if $count > 0}
<ul>
{foreach from=$nodelist item=node}
{capture name=MENUNODE}
{$node->id}
{/capture}
{general_menu_title pageid=$smarty.capture.MENUNODE}
{if $node->depth > $node->prevdepth}
{repeat string="<ul>" times=$node->depth-$node->prevdepth}
{elseif $node->depth < $node->prevdepth}
{repeat string="</li></ul>" times=$node->prevdepth-$node->depth}
</li>
{elseif $node->index > 0}</li>
{/if}
{if $node->current == true}
<li><a href="{$node->url}" class="currentpage"{if $node->target ne ""} target="{$node->target}"{/if}> {$current_menu_text} </a>
{elseif $node->parent == true && $node->depth == 1}
<li class="activeparent"> <a href="{$node->url}" class="activeparent"{if $node->target ne ""} target="{$node->target}"{/if}> {$current_menu_text} </a>
{elseif $node->type == 'sectionheader'}
<li class="sectionheader">{$current_menu_text}
{elseif $node->type == 'separator'}
<li style="list-style-type: none;"> <hr class="separator" />
{else}
<li><a href="{$node->url}"{if $node->target ne ""} target="{$node->target}"{/if}> {$current_menu_text} </a>
{/if}
{/foreach}
{repeat string="</li></ul>" times=$node->depth-1}</li>
</ul>
{/if}
