Translated content + nav block

Permalink
Hi,
I'm quite fresh with c5, and I've faced really difficult as for beginner issue.
I want my page be multi language, and I think I've achieved what I want - content is multi language.
Problem I faced is to how to display translated pages in nav block according to language selected.
Currently all pages are displayed in nav block, but what I want is:
I select chinese got only items in chinese
I select german got only items in german
and so on, right now all items are shown, does not matter what language I select I see in nav block every 1 st lvl page.

 
ronyDdeveloper replied on at Permalink Best Answer Reply 2 Attachments
ronyDdeveloper
I hope you are using Internationalization add-on for multilingual. Now you need to setup different menus for different languages. Suppose you have 2 languages called Chinese & German. So you need to create 2 separate stacks called "Chinese Main Nav" & "German Main Nav".
Then in your theme header.php, you can add the below code:
<?php 
Loader::model('section', 'multilingual');
$c = Page::getCurrentPage();
$al = MultilingualSection::getBySectionOfSite($c);
$locale = ACTIVE_LOCALE;
if (is_object($al)) {
   $locale = $al->getLanguage();
}
?>


Then add the below code where you want to display your menu.
<?php
if($locale == 'ch'){
   $a = new GlobalArea('Chinese Main Nav');
   $a->display();
}
else if($locale == 'gr'){
   $a = new GlobalArea('German Main Nav');
   $a->display();
}
?>


Note: You may need to change the $locale (ch, gr) as per your requirement. Then you need to add autonav as like the attached image autonav.png settings. Also I'm attaching a sample sitemap for your reference.

Hope this helps.

Rony
4rek25 replied on at Permalink Reply
You've saved my day.
Thank you for help :)
ronyDdeveloper replied on at Permalink Reply
ronyDdeveloper
If it solves your problem, then please mark it as best answer so others can get help from it.
JoostRijneveld replied on at Permalink Reply
JoostRijneveld
Great answer!

My sitemap is identical to yours. I have two languages, and a single-level tree below it of, let's say, 8 pages. However, the result I am looking for is slightly different. I'd like to include the 8 sub-pages from the language in the menu, but also the actual language 'Homepage' (the ones you named 'Norwegian' and 'English'). This would mean I would have 9 menu items.

A dirty solution I could come up with is to create the homepage as a sub-page as well, and then automatically redirect the language page to that homepage.. but that does not seem to be the way it was intended to work.

How do you suggest I go about this?