Helping ordinary people create extraordinary websites!
HOME TUTORIALS SCRIPTS WEB HOSTING BLOG FORUM
Get Our Newsletter
Email:

Internationalisation and my PHP Development Infrastructure

By Tony Marston
2005-07-17


My Implementation - Locate Language Subdirectory

Before loading the contents of a particular file it is first necessary to locate a valid subdirectory. This is done with the following function:

function getLanguageSubDir ($path)

// get subdirectory which corresponds with user's language code.
{
// build an array of subdirectory names for specified $path
$found = array();
if (is_dir($path)) {
$dir = dir($path);
while (false !== ($entry = $dir->read())) {
if ($entry == '.' or $entry == '..') {
// ignore
} else {
if (is_dir("$path/$entry")) {
$found[] = $entry;
} // if
} // if
} // if
$dir->close();
} // if

if (!empty($found)) {
if (isset($_SESSION['user_language_array']))) {
// scan $user_language_array looking for a matching entry
foreach ($_SESSION['user_language_array'] as $language) {
// look for language subtype
if (in_array($language[0], $found)) {
return "$path/$language[0]";
} // if
// look for primary language
if (in_array($language[1], $found)) {
return "$path/$language[1]";
} // if
} // foreach
} // if
} // if

// no language specified, so default to English
return $path .'/en';

} // getLanguageSubDir

Note here that as an absolute minimum there MUST be a subdirectory for the default language, and this subdirectory MUST contain a full set of the expected files.



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:
» Zend Framework Tutorial
» 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