I recently installed a second language and when I logged into the admin interface it reported an error:
MISSING LANGUAGE FILES OR DIRECTORIES
My operating system is a windows 2003 server.
The zen cart is 1.3.9d
The error is referring to the missing language in the admin section, which does not exist. Further testing shows that it is not checking for the existence of the language in the includes/language folder at all.
So what its doing is reporting an error on something that isn't and not even checking what it's supposed to be.
The issue is two fold, you may multiple languages in your website but only one in the admin section to administer the site.
If you add a language and it does not exist in the admin section you should not get an error. On the other hand, if you do have it in both your web site and the admin interface, it should be checked to be sure both the file and directory exist.
The code at the top of admin/includes/header.php is where this disaster is all happening: This is the un-edited code exactly as it's being distributed.
This is, to say the least, a bit of a mess since its not doing any thing useful or correctly.PHP Code:// Show Languages Dropdown for convenience only if main filename and directory exists
if ((basename($PHP_SELF) != FILENAME_DEFINE_LANGUAGE . '.php') and (basename($PHP_SELF) != FILENAME_PRODUCTS_OPTIONS_NAME . '.php') and empty($action)) {
$languages = zen_get_languages();
if (sizeof($languages) > 1) {
$languages_array = array();
$languages_selected = $_GET['language'];
$missing_languages='';
for ($i = 0, $n = sizeof($languages); $i < $n; $i++) {
$test_directory= DIR_WS_LANGUAGES . $languages[$i]['directory'];
$test_file= DIR_WS_LANGUAGES . $languages[$i]['directory'] . '.php';
if ( file_exists($test_file) and file_exists($test_directory) ) {
$count++;
$languages_array[] = array('id' => $languages[$i]['code'],
'text' => $languages[$i]['name']);
// if ($languages[$i]['directory'] == $language) {
if ($languages[$i]['directory'] == $_SESSION['language']) {
$languages_selected = $languages[$i]['code'];
}
} else {
$missing_languages .= ' ' . ucfirst($languages[$i]['directory']) . ' ' . $languages[$i]['name'];
}
}
// if languages in table do not match valid languages show error message
if ($count != sizeof($languages)) {
$messageStack->add('MISSING LANGUAGE FILES OR DIRECTORIES ...' . $missing_languages,'caution');
}
$hide_languages= false;
} else {
$hide_languages= true;
} // more than one language
} else {
$hide_languages= true;
} // hide when other language dropdown is used
The correct way:
Once the languages listed in the db have been retrieved we need to check to see if the directory and file exists in the includes/languages directory, as these must exist.
While we're at it we can check to see it the same language is also being used in the admin section (but it doesn't have to be).
In the case of the website languages both the directory and file must exist or an error should be reported/generated.
If both parts do not exist in admin/includes/languages it should not be considered an error and ignored.
However, if one part exists, either the directory or the file, then it can or should be considered an error.
Here is how it can be done which addresses what I've been talking about.
In the admin interface, the select language option list will only be generated if there is more than 1 language in the admin section.PHP Code:// Check to see if each language directory and file exists.
// Create an Admin Languages Dropdown list of only those languages used by the admin interface.
$hide_languages= true; // first, initialize $hide_languages to get rid of all the crap in the else conditions that were at the end of this if statement
if ((basename($PHP_SELF) != FILENAME_DEFINE_LANGUAGE . '.php') and (basename($PHP_SELF) != FILENAME_PRODUCTS_OPTIONS_NAME . '.php') and empty($action)) {
$languages_array = array();
$languages = zen_get_languages();
if (sizeof($languages) > 1) {
$languages_selected = $_SESSION['language'];
$missing_languages=$missing_admin_languages='';
$count = 0;
for ($i = 0, $n = sizeof($languages); $i < $n; $i++) {
// Check for the catalog language directory and file
$test_directory= DIR_FS_CATALOG_LANGUAGES . $languages[$i]['directory'] ;
$test_file= DIR_FS_CATALOG_LANGUAGES . $languages[$i]['directory'] . '.php';
$isFile = file_exists($test_file);
$isDir = file_exists($test_directory);
if ( !$isFile || !$isDir ) {
if ( !$isFile && !$isDir ) { $missing_languages .= ' Missing directory: ' . $test_directory . ', and file: '. $test_file;}
else if ( !$isDir ) { $missing_languages .= ' Missing directory: ' . $test_directory;}
else { $missing_languages .= ' Missing file: ' . $test_file;}
}
// Check to see if this language is also being used by admin interface.
$test_directory= DIR_WS_LANGUAGES . $languages[$i]['directory'] ;
$test_file= DIR_WS_LANGUAGES . $languages[$i]['directory'] . '.php';
$isFile = file_exists($test_file);
$isDir = file_exists($test_directory);
if ( $isFile and $isDir ) {
$count++;
$languages_array[] = array('id' => $languages[$i]['code'], 'text' => $languages[$i]['name']);
if ($languages[$i]['directory'] == $_SESSION['language']) {
$languages_selected = $languages[$i]['code'];
}
} else if ( !$isFile and !$isDir ) { // When both parts are missing it just means this language does not exist in the admin section
continue;
} else {
if ( !$isDir ) { $missing_admin_languages .= ' Missing directory: ' . DIR_WS_ADMIN . $test_directory;}
else { $missing_admin_languages .= ' Missing file: ' . DIR_WS_ADMIN . $test_file;}
}
}
if ( $missing_admin_languages !== '') {
$messageStack->add('MISSING ADMIN LANGUAGE FILES OR DIRECTORIES ...' . $missing_admin_languages,'caution');
}
if ( $missing_languages !== '') {
$messageStack->add('MISSING CATALOG LANGUAGE FILES OR DIRECTORIES ...' . $missing_languages,'caution');
}
if($count > 1) $hide_languages = false;
}
}
And, it will only contain the languages in the admin/includes/langauges directory not all the languages listed in the database.
Well there you have it, do what you like with it.




