Forum

Thread tagged as: Question

perch navigation with multi language

I am using strategy two from this page https://solutions.grabaperch.com/architecture/how-do-i-create-a-multilingual-site

But I am not sure when user has switched to Spanish language, how do I show nav text from spanish?

My navigation remains same, I need to switch language and title to the language selected

sawan ruparel

sawan ruparel 0 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Have you added a Spanish title to the page attributes?

I have added below in default.html above seo.html

<perch:pages id="nav-es" label="Spanish Navigation text" type="text" escape="true" />
<perch:pages id="title-es" label="Spanish Page title" type="text" escape="true" />

<perch:pages id="nav-de" label="Deutsch Navigation text" type="text" escape="true" />
<perch:pages id="title-de" label="Deutsch Page title" type="text" escape="true" />

<perch:pages id="nav-hr" label="Hrvatski Navigation text" type="text" escape="true" />
<perch:pages id="title-hr" label="Hrvatski Page title" type="text" escape="true" />

<perch:pages id="nav-tr" label="Türk Navigation text" type="text" escape="true" />
<perch:pages id="title-tr" label="Türk Page title" type="text" escape="true" />
Drew McLellan

Drew McLellan 2638 points
Perch Support

Ok. Are you then using those in your Spanish navigation template?

How do I do that. My navigation template on global/nav.php looks like below:

<?php
  perch_pages_navigation(array(
        'flat'                 => false,
        'template' => array('level1.html', 'level2.html'),
        'include-parent'       => false,
        'skip-template'        => false,
        'siblings'             => false,
        'only-expand-selected' => false,
        'add-trailing-slash'   => false,
        'navgroup'             => false,
        'include-hidden'       => false,
    ));

  ?>
Drew McLellan

Drew McLellan 2638 points
Perch Support

Where you have this:

'template' => array('level1.html', 'level2.html'),

switch it out for templates that use the Spanish fields when you want to show Spanish navigation.

'template' => array('level1_es.html', 'level2_es.html'),

(y) got it..

how about page title, how can i switch them as well?

Drew McLellan

Drew McLellan 2638 points
Perch Support

Yes, you'd do the same thing for the page title - just switch the template.

I am not sure how I can switch for title, my title in global/header.php file looks like this

<title><?php perch_pages_title(); ?></title>

here is how i am calling global/header from pages files

perch_layout('global/header', [
        'body-class' => 'home',
    ]);
Drew McLellan

Drew McLellan 2638 points
Perch Support

For your default language, use perch_pages_title() and then when you want a different language use e.g.

perch_page_attribute('title_es');