Helping ordinary people create extraordinary websites!

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:
 1 Votes

You might also want to check these out:


Leave a Comment on "Internationalisation and my PHP Development Infrastructure"
You must be logged in to post a comment.

Link to This Tutorial Page!


GET OUR NEWSLETTERS