Contao\System::getLanguages PHP Méthode

getLanguages() public static méthode

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
    public static function getLanguages($blnInstalledOnly = false)
    {
        $return = array();
        $languages = array();
        $arrAux = array();
        $langsNative = array();
        static::loadLanguageFile('languages');
        include __DIR__ . '/../../config/languages.php';
        foreach ($languages as $strKey => $strName) {
            $arrAux[$strKey] = isset($GLOBALS['TL_LANG']['LNG'][$strKey]) ? Utf8::toAscii($GLOBALS['TL_LANG']['LNG'][$strKey]) : $strName;
        }
        asort($arrAux);
        $arrBackendLanguages = scan(__DIR__ . '/../../languages');
        foreach (array_keys($arrAux) as $strKey) {
            if ($blnInstalledOnly && !in_array($strKey, $arrBackendLanguages)) {
                continue;
            }
            $return[$strKey] = isset($GLOBALS['TL_LANG']['LNG'][$strKey]) ? $GLOBALS['TL_LANG']['LNG'][$strKey] : $languages[$strKey];
            if (isset($langsNative[$strKey]) && $langsNative[$strKey] != $return[$strKey]) {
                $return[$strKey] .= ' - ' . $langsNative[$strKey];
            }
        }
        // HOOK: add custom logic
        if (isset($GLOBALS['TL_HOOKS']['getLanguages']) && is_array($GLOBALS['TL_HOOKS']['getLanguages'])) {
            foreach ($GLOBALS['TL_HOOKS']['getLanguages'] as $callback) {
                static::importStatic($callback[0])->{$callback[1]}($return, $languages, $langsNative, $blnInstalledOnly);
            }
        }
        return $return;
    }

Usage Example

Exemple #1
0
 /**
  * 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();
 }
All Usage Examples Of Contao\System::getLanguages