From: Lo?c C. <lo...@us...> - 2001-04-03 20:17:43
|
Update of /cvsroot/phpmychat/phpMyChat-0.15/chat/localization In directory usw-pr-cvs1:/tmp/cvs-serv6312/chat/localization Added Files: sort_languages.lib.php3 tutorial.lib.php3 Log Message: The first dev. version that works! Still many things to do, of course... --- NEW FILE --- <?php // // +--------------------------------------------------------------------------+ // | phpMyChat version 0.15.0 | // +--------------------------------------------------------------------------+ // | Copyright (c) 2000-2001 The phpHeaven-team | // +--------------------------------------------------------------------------+ // | This library sorts an array by keys in reverse order. It is used for | // | releases of PHP older than 3.0.15. | // | | // | This file is called by the 'chat/localization/languages.lib.php3', | // | the 'chat/localization/admin.lib.php3' and the | // | 'chat/localization/tutorial.lib.php3' scripts. | // +--------------------------------------------------------------------------+ // | From the phpMyChat project: | // | http://www.phpheaven.net/projects/phpMyChat/ | // | | // | Authors: the phpHeaven-team <php...@ya...> | // +--------------------------------------------------------------------------+ // // $Id: sort_languages.lib.php3,v 1.1 2001/04/03 20:17:39 loic1 Exp $ // // Library that sorts an array by keys in reverse order. // /** * Compares values of keys and sorts them * * @param array the array to be sorted * @param mixed a required parameter * * @return the sorted array * * @access private */ function pmcKeyComp(&$a, $b) { return - (strcmp($a,$b)); } // end of the 'pmcKeyComp()' function /** * emulates the krsort() function of PHP 3.0.16+ * * @param $toSort the array to be sorted * * @access public */ function krsort(&$toSort) { uksort($toSort, 'pmcKeyComp'); } // end of the 'krsort()' function ?> --- NEW FILE --- <?php // // +--------------------------------------------------------------------------+ // | phpMyChat version 0.15.0 | // +--------------------------------------------------------------------------+ // | Copyright (c) 2000-2001 The phpHeaven-team | // +--------------------------------------------------------------------------+ // | This library defines the language that will be used for the tutorial. | // | If there is no language already defined (neither in a cookie, neither | // | from a variable sent in the query part of the url) it will try to get | // | the most probable language the user would like to use thanks to some | // | environment variables. | // | | // | This file is called by the 'chat/tutorial_popup.php3' script. | // +--------------------------------------------------------------------------+ // | From the phpMyChat project: | // | http://www.phpheaven.net/projects/phpMyChat/ | // | | // | Authors: the phpHeaven-team <php...@ya...> | // +--------------------------------------------------------------------------+ // // $Id: tutorial.lib.php3,v 1.1 2001/04/03 20:17:39 loic1 Exp $ // // Defines the language to be used for the tutorial. // /** * Analyzes some PHP environment variables to find the most probable language * that should be used * * @param string string to analyze * @param integer type of the PHP environment variable which value is $str * * @global array the list of available translations * @global string the translation to use * * @access private */ function pmcTutorialDetect($str = '', $envType = '') { global $availableTutorials; global $lang; $notFound = true; reset($availableTutorials); while ($notFound && list($key, $name) = each($availableTutorials)) { // $envType = 1 for the 'HTTP_ACCEPT_LANGUAGE' environment variable, // 2 for the 'HTTP_USER_AGENT' one if ( ($envType == 1 && eregi('^' . $key . '$', $str)) || ($envType == 2 && eregi('(\(|\[|;[[:space:]])' . $key . '(;|\]|\))', $str))) { $lang = $availableTutorials[$key]; $notFound = false; } } } // end of the 'pmcTutorialDetect()' function /** * Creates the array containing available languages */ // Defines available languages $availableTutorials = array(); $languageDirectories = dir('./localization/'); while ($name = $languageDirectories->read()) { if (is_dir('./localization/' . $name) && file_exists('./localization/' . $name . '/localized.tutorial.' . C_EXTENSION)) { list($key) = file('./localization/' . $name . '/regex.txt'); $availableTutorials[$key] = $name; } } $languageDirectories->close(); // Sorts the $availableTutorials array in a convenient order if (!function_exists('krsort')) include('./localization/sort_languages.lib.' . C_EXTENSION); krsort($availableTutorials); /** * Get some predefined variables */ if (isset($HTTP_COOKIE_VARS['cookieLang'])) $cookieLang = $HTTP_COOKIE_VARS['cookieLang']; pmcGrabGlobals('HTTP_ACCEPT_LANGUAGE'); pmcGrabGlobals('HTTP_USER_AGENT'); /** * Finds the appropriate language file */ // If a language is defined in a cookie, ensures the translation exists if (isset($cookieLang) && file_exists('./localization/' . $cookieLang . '/localized.tutorial.' . C_EXTENSION)) { $lang = $cookieLang; } // Checks for an existing translation corresponding to the // 'HTTP_ACCEPT_LANGUAGE' variable sent by the browser else if (getenv('HTTP_ACCEPT_LANGUAGE') != '') { $accepted = explode(',', getenv('HTTP_ACCEPT_LANGUAGE')); pmcTutorialDetect($accepted[0], 1); } // Checks for an existing translation corresponding to the // 'HTTP_USER_AGENT' variable sent by the browser else if (getenv('HTTP_USER_AGENT') != '') { pmcTutorialDetect(getenv('HTTP_USER_AGENT'), 2); } // If no translation has been retained, uses the default one if (empty($lang)) { $lang = 'english'; $noTranslation = '<center><p class="redText">Sorry but the tutorial hasn\'t been translated to your language at this time.</p></center>'; } // Clears the table unset($availableTutorials); ?> |