Web Producer w/ Brilliance
Aquent
US-CA-San Rafael

Justtechjobs.com Post A Job | Post A Resume

Native Language Support
PHP is a great language for developing dynamic web sites. Some do it for fun while others for business. It is true that a great part of the web is in English. However, if you are targeting a worldwide audience, then neither English nor Esperanto alone is an option.
If you need to deliver content in several languages, it is a good idea to explore several alternatives. However, some alternatives may not be suitable for dynamic websites. Added to that, there is the overhead of time spent in maintenance. To further complicate things, your needs may not be totally in line with the resources you have at your disposal. Therefore, it is advisable to choose an alternative that suits you best.
I found myself in positions which required me to deliver content in both English and Spanish, and in one project a third language. Here are the possibilities I explored:
  • Explicit links for each language
  • Use Apache's mod_negotiation
  • Use GNU Gettext support in PHP
  • Write your own
This article gives a brief introduction to the first three possibilities, but then we will go about the fourth solution which suited the requirements best, given the set of constraints. I am assuming that the reader is at least familiar with PHP programming and the use of PHP classes.
Principles of content negotiation
Before we go into exploring the various options, we should understand the basics of content negotiation and how that applies to the development framework. Then, you will be able to develop a web application that can deliver its content in the language of choice of your visitor.
By simply configuring the web browser, the user can set it up in a way that his or her preferred language is used when available. Several languages can be specified in a prioritized list, by setting up the preferences or option of the browser.
And this list of preferred languages on every request made to the site. This action is totally transparent to the user, as the information gets sent in the Accept-Language header, for example:
Accept-Language:  bg, es, en-US, fr
Here our visitor has chosen Bulgarian, US English, Spanish and French in that order. Notice that you can even specify regional variants. The first two characters are a language code as specified in an ISO standard. This language code may be followed by a dash and a region code.
As an example, if the request arrives to a website whose content is entirely in Russian, then the list is exhausted and the visitor will get Russian text whether (s)he likes it or not. Now, assuming the website has both English and Spanish content (the 2nd and 3rd options), then the visitor will receive pages in Spanish. Why? Simply because here Spanish had higher priority with respect to English.
Sometimes, the web server itself can manage the content negotiation, if configured to do so. Otherwise, the request for a particular language is ignored. Alternatively, the application that delivers the content takes the decision of which language it is to use. This is exactly what we will do later.
Before going further, I would like to point out that the content negotiation is not just dealing with human languages. For example, it also negotiates the kind of information the client can take by means of MIME types, but that is beyond the scope of this article.
[ Next Page ]


Comments:
Gettext isn't easyDavid01/05/08 19:18
You are right ofcourse... But...Freeflashonlinegames Com 12/09/04 07:58
Accessing MSAccess database from PHTMLPrasanna Phadke10/20/02 14:50
RE: NativeLanguageSupportx-eniac10/01/02 04:29
RE: multi-langual dynamic site,HOW?x-eniac10/01/02 04:24
installingIllona04/26/02 12:19
PHP problem with "Ñ" in databaseguarez04/14/02 23:36
real solutioncrimaniak04/08/02 09:48
RE: XML/XSLT solutionJoel Stobart03/04/02 06:53
basic Html code !!!gengosa, marcelo12/13/01 05:43
multi-langual dynamic site,HOW?MSsaint11/12/01 13:10
A simple methodAlok Sinha05/03/01 19:36
NativeLanguageSupportluc bredemus04/13/01 05:53
RE: Dynamic phrases...Ronan03/14/01 14:26
RE: Dynamic phrases...Abel Gonzalez Vidal03/07/01 20:28
RE: Dynamic phrases...Ronan03/06/01 05:44
RE: Download linkDidimo Grimaldo02/21/01 20:14
HoweverEdsko de Vries02/18/01 03:43
RE: XML/XSLT solutionEdsko de Vries02/18/01 03:41
StPhp is my choiceAbel González Vidal02/17/01 21:52
RE: XML/XSLT solutionSandro Zic02/17/01 10:10
RE: XML/XSLT solutionTomas V.V.Cox02/17/01 07:43
RE: XML/XSLT solutionEdsko de Vries02/16/01 02:55
RE: Dynamic phrases...David Garcia Watkins02/15/01 14:24
Sorry for the inconvenienceDidimo Grimaldo02/15/01 06:45
RE: XML/XSLT solutionDidimo Grimaldo02/15/01 06:43
RE: Download linkDidimo Grimaldo02/15/01 06:33
RE: phpLang does it and more !!!Didimo Grimaldo02/15/01 06:29
RE: Dynamic phrases...greggory02/15/01 00:38
Let the user regulate the content.Stephen VanDyke02/14/01 10:26
XML/XSLT solutionEdsko de Vries02/14/01 07:31
Dynamic phrases...Mike Norton02/14/01 07:12
phpLang does it and more !!!Nicolas Hoizey02/14/01 05:56
Missing textPaul K Egell-Johnsen02/14/01 05:29
And with dynamic lists ?Patrick Paysant02/14/01 03:18
Download linkPablo Costa02/14/01 02:54
PerformanceKirk Parker02/14/01 00:31
 

If you are looking for help, please post on the appropriate forum here. Your questions will be answered much more quickly.

Add A Comment:

Name:

Email:

Subject:

Message:

To reduce spam posts, messages are now manually approved

You are not [logged in]. That means your account will not get credit for this post.