AutoNav + Internationalization Manual

Permalink 2 users found helpful
Hi,

I’m building new Multilingual Page with Concrete5 + Internationalization.

I have problem getting autonav to work with languages. Not sure why they skipped part how to install and setup Internationalization plugin on youtube videos. They just want to show us the benefit of concrete5 plugin without showing how tricky is to setup this plugin. Is that what they meant?

I've already searched whole forum and non of the solutions worked.

So my sitemap looks like this:

Home
-ENGLISH
--Page1
--Page2
-POLISH
--Page3
--Page4

On the front page I see only:

Select language: English | Polish (Flags)
ENGLISH | POLISH

If I open any page than both flags disappear.
If I edit AutoNav and select "Display Pages: at the second level" than AutoNav don’t show any Pages.


Can someone please help me how to configure SiteMap, Auto-Nav and "Switch Language".

I just like to see only one flag (If the current Page is in English why would I want to see English Flag). I'd like to see also links to all pages depending on language.

 
pigment replied on at Permalink Reply
pigment
wrong answer by me... it did not work at top level :(
Apos replied on at Permalink Best Answer Reply
Apos
Hello solver! When I started with concrete5 about two weeks ago, I had the same problem after watching the YouTube videos... Fortunately for me, I'm a developer (not for concrete5 though) so it was rather easy for me to find a solution. I'll try to make this as clear as possible.

In a nutshell, there are two steps to take in order to make this work:

1 ) The multilingual add-on has a function called "getLanguage()" and it does just as the name says, it returns the language currently used by the viewer. On my site, I use French and it returns "fr_FR".

2 ) The AutoNav add-on has the possibility to specify a root page, and list it's sub-pages in the navigation.

___


What I did then was to add the AutoNav add-on to my [theme / template]. You will have to decide for yourself where the following code will have to go:

$bt = BlockType::getByHandle('autonav');   
            $lh = Loader::helper('section', 'multilingual');
            if($lh->getLanguage() == "fr_FR")
            {
               $navPageRoot = Page::getByPath('/fr');
            }
            else if($lh->getLanguage() == "en_GB")
            {
               $navPageRoot = Page::getByPath('/en');
            }
            if ($navPageRoot->cID) {
               $bt->controller->displayPages = 'custom';
               $bt->controller->displayPagesCID = $navPageRoot->getCollectionID();
            } else {
               $bt->controller->displayPages = 'top';


The part where it says "getByPath('/fr')" and "getByPath('/en')" is the url of the root page for both French and English respectively.

The last line "render('templates/header_menu_dropdown');" was used because I found a bug in the AutoNav add-on. (And also because it gave more flexibility to the theme I was using.) Let me explain:

When doing it this way, you end up excluding the home page from the navigation. To add it back, you need to "Add External Link" to point back to the home page. (Add it as a sub-page of itself.) The problem was that AutoNav would not show the home page as selected in the navigation when viewing it.

Here is the code for header_menu_dropdown.php:
<?php  
   defined('C5_EXECUTE') or die("Access Denied.");
   $aBlocks = $controller->generateNav();
   $c = Page::getCurrentPage();
   $containsPages = false;
   $nh = Loader::helper('navigation');
   //this will create an array of parent cIDs 
   $inspectC=$c;
   $selectedPathCIDs=array( $inspectC->getCollectionID() );
   $parentCIDnotZero=true;   
   while($parentCIDnotZero){
      $cParentID=$inspectC->cParentID;
      if(!intval($cParentID)){
         $parentCIDnotZero=false;
      }else{


This file can be placed inside "Your_Theme_Root_Directory/blocks/autonav/templates/header_menu_dropdown.php"

Hopefully you have managed to follow me up to this point. :D

Question for other developers: Is there an API function call that can return the root page for the currently selected language? If there is one, I would be able to use it so that I don't have to hard code it like I did above.

Sorry if this became confusing. If need be, I can explain some parts with more details.
grapplepie replied on at Permalink Reply
@Apos, First of all thank you very much for your solution. Great work!

I'm using your header_menu_dropdown.php but unfortunately the 'external link' for the home page is still not shown as active. I just copy pasted your code, so where could the issue be? Rest is working fine...

Would appreciate your help a lot :)
Apos replied on at Permalink Reply
Apos
Glad to hear my solution partially worked.

The error lies in this line of code:
elseif ($c->getCollectionID() == Page::getByPath(str_replace("http://".$_SERVER['HTTP_HOST'].DIR_REL, "", $_c->getCollectionPointerExternalLink()))->getCollectionID())


Can you add these lines of code:
echo "Current page ID: " . $c->getCollectionID() . "\n";
echo "Full URL: " . $_c->getCollectionPointerExternalLink() . "\n";
echo "Partial URL: " . "http://" . $_SERVER['HTTP_HOST'] . DIR_REL . "\n";
echo "External URL ID: " . Page::getByPath(str_replace("http://".$_SERVER['HTTP_HOST'].DIR_REL, "", $_c->getCollectionPointerExternalLink()))->getCollectionID() . "\n";


right after the line:
$lastLevel = $thisLevel;


It should tell you a bit more information about what is going on. It will print those debugging strings right under your navigation.
mongo replied on at Permalink Reply
Question for other developers: Is there an API function call that can return the root page for the currently selected language? If there is one, I would be able to use it so that I don't have to hard code it like I did above.


Would also like to know abt this. Have the same issue as one of the posters. How to get the pseudo *home page* to show as active.

I guess these issues will be resolved in the next version of the Internationalization add on.

If this is so would be nice to get word of this from the developers ....
PatrickHeck replied on at Permalink Reply
PatrickHeck
This is what I use:
<?php $home = DIR_REL;
   if( $multilingual = Package::getByHandle('multilingual') ) {
      $ms = MultilingualSection::getCurrentSection();
      if (is_object($ms)) {
         $home = Loader::helper('navigation')->getLinkToCollection($ms, true);
}
}?>
<a href="<?= $home ?>">Home</a>
aitalmac replied on at Permalink Reply
If i just want autonav to add second level with the home, where should i add this code???
aitalmac replied on at Permalink Reply
where did you add this code?
I'm really new to concrete, could you explain me how to get home working properly?
aitalmac replied on at Permalink Reply
where did you put this code?

i'm new to PHP and concrete could you explain how to have this work properly?

Sorry first post, i saw loading but never finished, didn't realized i posted 3 times xD
mongo replied on at Permalink Reply
Hi, could you please explain where you use this code.

Thanks
PatrickHeck replied on at Permalink Reply
PatrickHeck
The code goes inside your theme. e.g. /themes/mytheme/default.php
You might want to drop your logo inside the link in the last line.
msfromg replied on at Permalink Reply
Hello everyone-

I'm quite new to C5, don't know about coding, and have been trying all day to get the internationalization add on to work with my navigation (within Slate-theme, if that's important).

I did it pretty much like Solver did and like it was explained in the video:

Home
-EnglishHome
---Page 1
---Page 2
-DutchHome
---Page 1
---Page 2
-GermanHome
---Page 1
---Page 2

For the navigation, I want to appear

EnglishHome | Page 1 | Page 2

on the first level. If I switch via SwitchLanguage to e.g. Dutch I want

DutchHome | Page 1 | Page 2

to be on the first level.

Could anyone help me which parameters I need to put for the AutoNav and what I need to put for the Sitemap (e.g. what to exclude)? There must be an solution without coding to this basic problem?
pvernaglia replied on at Permalink Reply 1 Attachment
pvernaglia
Try this autonav template, put it in blocks/autonav/templates and select it as the custom template
mongo replied on at Permalink Reply
Hi!

Thanks your attachement works perfectly, accept for one thing.

The site I am developing is not on the ROOT, so the URL that is parsed is incorrect.

What do I need to change so that this is fixed ?

I.e

my root is C5

Currently when the 'homepage' link is clicked is goes to

www.www.domain.com/home-english...

instead of

www.www.domain.com/c5/home-english...

The other links all work correctly.

Thanks
mongo replied on at Permalink Reply
Nobody can help with this ??
mongo replied on at Permalink Reply
Lines 58 and 60 I simply hard coded
/c5
after
href="
Maddalina replied on at Permalink Reply
Maddalina
[quote]Try this autonav template, put it in blocks/autonav/templates and select it as the custom template[/quote]

I have the same problem, but I'm not a developer, so thank you very much for the template, I've put in the correct folder, but where can I select it as custom template?
mhawke replied on at Permalink Reply
mhawke
I'm not sure how your specific AutoNav block has been added to your page. If it's been added as an editable block then put your page in edit mode and click on the AutoNav block. Instead of choosing 'Edit', choose 'Custom Template'. A new dialogue window should open where you can pick 'Include Parent' from the drop-down list.
Maddalina replied on at Permalink Reply
Maddalina
Hi mhawke,

that's the problem, even I'm the owner and administrator, the block is non editable in the c5, neither in the theme (slate).
Maddalina replied on at Permalink Reply
Maddalina
sorry for the multi-posting!
Maddalina replied on at Permalink Reply
Maddalina
sorry for the multi-posting!
ite replied on at Permalink Reply
Apos

where i must put this code:

<?php
$bt = BlockType::getByHandle('autonav');

$lh = Loader::helper('section', 'multilingual');

if($lh->getLanguage() == "pl_PL")
{
$navPageRoot = Page::getByPath('/pl');
}
else if($lh->getLanguage() == "en_GB")
{
$navPageRoot = Page::getByPath('/en');
}
if ($navPageRoot->cID) {

$bt->controller->displayPages = 'custom';
$bt->controller->displayPagesCID = $navPageRoot->getCollectionID();
} else {
$bt->controller->displayPages = 'top';
}

$bt->controller->orderBy = 'display_asc';
$bt->controller->displaySubPages = 'all';
$bt->controller->displaySubPageLevels = 'custom';
$bt->controller->displaySubPageLevelsNum = '3';
$bt->render('templates/header_menu_dropdown');

?>

I copy to /themes/test/elements/heather.php
Select type header_menu_dropdown and nothing. AutoNav shows eng and pol sites.