Forum

Thread tagged as: Question, Problem, Suggestions

Implementing a Language Selector

I am following this guide - https://solutions.grabaperch.com/architecture/how-do-i-create-a-multilingual-site and choosing to go down the route of Strategy two to create French regions within the site but I am getting confused about its installtion.

  1. So I started off by making an include file with this PHP code and including it on the page:
<?php
session_start();
if (isset($_GET['lang']) && $_GET['lang']!='') {
    $lang = $_GET['lang'];
    $_SESSION['lang'] = $lang;
}elseif (isset($_SESSION['lang'])){
    $lang = $_SESSION['lang'];
}else{
    // default language
    $lang = 'en';
}
?>
  1. Then I created two separate regions on the page:
<?php perch_content('Main content - '.$lang); ?>
<?php perch_content('Main content - '.$lang='fr'); ?>
  1. Logged into Perch and filled in both regions with relevant content.

My problem is that when viewing the page the regions seem to duplicate themselves:

I did consider Strategy one for this website although wouldn't you have to have two separate Perch websites running on two different databases? There editing content would be a pain in the bum.

As I have little experience with PHP I am struggling. Can anyone advise me on a solution?

Samuel Marchant

Samuel Marchant 0 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

You don't need both of these:

<?php perch_content('Main content - '.$lang); ?>
<?php perch_content('Main content - '.$lang='fr'); ?>

the whole point is that it's dynamic. Use this instead:

<?php perch_content('Main content - '.$lang); ?>

Thanks Drew, I knew it was something small.