Return the available languages as array
public static getLanguages ( boolean $blnInstalledOnly = false ) : array | ||
$blnInstalledOnly | boolean | If true, return only installed languages |
Résultat | array | An array of languages |
/** * Run the controller and parse the login template * * @return Response */ public function run() { /** @var BackendTemplate|object $objTemplate */ $objTemplate = new \BackendTemplate('be_login'); $strHeadline = sprintf($GLOBALS['TL_LANG']['MSC']['loginTo'], \Config::get('websiteTitle')); $objTemplate->theme = \Backend::getTheme(); $objTemplate->messages = \Message::generate(); $objTemplate->base = \Environment::get('base'); $objTemplate->language = $GLOBALS['TL_LANGUAGE']; $objTemplate->languages = \System::getLanguages(true); $objTemplate->title = \StringUtil::specialchars($strHeadline); $objTemplate->charset = \Config::get('characterSet'); $objTemplate->action = ampersand(\Environment::get('request')); $objTemplate->userLanguage = $GLOBALS['TL_LANG']['tl_user']['language'][0]; $objTemplate->headline = $strHeadline; $objTemplate->curLanguage = \Input::post('language') ?: str_replace('-', '_', $GLOBALS['TL_LANGUAGE']); $objTemplate->curUsername = \Input::post('username') ?: ''; $objTemplate->uClass = $_POST && empty($_POST['username']) ? ' class="login_error"' : ''; $objTemplate->pClass = $_POST && empty($_POST['password']) ? ' class="login_error"' : ''; $objTemplate->loginButton = \StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['loginBT']); $objTemplate->username = $GLOBALS['TL_LANG']['tl_user']['username'][0]; $objTemplate->password = $GLOBALS['TL_LANG']['MSC']['password'][0]; $objTemplate->feLink = $GLOBALS['TL_LANG']['MSC']['feLink']; $objTemplate->default = $GLOBALS['TL_LANG']['MSC']['default']; $objTemplate->jsDisabled = $GLOBALS['TL_LANG']['MSC']['jsDisabled']; return $objTemplate->getResponse(); }
/** * @param bool $blnReload * @return array */ public function getLanguages($blnReload = false) { if ($blnReload || !is_array(self::$arrLanguages) || count(self::$arrLanguages) < 1) { // Get all languages $arrSystemLanguages = System::getLanguages(); // Get all used languages $arrLanguages = array(); // If languages are specified if ($GLOBALS['TL_CONFIG']['chooseTranslationLanguages'] == '1') { $arrTranslationLanguages = deserialize($GLOBALS['TL_CONFIG']['translationLanguages']); if (is_array($arrTranslationLanguages) && $arrTranslationLanguages > 0) { foreach ($arrTranslationLanguages as $strLanguage) { $arrLanguages[$strLanguage] = $arrSystemLanguages[$strLanguage]; } } } else { $objRootPages = TranslationFieldsPageModel::findRootPages(); if ($objRootPages !== null) { while ($objRootPages->next()) { $arrLanguages[$objRootPages->language] = $arrSystemLanguages[$objRootPages->language]; } } // If langauge array is empty if (count($arrLanguages) < 1) { // Set all available languages $arrLanguages = System::getLanguages(true); // Set the language of the user to the top if (BackendUser::getInstance()->language != null) { // Get langauge value $strLanguageValue = $arrLanguages[BackendUser::getInstance()->language]; // Remove the current language from the array unset($arrLanguages[BackendUser::getInstance()->language]); // Add old array to a temp array $arrLanguagesTemp = $arrLanguages; // Generate a new array $arrLanguages = array(BackendUser::getInstance()->language => $strLanguageValue); // Merge the old array into the new array $arrLanguages = array_merge($arrLanguages, $arrLanguagesTemp); } } } self::$arrLanguages = $arrLanguages; } return self::$arrLanguages; }
/** * @param string $languageCode * * @return string */ protected function getLanguageLabel($languageCode) { static $languages; if (null === $languages) { $languages = System::getLanguages(); } if (array_key_exists($languageCode, $languages)) { list($label, ) = explode(' - ', $languages[$languageCode], 2); } else { $label = $languageCode; } return $label; }