|
Helping ordinary people create extraordinary websites! |
Internationalisation and my PHP Development InfrastructureBy Tony Marston2005-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'])) { 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:
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 |
|