Feature #272 - Installation scripts: If it is possible, the initial value of the language during the installation procedure is according to the the browser.

skala
Ivan Tcholakov 15 years ago
parent f9ba1ce3d6
commit 5285dba95f
  1. 40
      main/install/index.php
  2. 119
      main/install/install_upgrade.lib.php

@ -43,6 +43,10 @@ session_start();
require '../inc/lib/main_api.lib.php'; require '../inc/lib/main_api.lib.php';
require api_get_path(LIBRARY_PATH).'database.lib.php'; require api_get_path(LIBRARY_PATH).'database.lib.php';
// Including specialized libraries for the installation procedure.
require_once 'install_upgrade.lib.php'; //also defines constants
require_once 'install_functions.inc.php';
// The function api_get_setting() might be called within the installation scripts. // The function api_get_setting() might be called within the installation scripts.
// We need to provide some limited support for it through initialization of the // We need to provide some limited support for it through initialization of the
// global array-type variable $_setting. // global array-type variable $_setting.
@ -52,21 +56,27 @@ $_setting = array(
'permissions_for_new_files' => '0660' 'permissions_for_new_files' => '0660'
); );
// Loading language files. // Determination of the language during the installation procedure.
// TODO: It would be nice browser's intrface language to be detected at this point.
require api_get_path(SYS_LANG_PATH).'english/trad4all.inc.php';
require api_get_path(SYS_LANG_PATH).'english/install.inc.php';
if (!empty($_POST['language_list'])) { if (!empty($_POST['language_list'])) {
$search = array('../', '\\0'); $search = array('../', '\\0');
$install_language = str_replace($search, '', urldecode($_POST['language_list'])); $install_language = str_replace($search, '', urldecode($_POST['language_list']));
if (!is_dir(api_get_path(SYS_LANG_PATH).$install_language)) {
$install_language = 'english';
}
include_once api_get_path(SYS_LANG_PATH).$install_language.'/trad4all.inc.php';
include_once api_get_path(SYS_LANG_PATH).$install_language.'/install.inc.php';
api_session_register('install_language'); api_session_register('install_language');
} elseif (isset($_SESSION['install_language']) && $_SESSION['install_language']) { } elseif (isset($_SESSION['install_language']) && $_SESSION['install_language']) {
$install_language = $_SESSION['install_language']; $install_language = $_SESSION['install_language'];
} else {
// Trying to switch to the browser's language, it is covenient for most of the cases.
$install_language = detect_browser_language();
}
// Language validation.
if (!array_key_exists($install_language, get_language_folder_list())) {
$install_language = 'english';
}
// Loading language files.
require api_get_path(SYS_LANG_PATH).'english/trad4all.inc.php';
require api_get_path(SYS_LANG_PATH).'english/install.inc.php';
if ($install_language != 'english') {
include_once api_get_path(SYS_LANG_PATH).$install_language.'/trad4all.inc.php'; include_once api_get_path(SYS_LANG_PATH).$install_language.'/trad4all.inc.php';
include_once api_get_path(SYS_LANG_PATH).$install_language.'/install.inc.php'; include_once api_get_path(SYS_LANG_PATH).$install_language.'/install.inc.php';
} }
@ -86,10 +96,6 @@ api_set_internationalization_default_encoding($charset);
// Page encoding initialization. // Page encoding initialization.
header('Content-Type: text/html; charset='. api_get_system_encoding()); header('Content-Type: text/html; charset='. api_get_system_encoding());
// Specialized libraries for the installation procedure.
require_once 'install_upgrade.lib.php'; //also defines constants
require_once 'install_functions.inc.php';
// Some constants // Some constants
define('SYSTEM_INSTALLATION', 1); define('SYSTEM_INSTALLATION', 1);
define('MAX_COURSE_TRANSFER', 100); define('MAX_COURSE_TRANSFER', 100);
@ -232,9 +238,9 @@ if (!isset($_GET['running'])) {
$adminPhoneForm = '(000) 001 02 03'; $adminPhoneForm = '(000) 001 02 03';
$institutionForm = 'My Organisation'; $institutionForm = 'My Organisation';
$institutionUrlForm = 'http://www.chamilo.org'; $institutionUrlForm = 'http://www.chamilo.org';
$languageForm = 'english';
// TODO: A better choice to be tested: // TODO: A better choice to be tested:
//$languageForm = api_get_interface_language(); //$languageForm = 'english';
$languageForm = api_get_interface_language();
$checkEmailByHashSent = 0; $checkEmailByHashSent = 0;
$ShowEmailnotcheckedToStudent = 1; $ShowEmailnotcheckedToStudent = 1;
@ -355,7 +361,7 @@ if ($encryptPassForm == '1') {
document.getElementById('optional_param5').style.display = ''; document.getElementById('optional_param5').style.display = '';
document.getElementById('optional_param6').style.display = ''; document.getElementById('optional_param6').style.display = '';
init_visibility = 1; init_visibility = 1;
document.getElementById('optionalparameters').innerHTML='<img style="vertical-align:middle;" src="../img/div_hide.gif" alt="" /> <?php echo get_lang('OptionalParameters'); ?>'; document.getElementById('optionalparameters').innerHTML='<img style="vertical-align:middle;" src="../img/div_hide.gif" alt="" /> <?php echo get_lang('OptionalParameters', ''); ?>';
} else { } else {
document.getElementById('optional_param1').style.display = 'none'; document.getElementById('optional_param1').style.display = 'none';
document.getElementById('optional_param2').style.display = 'none'; document.getElementById('optional_param2').style.display = 'none';
@ -365,7 +371,7 @@ if ($encryptPassForm == '1') {
document.getElementById('optional_param4').style.display = 'none'; document.getElementById('optional_param4').style.display = 'none';
document.getElementById('optional_param5').style.display = 'none'; document.getElementById('optional_param5').style.display = 'none';
document.getElementById('optional_param6').style.display = 'none'; document.getElementById('optional_param6').style.display = 'none';
document.getElementById('optionalparameters').innerHTML='<img style="vertical-align:middle;" src="../img/div_show.gif" alt="" /> <?php echo get_lang('OptionalParameters'); ?>'; document.getElementById('optionalparameters').innerHTML='<img style="vertical-align:middle;" src="../img/div_show.gif" alt="" /> <?php echo get_lang('OptionalParameters', ''); ?>';
init_visibility = 0; init_visibility = 0;
} }
} }

@ -392,25 +392,114 @@ function get_sql_file_contents($file, $section, $print_errors = true) {
} }
/** /**
* Returns a list of language directories. * Tries to detect browser's language.
* @return string Returns a language identificator, i.e. 'english', 'spanish', ...
*/ */
function get_language_folder_list() { function detect_browser_language() {
$result = array(); static $language_index = array(
$exceptions = array('.', '..', 'CVS', '.svn'); 'ar' => 'arabic',
$search = array('_latin', '_unicode', '_corporate', '_org' , '_KM', '_'); 'ast' => 'asturian',
$replace_with = array(' (Latin)', ' (unicode)', ' (corporate)', ' (org)', ' (KM)', ' '); 'bg' => 'bulgarian',
$dirname = api_get_path(SYS_LANG_PATH); 'bs' => 'bosnian',
$handle = opendir($dirname); 'ca' => 'catalan',
while ($entries = readdir($handle)) { 'zh' => 'simpl_chinese',
if (in_array($entries, $exceptions)) { 'zh-tw' => 'trad_chinese',
continue; 'cs' => 'czech',
'da' => 'danish',
'prs' => 'dari',
'de' => 'german',
'el' => 'greek',
'en' => 'english',
'es' => 'spanish',
'eo' => 'esperanto',
'eu' => 'euskera',
'fa' => 'persian',
'fr' => 'french',
'fur' => 'friulian',
'gl' => 'galician',
'ka' => 'georgian',
'hr' => 'croatian',
'he' => 'hebrew',
'id' => 'indonesian',
'it' => 'italian',
'ko' => 'korean',
'lv' => 'latvian',
'lt' => 'lithuanian',
'mk' => 'macedonian',
'hu' => 'hungarian',
'ms' => 'malay',
'nl' => 'dutch',
'ja' => 'japanese',
'no' => 'norwegian',
'oc' => 'occitan',
'ps' => 'pashto',
'pl' => 'polish',
'pt' => 'portuguese',
'pt-br' => 'brazilian',
'ro' => 'romanian',
'qu' => 'quechua_cusco',
'ru' => 'russian',
'sk' => 'slovak',
'sl' => 'slovenian',
'sr' => 'serbian',
'fi' => 'finnish',
'sv' => 'swedish',
'th' => 'thai',
'tr' => 'turkce',
'uk' => 'ukrainian',
'vi' => 'vietnamese',
'sw' => 'swahili',
'yo' => 'yoruba'
);
$system_available_languages = & get_language_folder_list();
$accept_languages = strtolower(str_replace('_', '-', $_SERVER['HTTP_ACCEPT_LANGUAGE']));
foreach ($language_index as $code => $language) {
if (strpos($accept_languages, $code) === 0) {
if (!empty($system_available_languages[$language])) {
return $language;
}
} }
if (is_dir($dirname.$entries)) { }
$result[$entries] = ucwords(str_replace($search, $replace_with, $entries));
$user_agent = strtolower(str_replace('_', '-', $_SERVER['HTTP_USER_AGENT']));
foreach ($language_index as $code => $language) {
if (preg_match("/[[( ]{$code}[;,_-)]/", $user_agent)) {
if (!empty($system_available_languages[$language])) {
return $language;
}
} }
} }
closedir($handle);
asort($result); return 'english';
}
/**
* Returns a list of language directories.
*/
function & get_language_folder_list() {
static $result;
if (!is_array($result)) {
$result = array();
$exceptions = array('.', '..', 'CVS', '.svn');
$search = array('_latin', '_unicode', '_corporate', '_org' , '_KM', '_');
$replace_with = array(' (Latin)', ' (unicode)', ' (corporate)', ' (org)', ' (KM)', ' ');
$dirname = api_get_path(SYS_LANG_PATH);
$handle = opendir($dirname);
while ($entries = readdir($handle)) {
if (in_array($entries, $exceptions)) {
continue;
}
if (is_dir($dirname.$entries)) {
$result[$entries] = ucwords(str_replace($search, $replace_with, $entries));
}
}
closedir($handle);
asort($result);
}
return $result; return $result;
} }

Loading…
Cancel
Save