?
Solved

Bilingual Site

Posted on 2011-05-11
6
Medium Priority
?
267 Views
Last Modified: 2012-06-21
I want to create a Spanish version of my site.  I have an idea how to do this but, being new to PHP, I thought I would see if perhaps I'm missing something, or there is a better way.

My thought is to drop the English version I have down into an English Folder and create a Spanish folder at the same level.

The site top index file will default and jump into the English folder. The user can switch languages, which will write a language cookie to his browser and use header() to switch to the other folder.

The top index file will look for a language cookie coming from the user and use it to jump into one folder or the other, so a user returning to the site will immediately see the language they selected the last time they visited the site.

That's it!

I know there are language packages that can express various phrases in multiple languages, but I want a complete translation of the site into Spanish - everything: testimonials, articles, image text - everything.

Thanks for any suggestions.

Steve
0
Comment
Question by:steva
  • 2
  • 2
  • 2
6 Comments
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 35738380
My thought is to drop the English version I have down into an English Folder and create a Spanish folder at the same level.

You're on exactly the right track there.  See these two examples:
http://php.net/manual/en/function.isset.php
http://php.net/manual/es/function.isset.php

You might consider getting a few extra eyes on the translations, or having a "report this" button on the translated pages.  That way you could be sure that you're getting the best quality translations!

Good luck with it, ~Ray
0
 
LVL 11

Accepted Solution

by:
Ovid Burke earned 1000 total points
ID: 35738969
You can also use the following to check the language of the HTTP request if there is one.

<?php
# redirect based on browser language
$lang = substr($_SERVER["HTTP_ACCEPT_LANGUAGE"], 0, 2);
switch($lang) {
	# spanish
	case "es":
		header("Location: /es/index");
	break;
	
	# english
	case "en":
	# default
	default:
		header("Location: /en/index");
	break;
}
exit;
?>

Open in new window

0
 

Author Comment

by:steva
ID: 35739521
Ray,

Thanks for the suggestion. Actually, the wife of my client comes from Argentina, so I think I can get a decent translation.

I looked at the php manual pages you referenced.  It would be interesting to see the change.php program that the form calls, but I guess  that's not possible.  

By the way, my White/Eisenhamer "PHP 5 in Practice" came in and you're right, I love it.


madaboutasp,

I wasn't aware of the HTTP_ACCEPT_LANGUAGE header.  It looks interesting, but how does it get set in the user's browser.  I see that it has q values for each language.  How would someone's browser get set, for example, to es,en;q=0.3?

0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 111

Assisted Solution

by:Ray Paseur
Ray Paseur earned 1000 total points
ID: 35740198
Here is the language change form.  GET method takes you to the root URL, http://php.net/manual/ plus the language and function URL.  Easy!
<div class="langchooser">
  <form action="/manual/change.php" method="get">
   <p>view this page in </p><fieldset><select name="page">
    <option value="pt_BR/function.isset.php">Brazilian Portuguese</option>
    <option value="zh/function.isset.php">Chinese (Simplified)</option>
    <option value="fr/function.isset.php">French</option>
    <option value="de/function.isset.php">German</option>
    <option value="ja/function.isset.php">Japanese</option>
    <option value="pl/function.isset.php">Polish</option>
    <option value="ro/function.isset.php">Romanian</option>
    <option value="fa/function.isset.php">Persian</option>
    <option value="es/function.isset.php">Spanish</option>
    <option value="tr/function.isset.php">Turkish</option>
    <option value="help-translate.php">Other</option>
   </select>
   <input type="image" src="http://static.php.net/www.php.net/images/small_submit.gif" id="changeLangImage" alt="Change language" />
  </fieldset></form>
 </div>

Open in new window

0
 
LVL 11

Expert Comment

by:Ovid Burke
ID: 35741624
It detects the users' browser/system languages and lists them in the same order as the users' settings. I would imagine that a user/browser/system will select at least one default language at setup or installation. I use this to initially determine which language to display. The user can still change the language by options on the site if they choose, and that part you might still need to manage with cookies.

In FF: Tools > Options > Content (Tab) > Languages
In IE: Tools > Internet Options > General (Tab) > Languages

I never bothered with q=0.3 etc, because the first two characters is sufficient for this purpose.

0
 

Author Closing Comment

by:steva
ID: 35741795
Thanks
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The title says it all. Writing any type of PHP Application or API code that provides high throughput, while under a heavy load, seems to be an arcane art form (Black Magic). This article aims to provide some general guidelines for producing this typ…
This holiday season, we’re giving away the gift of knowledge—tech knowledge, that is. Keep reading to see what hacks, tips, and trends we have wrapped and waiting for you under the tree.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

616 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question