Forum

Thread tagged as: Question, Add-on-development

Re use pages for other languages

Hi, Right now if I set ".$lang" to my php pages and visit the website with different language (I have 8 dif languages) I automatic creates the different regions for each language for this particular page. The think is that for some regions I want to use the same content for all the languages(for example images). Right now I have to go inside each region for every language and set the content. Is there any way or do you think of any way where I can use again content from one region to create content for another region? For example if I have a page with an region in english and I want to use this specific region also the the german language. Any ideas?

Lukasz Biegus

Lukasz Biegus 0 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

You could do something like:

if ($lang == 'de') {
    $lang = 'en';
}

Yes but by doing this it will change the language for all the website, not just for that specific region. For example I have the English version of a page which has 3 regions Text-Header(in English) Image Text-Paragraph(in English)

and the chinese version of a page Text-Header(in Chinese) Image Text-Paragraph(in Chinese)

Is it possible for the image section which is common for both languages to have it only once, so I dont have to go inside each language page and modify it?

I have figure ut out Drew thanks for the idea.

I have my php page which calls a region (for example "test - Experience Section"). <?php if ($lang == 'de_DE') { $lang = 'en_UK'; perch_content('test - Experience Section - '.$lang); $lang = 'de_DE'; } else{ perch_content('test - Experience Section - '.$lang); } ?>

I have hard code the "if" so if the language is DE it will be converted to UK. What I am searching to do, is to give the option to the user to select from the backend, for which languages he wants this region to be displayed. I have tried couple of things but nothing worked.

Any ideas?

Drew McLellan

Drew McLellan 2638 points
Perch Support

No, I don't have a suggestion for that.

Thanks Drew I will do some research I will let you know if I find a way

Right now I have my page (for example test.php) that calls and use html templates. Can you suggest a way of passing with "PerchSystem" variables from the html templates to the php page?

Drew McLellan

Drew McLellan 2638 points
Perch Support

Can you give an example?

Right now I have a master template with "perch_content('test - content Section - '.$lang); " So when the user visit the page that use this template with en language selected, perch creates region for en if the user visit the page with chinese language selected, perch creates region for chinese. Now if the admin user has not enter any content for chinese then the page will be displayed blank when chinese language selected. What I am trying to do is either the admin user can select for which language the content region of the page will be the same as english. Or if the region of the page does not have any content then english region will be displayed instead. So if chinese region does not have any content then the english region can be displayed instead

Drew McLellan

Drew McLellan 2638 points
Perch Support

You need to output the result of the region to a variable. If it's empty, then output the English version. If not, echo the variable.

You mean something like: check if type == NEW if yes echo English content Else echo content?

How can I do that? Can you provide some instructions? Right now as I told before I create the region with: "perch_content('test - content Section - '.$lang);"

What I did is: inside my page.php

$regionname = 'test -  ';

$thecontent = perch_content($regionname.$lang, true); 
if (strpos($thecontent,"Undefined content") !== false) {
    echo "now";
    perch_content($regionname.'en_UK'); 
}
else{
    echo $thecontent; 
}

I am facing a very strange issue. The first time I visit the region with chinese language, it does not display the english content, but if I refresh it does.

I viewed the source code for the 2 states (before after refresh action) and it is Exactly the same.

Drew McLellan

Drew McLellan 2638 points
Perch Support

The very first time the region is created. On subsequent visits it already exists.

I have modified my if statement and it works if (!isset($thecontent) || empty($thecontent) || strpos($thecontent, 'Undefined' ) !== false) {