/** * Generate page * * @param iMSCP_pTemplate $tpl Template engine * @return void */ function admin_generateLanguagesList($tpl) { $cfg = iMSCP_Registry::get('config'); $defaultLanguage = $cfg['USER_INITIAL_LANG']; $availableLanguages = i18n_getAvailableLanguages(); if (!empty($availableLanguages)) { foreach ($availableLanguages as $languageDefinition) { $tpl->assign(array('LANGUAGE_NAME' => tohtml($languageDefinition['language']), 'NUMBER_TRANSLATED_STRINGS' => tohtml(tr('%d strings translated', $languageDefinition['translatedStrings'])), 'LANGUAGE_REVISION' => tohtml($languageDefinition['revision']), 'LOCALE_CHECKED' => $languageDefinition['locale'] == $defaultLanguage ? 'checked' : '', 'LOCALE' => tohtml($languageDefinition['locale'], 'htmlAttr'))); $tpl->parse('LANGUAGE_BLOCK', '.language_block'); } } else { $tpl->assign('LANGUAGES_BLOCK', ''); } }
/** * Helper function to generates an html list of available languages * * This method generate a HTML list of available languages. The language used by the user is pre-selected. * If no language is found, a specific message is shown. * * @param iMSCP_pTemplate $tpl Template engine * @param string $userDefinedLanguage User defined language * @return void */ function gen_def_language($tpl, $userDefinedLanguage) { /** @var $cfg iMSCP_Config_Handler_File */ $cfg = iMSCP_Registry::get('config'); $htmlSelected = $cfg['HTML_SELECTED']; $availableLanguages = i18n_getAvailableLanguages(); array_unshift($availableLanguages, array('locale' => 'auto', 'language' => tr('Auto (Browser language)'))); if (!empty($availableLanguages)) { foreach ($availableLanguages as $language) { $tpl->assign(array('LANG_VALUE' => $language['locale'], 'LANG_SELECTED' => $language['locale'] == $userDefinedLanguage ? $htmlSelected : '', 'LANG_NAME' => tohtml($language['language']))); $tpl->parse('DEF_LANGUAGE', '.def_language'); } } else { $tpl->assign('LANGUAGES_AVAILABLE', ''); set_page_message(tr('No languages found.'), 'static_warning'); } }
/** * Change panel default language * * @author Laurent Declercq <*****@*****.**> * @return bool TRUE if language name is valid, FALSE otherwise */ function i18n_changeDefaultLanguage() { if (isset($_POST['defaultLanguage'])) { /** @var $cfg iMSCP_Config_Handler_File */ $cfg = iMSCP_Registry::get('config'); /** @var $dbConfig iMSCP_Config_Handler_Db */ $defaultLanguage = clean_input($_POST['defaultLanguage']); $availableLanguages = i18n_getAvailableLanguages(); // Check for language availability $isValidLanguage = false; foreach ($availableLanguages as $languageDefinition) { if ($languageDefinition['locale'] == $defaultLanguage) { $isValidLanguage = true; } } if (!$isValidLanguage) { return false; } /** @var $dbConfig iMSCP_Config_Handler_Db */ $dbConfig = iMSCP_Registry::get('dbConfig'); $dbConfig->USER_INITIAL_LANG = $defaultLanguage; $cfg->USER_INITIAL_LANG = $defaultLanguage; // Ensures language change on next load for current user in case he has not yet his gui properties explicitly // set (eg. for the first admin user when i-MSCP was just installed $stmt = exec_query('SELECT lang FROM user_gui_props WHERE user_id = ?', $_SESSION['user_id']); if ($stmt->fields['lang'] == null) { unset($_SESSION['user_def_lang']); } } else { return false; } return true; }