Multilanguage support

7 posts by 3 authors in: Forums > CMS Builder
Last Post: December 7, 2010   (RSS)

Re: [Dan Maitland] Multilanguage support

By Chris - December 1, 2010 - edited: December 1, 2010

Hi Dan,

Can you not have a link on your English page like this:

<a href="proprietes.php">Voir cette page en Français</a>

...and a link on your French page like this:

<a href="properties.php">View this page in English</a>

Would that work? If not, why not?
All the best,
Chris

Re: [chris] Multilanguage support

By DanMaitland - December 2, 2010

The link to each of the different languages are includes in the header and we would like a way to dynamically switch without having to hard code the link.

i.e. if you are on one of the properties in french and you click the English link at the top it will bring you to the french version of that property.

Re: [Dan Maitland] Multilanguage support

By Jason - December 3, 2010

Hi,

Could you attach a copy of your header file so we can see the code you're using. We can then give you a more specific example of how you can do this.

Thanks.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Multilanguage support

By DanMaitland - December 5, 2010

I'm not to sure what you are expecting to see in this file but here it is.
Attachments:

header.php 1K

Re: [Dan Maitland] Multilanguage support

By Jason - December 6, 2010

Hi,

It looks like you're using one header if it's an English Page and one header if it's a French page. Is that right?

If so, what you can do is set up an array of file names in your header file, using the file name of one language as an index and the file name of the other language as the value.

For example, here is an array you could put in your English Header using English names as an index and French names as a value:

NOTE, this is only an example and won't include all file name you'll need on your site.

//create English to French array
$englishToFrench = array();
$englishToFrench['home.php']="index.php";
$englishToFrench['properties.php']="proprietes.php";
$englishToFrench['about.php']="a-propos-de-gold-castle.php";
$englishToFrench['contact.php']="contactez-nous.php";
$englishToFrench['property.php']="proprietie.php";


Next we need to get the name of the current PHP file being displayed:
//get current file name.
$path = explode("/",$_SERVER['SCRIPT_NAME']);
$fileName = trim($path[count($path)-1]);


Now we can use the current file name to get the french equivalent. (If it's not there, we'll default to the home page.)
if(!@$englishToFrench[$fileName]){
$link="index.php";
}
else{
$link = $englishToFrench[$fileName];
}


Finally, we can add any url variables to the link string if they exist.

/add url variables
$urlString = "";
foreach($_REQUEST as $key=>$value){
if($urlString){
$urlString.="&$key=$value";
}
else{
$urlString="$key=$value";
}
}

if($urlString){
$link.="?$urlString";
}


All we have to do now is use $link in our <a> tag:

<a href="<?php echo $link;?>">Français</a>

Give this a try, it should get you started.

Hope this helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Multilanguage support

By DanMaitland - December 7, 2010

Jason,
You are a GOD!!! It works like a freakn charm. I can't thank you enough. Thank you, thank you, thank you!