I think multilingual support should become part of the core as a default module/plugin. Here’s how I’ve added this quickly for now. Just another way of doing the same without cookies.
Have a tree for each language and have an unpublished folder ’Menu’ for the menu in the language folder. Like this:
> English
| > Menu (unpublished)
| | > Home
| | > Feedback
| | > ...
| > Links
| | > Link to an english item
| | > ...
> Dutch
| > Menu (unpublished)
| | > Home
| | > Reageer
| | > ...
| > Links
| | > Link to a dutch item
| | > ...
Remove all the content from your snippets and move them to chunks. You can then use the snippets ’getLanguageId’ and ’getMenuId’ (see below) to do this:
Display the menu for a language.
[!ListMenu?LM_node=[[getMenuId]] !]
Use a chunk in a certain language
{{html_navigation_[[getLanguageId]]}}
Or
{{[[getLanguageId]]_navigation}}
SNIPPET getLanguageId
return getRootId($modx);
function getRootId($modx) {
$parentId=$modx->documentObject['id'];
do {
$thisId=$parentId;
// Get published or unpublished parent
$thisDoc=$modx->getDocument($thisId,'parent',1,0) ? $modx->getDocument($thisId,'parent',1,0) : $modx->getDocument($thisId,'parent',0,0);
$parentId = $thisDoc['parent'];
} while ($parentId!=0);
return $thisId;
}
SNIPPET getMenuId
// First get the root ID for this branch
$pId = getRootId($modx);
// Next, get all children for this parent
$children = $modx->getDocumentChildren($pId, $published=0, $deleted=0, $fields="*");
// Then find the child named 'Menu'
$i=0;
while ($children[$i]['pagetitle']!="Menu" || $i>=count($children)) $i++;
return $children[$i]['id'];
function getRootId($modx) {
$parentId=$modx->documentObject['id'];
do {
$thisId=$parentId;
// Get published or unpublished parent
$thisDoc=$modx->getDocument($thisId,'parent',1,0) ? $modx->getDocument($thisId,'parent',1,0) : $modx->getDocument($thisId,'parent',0,0);
$parentId = $thisDoc['parent'];
} while ($parentId!=0);
return $thisId;
}