Forum

Thread tagged as: Question, Problem, Forum

How to get perch_pages_navigation to output bi-lingual navigation

I am retro-fitting a website using Perch. So far its going great and I have included a Mandarin language option by following your tutorial @ https://solutions.grabaperch.com/architecture/how-do-i-create-a-multilingual-site

I have run into an issue when perch generates subpages and outputs the sub-nav.

I can get the desired effect in the admin (I.e English / Chinese specific regions) but I cannot get it output the sub-nav. It defaults back to the top level navigation.

I am not really familiar with php. This is the code I'm using in the page template:

<div class="sub-panel-content">
<?php 
    perch_pages_navigation(array(
        'levels'    => 1,
        'from-path' => '/staff'.$lang,
    ));
?>
</div>

site url : peregrine.rljr.im

Can you advise?

Jon Douglas-Beveridge

Jon Douglas-Beveridge 0 points

  • 7 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

With this:

'from-path' => '/staff'.$lang,

that suggests the parent page has a path something like /staffen - is that correct?

Hi Drew,

No. When I click on the link - it goes to /staff/index.php

?lang=en / ?lang=ch does not get appended to the URL(s) - which is the desired result

/staff - is where the subpages are generated by perch.

Another way to ask my question is "how do I get perch_pages_navigation to recognise and output both language options?"

Drew McLellan

Drew McLellan 2638 points
Perch Support

So I think this:

'from-path' => '/staff'.$lang, 

should be

'from-path' => '/staff',

Yes, I've made that amend and I am getting the respective languages now. Thanks.

I think my issue is when I create a sub-page in perch.

Obviously it only creates 1 page not 2. So the navigation is in the language you used (ie. English). This is then used by perch_pages_navigation to generate the sub-nav for '/staff'.

This mean that the Staff Member links will always show in English, even on the Manderin versions.

I suppose I need a way of feeding in the Manderin translation of the page title into the sub-nav's links, so it at least appears to the user in the correct language.

Do you think this is possible?

https://peregrine.rljr.im/staff/?lang=en

Drew McLellan

Drew McLellan 2638 points
Perch Support

If you add the translation into the page attributes, this can be output in the navigation.

https://docs.grabaperch.com/docs/pages/page-attributes/

Sorry to be a pain in the a*se -

I followed the second strategy on the https://solutions.grabaperch.com/architecture/how-do-i-create-a-multilingual-site tutotial.

So I have a single page that outputs alternate regions based on the language choice.

I don't get how to output alternate page titles (1 english / 1 manderin) using the <perch:pages /> tags in an attributes template, that then get picked up by perch_navigation_pages as the nav links.

Can you elaborate a bit more?

Drew McLellan

Drew McLellan 2638 points
Perch Support

  1. Create an attribute template with a field for each translated title
  2. Use PerchSystem::set_var() to pass the lang option into the nav templates
  3. Output the field you need based on the lang using perch:if