[All-OS, Web sites] Internationalizing Web sites
PRODUCT: PHP All versions Web browsers
OP/SYS: All operating systems
COMPONENT: HTTP_USER_AGENT environment variable HTTP_ACCEPT_LANGUAGE environment variable
SOURCE: Philippe Vouters Fontainebleau/France
HIGH QUALITY MOBILES+TABLETS: http://android-land.fr
OVERVIEW: This article highlights a way to internationalize Web pages or Web sites. The main idea is to redirect the remote Web browser to a Web page according to the Web browser's configured or accepted language. The browser's configured language is often set by some Web browsers such as Firefox, Opera, Chrome or Safari in the HTTP_USER_AGENT environment variable. The browser's accepted languages is set by all graphical Web browsers in the HTTP_ACCEPT_LANGUAGE environment variable. It should be noted that both Konqueror and Internet Explorer do not give any clue as to what is the language they are configured in.
*** CAUTION *** This sample PHP script has been tested using PHP Version 5.2.9 on Linux Fedora 11. However, we cannot guarantee its effectiveness because of the possibility of error in transmitting or implementing it. It is meant to be used as a template for writing your own script, and may require modification for use on your system.
ACTUAL INTERNATIONAL WEB SITES: Consider the internationalization aspect of three Web sites and how they solved it: First http://www.uefa.com/ : --------------------------- The national language is selectable in the upper right screen of the browser window. Next http://www.google.com/ : ---------------------------- Using Wireshark to trace traffic on port 80 and Opera (English version) under Windows XP SP3, whichever the way you set your only preferred language, either French or English, meanwhile having first deleted any Google's cookies immediately redirects you to http://www.google.fr/ when http://www.google.com/ is activated from France. Only selecting Russian as the preferred language, no Web site redirection occurs (you stay on http://www.google.com/) and the Russian's speaking Web page mentions Google France when the URL is activated from France. So a first approach is that this technique appears to use a geographical localisation based upon the Internet IP address. However, things are more complicated as there is also a tradeoff based upon the Opera's preferred languages. If you only set English as the preferred language without any other idiom, from France you are redirected to http://www.google.fr/ and a French speaking page. If you add French as the second language and always deleting any Google's cookie, requesting http://www.google.com/, you are redirected to http://www.google.fr/ and an English speaking page. If you add Russian, move it up on top of the preferred languages, always deleting any Google's cookies and with http://www.google.com/ in the address bar, you are no longer redirected to http://www.google.fr/ (you stay on http://www.google.com/) and the page displays in Russian. Apparent conclusion for Google: a mixture of HTTP_ACCEPT_LANGUAGE environment variable handling and geographical localization. Last http://www.hp.com/ : ------------------------ Using exclusively Opera (English version) under Windows XP SP3, first delete any HP's cookies (Tools->Preferences - Advanced Tab - Cookies - Manage Cookies button). Depending on whether you set the first preferred language in the list to French or English, you are automatically redirected to a French speaking page or an English speaking page. Not deleting the English stored HP's cookies and moving up back to French as the first preferred language leads you to a "Sorry, we can't find that page" HP's response. Using Wireshark and tracing network traffic on port 80 shows that opening http://www.hp.com/ highlights the preferred language in the browser's network sent "Accept-Language" information which can be retrieved in the HTTP_ACCEPT_LANGUAGE environment variable information (without Wireshark, activate /cgi-bin/printenv to check). Apparent conclusion for HP site: This Web site ought to rely upon two informations : the information contained in HTTP_ACCEPT_LANGUAGE environment variable combined with the content of its cookies.
ALTERNATIVE TO MANUAL TRANSLATION: Another approach to multi-language Web sites would be to use the following new PHP class: Name: PHP Website Multi Language Author: Sandeep Kumar Description: This class can be used to translate application texts using Google Translate. It can take a script with an array of texts in English and sends requests to the Google Translate Web site to translate each of the texts to another idiom. The class generates a new script for the target language with an array with the texts translated to that language. URL: http://www.phpclasses.org/browse/package/5766.html Support forum: http://www.phpclasses.org/discuss/package/5766/
SOME NOTES ABOUT AUTOMATIC TRANSLATIONS: Automatic translation of Web content by tools such as offered by Google or any other Web site offering such a service has a real drawback. The translation can be approximate, sometimes leading to confusions for the reader. According to the author, an automatic translation ought to not yet be used by commercial sites. As an example of the statement contained in the above paragraph and for those well knowing English and another language, read the English version of http://www.fedoraforum.org/ and its automatic translation by Google. You will get Google's translation by clicking on the non-English language found at the bottom of this Web page. More information on computer assisted translations can be found at the following link : http://en.wikipedia.org/wiki/Computer-assisted_translation