From 311964dafc589ec1f6b6f63df86d65c698ffc8a3 Mon Sep 17 00:00:00 2001 From: Rimas Kudelis <rq@akl.lt> Date: Mon, 7 Mar 2016 10:59:29 +0200 Subject: [PATCH] Localize the installer This makes it possible for the admin to choose their preferred language in the first step of the installer. That choice applies to the rest of the installation process and is set as the default system language in the config file. --- config.template.php | 2 +- languages/en_us/Install.php | 1 + layouts/vlayout/modules/Install/Step1.tpl | 11 +++++++++ modules/Install/models/ConfigFileUtils.php | 7 +++++- modules/Install/models/InitSchema.php | 2 ++ modules/Install/models/Utils.php | 27 ++++++++++++++++++++++ modules/Install/views/Index.php | 10 ++++++-- 7 files changed, 56 insertions(+), 4 deletions(-) diff --git a/config.template.php b/config.template.php index 73ad086e5..563174eec 100644 --- a/config.template.php +++ b/config.template.php @@ -169,7 +169,7 @@ $default_charset = '_VT_CHARSET_'; // default language // default_language default value = en_us -$default_language = 'en_us'; +$default_language = '_VT_DEFAULT_LANGUAGE_'; // add the language pack name to every translation string in the display. // translation_string_prefix default value = false diff --git a/languages/en_us/Install.php b/languages/en_us/Install.php index 83c21d54d..08da15bdb 100644 --- a/languages/en_us/Install.php +++ b/languages/en_us/Install.php @@ -17,6 +17,7 @@ $languageStrings = array( 'ERR_UNABLE_CREATE_DATABASE' => 'Unable to Create database', 'LBL_ADMIN_INFORMATION'=>'Admin User Information', 'LBL_ADMIN_USER_INFORMATION' => 'Admin User Information', + 'LBL_CHOOSE_LANGUAGE' => 'Choose the default language for this installation:', 'LBL_CONFIRM_CONFIGURATION_SETTINGS' => 'Confirm Configuration Settings', 'LBL_CREATE_NEW_DB'=>'Create new database', 'LBL_CURRENCIES'=>'Currency', diff --git a/layouts/vlayout/modules/Install/Step1.tpl b/layouts/vlayout/modules/Install/Step1.tpl index 5bff3cdd8..011a83ab6 100644 --- a/layouts/vlayout/modules/Install/Step1.tpl +++ b/layouts/vlayout/modules/Install/Step1.tpl @@ -37,6 +37,17 @@ <h3>{vtranslate('LBL_WELCOME_TO_VTIGER6_SETUP_WIZARD', 'Install')}</h3> {vtranslate('LBL_VTIGER6_SETUP_WIZARD_DESCRIPTION','Install')} </div> + {if $LANGUAGES|@count > 1} + <div> + <label>{vtranslate('LBL_CHOOSE_LANGUAGE', 'Install')} + <select name="lang" id="lang"> + {foreach key=header item=language from=$LANGUAGES} + <option value="{$header}" {if $header eq $CURRENT_LANGUAGE}selected{/if}>{vtranslate("$language",'Install')}</option> + {/foreach} + </select> + </label> + </div> + {/if} </div> </div> <div class="row-fluid"> diff --git a/modules/Install/models/ConfigFileUtils.php b/modules/Install/models/ConfigFileUtils.php index 4814b031a..34cbbf023 100644 --- a/modules/Install/models/ConfigFileUtils.php +++ b/modules/Install/models/ConfigFileUtils.php @@ -20,6 +20,7 @@ class Install_ConfigFileUtils_Model { private $siteUrl; private $cacheDir; private $vtCharset = 'UTF-8'; + private $vtDefaultLanguage = 'en_us'; private $currencyName; private $adminEmail; @@ -43,6 +44,7 @@ class Install_ConfigFileUtils_Model { if (isset($configFileParameters['admin_email'])) $this->adminEmail = $configFileParameters['admin_email']; if (isset($configFileParameters['currency_name'])) $this->currencyName = $configFileParameters['currency_name']; if (isset($configFileParameters['vt_charset'])) $this->vtCharset = $configFileParameters['vt_charset']; + if (isset($configFileParameters['default_language'])) $this->vtDefaultLanguage = $configFileParameters['default_language']; // update default port if ($this->dbPort == '') $this->dbPort = self::getDbDefaultPort($this->dbType); @@ -88,6 +90,9 @@ class Install_ConfigFileUtils_Model { /* replace charset variable */ $buffer = str_replace( "_VT_CHARSET_", $this->vtCharset, $buffer); + /* replace default lanugage variable */ + $buffer = str_replace( "_VT_DEFAULT_LANGUAGE_", $this->vtDefaultLanguage, $buffer); + /* replace master currency variable */ $buffer = str_replace( "_MASTER_CURRENCY_", $this->currencyName, $buffer); @@ -254,7 +259,7 @@ ini_set('memory_limit','64M'); // default language // default_language default value = en_us -\$default_language = 'en_us'; +\$default_language = '{$this->vtDefaultLanguage}'; // add the language pack name to every translation string in the display. // translation_string_prefix default value = false diff --git a/modules/Install/models/InitSchema.php b/modules/Install/models/InitSchema.php index 7b8e5a249..144283ea9 100644 --- a/modules/Install/models/InitSchema.php +++ b/modules/Install/models/InitSchema.php @@ -770,6 +770,7 @@ class Install_InitSchema_Model { //Fix for http://trac.vtiger.com/cgi-bin/trac.cgi/ticket/7974 $userFirstName = $_SESSION['config_file_info']['firstname']; $userLastName = $_SESSION['config_file_info']['lastname']; + $userLanguage = $_SESSION['config_file_info']['default_language']; // create default admin user $user = CRMEntity::getInstance('Users'); //Fix for http://trac.vtiger.com/cgi-bin/trac.cgi/ticket/7974 @@ -781,6 +782,7 @@ class Install_InitSchema_Model { $user->column_fields["is_admin"] = 'on'; $user->column_fields["user_password"] = $adminPassword; $user->column_fields["time_zone"] = $userTimeZone; + $user->column_fields["language"] = $userLanguage; $user->column_fields["holidays"] = 'de,en_uk,fr,it,us,'; $user->column_fields["workdays"] = '0,1,2,3,4,5,6,'; $user->column_fields["weekstart"] = '1'; diff --git a/modules/Install/models/Utils.php b/modules/Install/models/Utils.php index 87a7d28c3..af08cb4aa 100644 --- a/modules/Install/models/Utils.php +++ b/modules/Install/models/Utils.php @@ -273,6 +273,33 @@ class Install_Utils_Model { return $currencies; } + + /** + * Returns an array with the list of languages which are available in source + * Note: the DB has not been initialized at this point, so we have to look at + * the contents of the `languages/` directory. + * @return <Array> + */ + public static function getLanguageList() { + $languageFolder = 'languages/'; + $handle = opendir($languageFolder); + $language_list = array(); + while ($prefix = readdir($handle)) { + if (substr($prefix, 0, 1) === '.' || $prefix === 'Settings') { + continue; + } + if (is_dir('languages/' . $prefix) && is_file('languages/' . $prefix . '/Install.php')) { + $language_list[$prefix] = $prefix; + } + } + + ksort($language_list); + + return $language_list; + } + + + /** * Function checks if its mysql type * @param type $dbType diff --git a/modules/Install/views/Index.php b/modules/Install/views/Index.php index 3d7017986..2942acedf 100644 --- a/modules/Install/views/Index.php +++ b/modules/Install/views/Index.php @@ -41,8 +41,12 @@ class Install_Index_view extends Vtiger_View_Controller { parent::preProcess($request); $viewer = $this->getViewer($request); $moduleName = $request->getModule(); - $defaultLanguage = ($request->get('lang'))?$request->get('lang'):'en_us'; - vglobal('default_language', $defaultLanguage); + if ($chosenLanguage = $request->get('lang')) { + $_SESSION['config_file_info']['default_language'] = $chosenLanguage; + } elseif (empty($_SESSION['config_file_info']['default_language'])) { + $_SESSION['config_file_info']['default_language'] = 'en_us'; + } + vglobal('default_language', $_SESSION['config_file_info']['default_language']); define('INSTALLATION_MODE', true); define('INSTALLATION_MODE_DEBUG', $this->debug); @@ -67,6 +71,8 @@ class Install_Index_view extends Vtiger_View_Controller { public function Step1(Vtiger_Request $request) { $viewer = $this->getViewer($request); $moduleName = $request->getModule(); + $viewer->assign('CURRENT_LANGUAGE', vglobal('default_language')); + $viewer->assign('LANGUAGES', Install_Utils_model::getLanguageList()); $viewer->view('Step1.tpl', $moduleName); } -- GitLab