getQueryBuilderForTable('sys_language'); $queryBuilder = $queryBuilder->select('uid', 'title', 'flag') ->from('sys_language') ->groupBy('flag', 'uid'); if ($uids !== NULL) { $queryBuilder = $queryBuilder->where( $queryBuilder->expr()->in( 'uid', $queryBuilder->createNamedParameter($uids, Connection::PARAM_INT_ARRAY) ) ); } $rows = $queryBuilder->execute()->fetchAll(); $sysLanguageList = []; foreach ($rows as $row) { $sysLanguageList[$row['flag']]['uid'] = $row['uid']; $sysLanguageList[$row['flag']]['title'] = $row['title']; } return $sysLanguageList; } /** * Initialises array of system languages from database. */ public function initSysLanguageList() { if (!isset($this->sysLanguageList)) { $this->sysLanguageList = $this->selectFromSysLanguageByUids(); } } /** * Returns the iso reverse mapped flag language or the given value if nothing could be mapped. * * @param string $flag language acronym (iso language code, e.g.: 'de', 'da', 'fi'...) * @return string */ public function doIsoReverseMapping($flag) { $isoReverseMapping = $this->getIsoReverseMapping(); $mappedFlag = isset($isoReverseMapping[$flag]) ? (string) $isoReverseMapping[$flag] : ''; if ($mappedFlag !== '') { $flag = $mappedFlag; } return $flag; } /** * Returns system language id for given language acronym ($flag). * If that language is not registered in system, function returns NULL. * * @param string $flag language acronym (iso language code, e.g.: 'de', 'da', 'fi'...) * @return int|NULL */ public function getSysLanguageIdByFlag($flag) { $this->initSysLanguageList(); $flag = $this->doIsoReverseMapping($flag); // chinese seems to have a big mapping issue. In general it seems that the iso handling is currently more // or less simply fucked up in TYPO3. Also it's possible that I don't get the bigger picture here. Who knows... // Also note: Chinese isn't working without a default file in the override mode. if ($flag === 'zh') { $flag = 'cn'; } if (!empty($this->sysLanguageList[$flag]['uid'])) { return (int) $this->sysLanguageList[$flag]['uid']; } return NULL; } /** * Returns the mapping between ISO language codes and TYPO3 (old) codes. * * @return array */ public function getIsoReverseMapping() { if (!empty($this->isoReverseMapping)) { return $this->isoReverseMapping; } /** @var Locales $locales */ $locales = GeneralUtility::makeInstance(Locales::class); $isoMapping = $locales->getIsoMapping(); $this->isoReverseMapping = \array_flip($isoMapping); return $this->isoReverseMapping; } }