You are here:  » Multi-lingual Site

Active Forum Topics

Multi-lingual Site

Submitted by support on Mon, 2015-10-19 09:32 in

Hi everyone,

I've had a couple of enquiries recently regarding using Price Tapestry for a multi-lingual site, so I thought I'd describe an easy way to set this up by using a language cookie to determine which version of translate.php to include. To set this up, first create multiple copies of includes/translate.php with the languages required, renamed with an appropriate _{code} suffix, for example:

(this can just be a copy of includes/translate.php from the distribution)

(French, German, Spanish, Italian and a "fill in the blanks" version are available to download)

With the required versions in place, now create a new includes/translate.php as follows:

["en"] = "English";
$translate_lang["fr"] = "Française";
$translate_langDefault "en";
  if (isset(
$lang $_POST["lang"];
    if (!isset(
$translate_lang[$lang])) $lang $translate_langDefault;
header("Location: ".$_SERVER["REQUEST_URI"]);
$lang = (isset($_COOKIE["lang"])?$_COOKIE["lang"]:"");
  if (!isset(
$translate_lang[$lang])) $lang $translate_langDefault;
"<form method='POST'>";
"<select name='lang' onChange='JavaScript:this.form.submit();'>";
$translate_lang as $k => $v)
$selected = ($lang==$k?"selected='selected'":"");
"<option value='".$k."' ".$selected.">".$v."</option>";
"<noscript><input type='submit' value='Change'></noscript>";

Edit the $translate_lang array at the top of the new file containing entries for each version of translate_{code}.php created, with the array keys matching {code} and the values being the label to display in the change language select box.

Finally, to display the form, edit your template (e.g. html/header.php or html/footer.php) and at the point you wish to display the change language form simply add the code:

<?php translate_form(); ?>

The form submission is picked up using isset($_POST["lang"]), and if TRUE a "lang" cookie is set using setcookie() with the value selected. The first entry in the $translate_lang acts as the default in the case of an invalid submission.


Submitted by Rocket32 on Mon, 2015-11-16 12:10

I tried the above by making my site multi-language, but when adding the codes a blank page comes up. Also is the form required for this to work? Can the language be auto detected and translate picks correct language if available? My in header.php reads language=en right now. Does this need changing?

Submitted by support on Tue, 2015-11-17 13:00


I've updated the above to use a different method of default selection - see line 4:

  $translate_langDefault = "en";

The previous method can cause problems on some versions of PHP, so if the default wasn't being selected correctly the require() would fail which is a fatal error so that might be what's happening here.

If you're still getting a blank page, add the following lines to the very top of the script after the opening <?php tag:


...and see if that reports the problem - let me know what is displayed (or if no difference) and Ill check it out further for you. Once up and running, let me know and I'll have a think about automatic selection - it would need to come from something in user context rather than the HTML source as that will be fixed - I'll have a look at what JavaScript system variables might be available to do this...


Submitted by Rocket32 on Wed, 2015-11-18 23:46

Still now success. I am getting the following error;

On Chrome Browser;

This webpage is not available


On Firefox Browser;

Content Encoding Error

The page you are trying to view cannot be shown because it uses an invalid or unsupported form of compression.

Please contact the website owners to inform them of this problem.

Submitted by support on Thu, 2015-11-19 08:36


Please could you email me your modified translate.php and each of the language versions you are using e.g. translate_en.php, translate_fr.php etc. and I'll try out your exact same files on my test server for you and see if I can spot the problem...


Submitted by smartprice24 on Thu, 2018-01-11 17:58

Hi David. In the last version PT, no swith language. Only default language work.

The dropdown select language, but no change.



Submitted by support on Fri, 2018-01-12 10:35

Hello Giuseppe,

I just doubled checked everything against the latest distribution and the language was selected and changed as expected so as above, if you could email me your modified translate.php and each of the language versions you are using e.g. translate_en.php, translate_fr.php etc. and I'll try out your exact same files on my test server...