/** * @return void */ public function indexAction() { $menu = array(); $availableLanguages = explode(',', '0,' . $this->widgetConfiguration['availableLanguages']); $availableLanguages = array_unique($availableLanguages); $currentLanguageUid = (int) $this->widgetConfiguration['currentLanguageUid']; $defaultLanguageIsoCodeShort = $this->widgetConfiguration['defaultLanguageIsoCodeShort']; $defaultLanguageLabel = $this->widgetConfiguration['defaultLanguageLabel']; $defaultLanguageFlag = $this->widgetConfiguration['defaultLanguageFlag']; $flagIconPath = $this->widgetConfiguration['flagIconPath']; $flagIconFileExtension = $this->widgetConfiguration['flagIconFileExtension']; if (!empty($availableLanguages)) { foreach ($availableLanguages as $languageUid) { $menuEntry = array(); $menuEntry['L'] = $languageUid; $menuEntry['pageUid'] = $GLOBALS['TSFE']->id; $class = 'unknown'; $label = 'unknown'; $flag = 'unknown'; $hasTranslation = TRUE; // Is active language $menuEntry['active'] = (int) $currentLanguageUid === (int) $languageUid; // Is default language if ((int) $languageUid === 0) { $class = $defaultLanguageIsoCodeShort != '' ? $defaultLanguageIsoCodeShort : 'en'; $label = $defaultLanguageLabel != '' ? $defaultLanguageLabel : 'English'; $flag = $defaultLanguageFlag != '' ? $defaultLanguageFlag : 'gb'; } elseif ($sysLanguage = $this->getSysLanguage($languageUid)) { if (!$this->languageRepository instanceof LanguageRepository) { $this->languageRepository = GeneralUtility::makeInstance('SJBR\\StaticInfoTables\\Domain\\Repository\\LanguageRepository'); } $languageObject = $this->languageRepository->findByIdentifier($sysLanguage['static_lang_isocode']); if ($languageObject instanceof \SJBR\StaticInfoTables\Domain\Model\Language) { $class = $languageObject->getIsoCodeA2(); $label = $languageObject->getNameEn(); } $flag = $sysLanguage['flag']; $hasTranslation = $this->hasTranslation($GLOBALS['TSFE']->id, $languageUid); } $menuEntry['label'] = $label; $menuEntry['class'] = strtolower($class); $menuEntry['flag'] = $flag; $menuEntry['hasTranslation'] = $hasTranslation; $menu[] = $menuEntry; } } $this->view->assign('menu', $menu); $this->view->assign('flagIconPath', $flagIconPath); $this->view->assign('flagIconFileExtension', $flagIconFileExtension); }
/** * Show the menu * * @return string empty string */ public function indexAction() { // Adjust settings $this->processSettings(); // Get system languages $systemLanguages = $this->systemLanguageRepository->findAllByUidInList($this->settings['languages'])->toArray(); // Add default language $defaultLanguageISOCode = $this->settings['defaultLanguageISOCode'] ? strtoupper($this->settings['defaultLanguageISOCode']) : 'EN'; $defaultCountryISOCode = $this->settings['defaultCountryISOCode'] ? strtoupper($this->settings['defaultCountryISOCode']) : ''; $defaultIsoLanguage = $this->languageRepository->findOneByIsoCodes($defaultLanguageISOCode, $defaultCountryISOCode); if (!is_object($defaultIsoLanguage)) { $defaultCountryISOCode = ''; $defaultIsoLanguage = $this->languageRepository->findOneByIsoCodes($defaultLanguageISOCode); if (!is_object($defaultIsoLanguage)) { $defaultLanguageISOCode = 'EN'; $defaultIsoLanguage = $this->languageRepository->findOneByIsoCodes($defaultLanguageISOCode); } } if (\TYPO3\CMS\Core\Utility\VersionNumberUtility::convertVersionNumberToInteger(TYPO3_version) < 6001000) { $defaultSystemLanguage = $this->objectManager->create('SJBR\\SrLanguageMenu\\Domain\\Model\\SystemLanguage'); } else { $defaultSystemLanguage = $this->objectManager->get('SJBR\\SrLanguageMenu\\Domain\\Model\\SystemLanguage'); } $defaultSystemLanguage->setIsoLanguage($defaultIsoLanguage); $defaultSystemLanguage->setTitle($defaultSystemLanguage->getIsoLanguage()->getNameLocalized()); array_unshift($systemLanguages, $defaultSystemLanguage); // Get the available page language overlays $availableOverlays = array(); // Add default language $availableOverlays[] = 0; // Beware of inaccessible page $page = $this->pageRepository->findByUid($this->getFrontendObject()->id); if ($page instanceof \SJBR\SrLanguageMenu\Domain\Model\Page) { $pageLanguageOverlays = $this->pageLanguageOverlayRepository->findByPage($page)->toArray(); foreach ($pageLanguageOverlays as $pageLanguageOverlay) { // The overlay may refer to a deleted Website language if (is_object($pageLanguageOverlay->getLanguage())) { $availableOverlays[] = $pageLanguageOverlay->getLanguage()->getUid(); } } } // Do not show menu if hideIfNoAltLanguages is set and there are no alternate languages $this->settings['showMenu'] = !$this->settings['hideIfNoAltLanguages'] || count($availableOverlays) > 1; // Build language options $options = array(); // If $this->settings['languages'] is not empty, the languages will be sorted in the order it specifies $languages = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $this->settings['languages'], TRUE); if (!empty($languages) && !in_array(0, $languages)) { array_unshift($languages, 0); } $index = 0; foreach ($systemLanguages as $systemLanguage) { $option = array('uid' => $systemLanguage->getUid() ? $systemLanguage->getUid() : 0, 'isoCodeA2' => is_object($systemLanguage->getIsoLanguage()) ? $systemLanguage->getIsoLanguage()->getIsoCodeA2() : '', 'countryIsoCodeA2' => is_object($systemLanguage->getIsoLanguage()) ? $systemLanguage->getIsoLanguage()->getCountryIsoCodeA2() : ''); // Set combined ISO code $option['combinedIsoCode'] = strtolower($option['isoCodeA2']) . ($option['countryIsoCodeA2'] ? '_' . $option['countryIsoCodeA2'] : ''); // Set the label switch ($this->settings['languageTitle']) { case '0': $option['title'] = is_object($systemLanguage->getIsoLanguage()) ? $systemLanguage->getIsoLanguage()->getNameLocalized() : ''; break; case '1': $option['title'] = is_object($systemLanguage->getIsoLanguage()) ? $systemLanguage->getIsoLanguage()->getLocalName() : ''; break; case '2': $option['title'] = $systemLanguage->getTitle(); break; case '3': $option['title'] = strtoupper($option['combinedIsoCode']); break; } if (!$option['title']) { $option['title'] = $systemLanguage->getTitle(); } // Set paths to flags $partialFlagFileName = $this->settings['flagsDirectory'] . ($this->settings['alternateFlags'][$option['combinedIsoCode']] ? $this->settings['alternateFlags'][$option['combinedIsoCode']] : $option['combinedIsoCode']); $option['flagFile'] = $partialFlagFileName . '.png'; // Set availability of overlay $option['isAvailable'] = in_array($option['uid'], $availableOverlays); $option['notAvailableTitle'] = $option['title']; if (!$option['isAvailable']) { // Switch localization target language \SJBR\SrLanguageMenu\Utility\LocalizationUtility::setAlternateLanguage($option['combinedIsoCode'], $this->extensionName); $option['notAvailableTitle'] = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('translationNotAvailable', $this->extensionName, array($systemLanguage->getIsoLanguage() ? $systemLanguage->getIsoLanguage()->getLocalName() : $option['title'])); // Restore configured localization target language \SJBR\SrLanguageMenu\Utility\LocalizationUtility::restoreConfiguredLanguage($this->extensionName); } // Add configured external url for missing overlay record if ($this->settings['useExternalUrl'][$option['combinedIsoCode']] || is_array($this->settings['useExternalUrl'][$option['combinedIsoCode']])) { if ($option['isAvailable']) { if ($this->settings['forceUseOfExternalUrl'] || $this->settings['useExternalUrl'][$option['combinedIsoCode']]['force']) { $option['externalUrl'] = is_array($this->settings['useExternalUrl'][$option['combinedIsoCode']]) ? $this->settings['useExternalUrl'][$option['combinedIsoCode']]['_typoScriptNodeValue'] : $this->settings['useExternalUrl'][$option['combinedIsoCode']]; } } else { $option['externalUrl'] = is_array($this->settings['useExternalUrl'][$option['combinedIsoCode']]) ? $this->settings['useExternalUrl'][$option['combinedIsoCode']]['_typoScriptNodeValue'] : $this->settings['useExternalUrl'][$option['combinedIsoCode']]; $option['isAvailable'] = TRUE; } } // Set current language indicator $option['isCurrent'] = $option['uid'] == $this->getFrontendObject()->sys_language_uid; // If $this->settings['languages'] is not empty, the languages will be sorted in the order it specifies $key = array_search($option['uid'], $languages); $key = $key !== FALSE ? $key : count($languages) + $index++; $options[$key] = $option; } ksort($options); // Show current language first, if configured if ($this->settings['showCurrentFirst']) { $key = array_search($this->getFrontendObject()->sys_language_uid, $languages); if ($key) { $option = $options[$key]; unset($options[$key]); array_unshift($options, $option); } } // Render the menu $this->view->assign('settings', $this->settings); $this->view->assign('options', $options); }
/** * Gets the update queries for this language pack * * @return string update queries in sql format */ public function getUpdateQueries() { $updateQueries = array(); $locale = $this->getLocale(); $updateQueries = array_merge($updateQueries, $this->countryRepository->getUpdateQueries($locale)); $updateQueries = array_merge($updateQueries, $this->countryZoneRepository->getUpdateQueries($locale)); $updateQueries = array_merge($updateQueries, $this->currencyRepository->getUpdateQueries($locale)); $updateQueries = array_merge($updateQueries, $this->languageRepository->getUpdateQueries($locale)); $updateQueries = array_merge($updateQueries, $this->territoryRepository->getUpdateQueries($locale)); return implode(LF, $updateQueries); }
/** * Creation/update a language pack for the Static Info Tables * * @return string An HTML display of data overview */ public function sqlDumpNonLocalizedDataAction() { // Create a SQL dump of non-localized data $dumpContent = array(); $dumpContent[] = $this->countryRepository->sqlDumpNonLocalizedData(); $dumpContent[] = $this->countryZoneRepository->sqlDumpNonLocalizedData(); $dumpContent[] = $this->currencyRepository->sqlDumpNonLocalizedData(); $dumpContent[] = $this->languageRepository->sqlDumpNonLocalizedData(); $dumpContent[] = $this->territoryRepository->sqlDumpNonLocalizedData(); // Write the SQL dump file $extensionKey = \TYPO3\CMS\Core\Utility\GeneralUtility::camelCaseToLowerCaseUnderscored($this->extensionName); $extensionPath = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath($extensionKey); $filename = 'export-ext_tables_static+adt.sql'; \TYPO3\CMS\Core\Utility\GeneralUtility::writeFile($extensionPath . $filename, implode(LF, $dumpContent)); $message = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('sqlDumpCreated', $this->extensionName) . ' ' . $extensionPath . $filename; $this->addFlashMessage($message, '', \TYPO3\CMS\Core\Messaging\AbstractMessage::OK); $this->forward('information'); }