Helping ordinary people create extraordinary websites!
GET OUR NEWSLETTER
Your Email:
 

Internationalisation and my PHP Development Infrastructure

By Tony Marston
2005-07-17


My Implementation - Determine User Language

The first step is determine the user's language as provided by the client browser (user agent) in the $_SERVER["HTTP_ACCEPT_LANGUAGE"] variable. For this I am using the User Agent Language Detection script provided by http://techpatterns.com/. The code I use is as follows:

if (!isset($_SESSION['user_language_array'])) {

// get language codes from HTTP header
require 'language_detection.inc';
$_SESSION['user_language_array'] = get_languages();
} // if

This returns an array of entries, one for each of the languages that the user may have set in his/her browser. Each language entry is another array of 4 entries as follows:

  1. Full language abbreviation, such as: 'en-gb' or 'en-us'
  2. Primary language, such as: 'en'
  3. Full language string, such as: 'English (United Kingdom)' or 'English (United States)'
  4. Primary language string, such as: 'English'

When looking for the subdirectory containing the language text file the array of language codes provided by the User Agent (client browser) will be examined first to last. If no subdirectory exists with the same name as the language subtype (such as 'en-us' or 'fr-ca') the software will look for a subdirectory with the same name as the primary language (such as 'en' or 'fr'). If nothing can be found for the first entry in the User Agent array the software will move on to the next entry.

If no subdirectory is found for any entry in the User Agent array the software will drop back to the installation's default language. In my sample application this is hard coded as 'en', but in my full development environment this is configurable using the Update Control Data screen.

Within my full development environment it is also possible for each user to define his/her preferred language code in the Update User screen. This overrides both the User Agent array and the installation default language.



Tutorial Pages:
» Introduction
» Possible Methods
» Design Decisions
» My Implementation - Directory Structure
» My Implementation - File Names
» My Implementation - Determine User Language
» My Implementation - Locate Language Subdirectory
» My Implementation - Load Screen Structure file
» My Implementation - Get Language Text
» My Implementation - Get Language Array
» My Implementation - Handling Dates
» My Implementation - Handling Numbers
» Conclusion
» References


 | Bookmark
Related Tutorials:
» Port Scanning and Service Status Checking in PHP
» Web Database Access from Desktop Applications
» CubeCart 3.0 Installation and Configuration
» PHP Site Search Made Easy
» Installing and Configuring Drupal 6.1
» Desktop Application Development with PHP-GTK

Advertise with Us!


Tutorials Scripts Web Hosting Developer Manuals
Resources