Ejemplo n.º 1
0
 /**
  * Creation/update a language pack for the Static Info Tables
  *
  * @param \SJBR\StaticInfoTables\Domain\Model\LanguagePack $languagePack
  * @return string An HTML display of data overview
  */
 public function createLanguagePackAction(\SJBR\StaticInfoTables\Domain\Model\LanguagePack $languagePack)
 {
     // Add the localization columns
     $locale = $languagePack->getLocale();
     // Get the English name of the locale
     $localeUtility = $this->objectManager->get('SJBR\\StaticInfoTables\\Utility\\LocaleUtility');
     $language = $localeUtility->getLanguageFromLocale($locale);
     $languagePack->setLanguage($language);
     $languagePack->setTypo3VersionRange($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][\TYPO3\CMS\Core\Utility\GeneralUtility::camelCaseToLowerCaseUnderscored($this->extensionName)]['constraints']['depends']['typo3']);
     // If version is not set, use the version of the base extension
     if (!$languagePack->getVersion()) {
         $languagePack->setVersion($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][\TYPO3\CMS\Core\Utility\GeneralUtility::camelCaseToLowerCaseUnderscored($this->extensionName)]['version']);
     }
     $this->countryRepository->addLocalizationColumns($locale);
     $this->countryZoneRepository->addLocalizationColumns($locale);
     $this->currencyRepository->addLocalizationColumns($locale);
     $this->languageRepository->addLocalizationColumns($locale);
     $this->territoryRepository->addLocalizationColumns($locale);
     // Store the Language Pack
     $languagePackRepository = $this->objectManager->get('SJBR\\StaticInfoTables\\Domain\\Repository\\LanguagePackRepository');
     $messages = $languagePackRepository->writeLanguagePack($languagePack);
     if (count($messages)) {
         foreach ($messages as $message) {
             $this->addFlashMessage($message, '', \TYPO3\CMS\Core\Messaging\AbstractMessage::OK);
         }
     }
     $this->forward('information');
 }
 /**
  * Writes the language pack files
  *
  * @param \SJBR\StaticInfoTables\Domain\Model\LanguagePack the object to be stored
  * @return array localized messages
  */
 public function writeLanguagePack(\SJBR\StaticInfoTables\Domain\Model\LanguagePack $languagePack)
 {
     $content = array();
     $extensionKey = GeneralUtility::camelCaseToLowerCaseUnderscored($this->extensionName);
     $extensionPath = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath($extensionKey);
     $content = array();
     $locale = $languagePack->getLocale();
     $localeLowerCase = strtolower($locale);
     $localeUpperCase = strtoupper($locale);
     $localeCamel = GeneralUtility::underscoredToUpperCamelCase(strtolower($locale));
     $languagePackExtensionKey = $extensionKey . '_' . $localeLowerCase;
     $languagePackExtensionPath = PATH_site . 'typo3conf/ext/' . $languagePackExtensionKey . '/';
     // Cleanup any pre-existing language pack
     if (is_dir($languagePackExtensionPath)) {
         GeneralUtility::rmdir($languagePackExtensionPath, TRUE);
     }
     // Create language pack directory structure
     if (!is_dir($languagePackExtensionPath)) {
         GeneralUtility::mkdir_deep(PATH_site, 'typo3conf/ext/' . $languagePackExtensionKey . '/');
     }
     if (!is_dir($languagePackExtensionPath . 'Classes/Domain/Model/')) {
         GeneralUtility::mkdir_deep($languagePackExtensionPath, 'Classes/Domain/Model/');
     }
     if (!is_dir($languagePackExtensionPath . 'Configuration/DomainModelExtension/')) {
         GeneralUtility::mkdir_deep($languagePackExtensionPath, 'Configuration/DomainModelExtension/');
     }
     if (!is_dir($languagePackExtensionPath . 'Configuration/TypoScript/Extbase/')) {
         GeneralUtility::mkdir_deep($languagePackExtensionPath, 'Configuration/TypoScript/Extbase/');
     }
     if (!is_dir($languagePackExtensionPath . 'Resources/Private/Language/')) {
         GeneralUtility::mkdir_deep($languagePackExtensionPath, 'Resources/Private/Language/');
     }
     // Get the source files of the language pack template
     $sourcePath = $extensionPath . 'Resources/Private/LanguagePackTemplate/';
     $sourceFiles = array();
     $sourceFiles = GeneralUtility::getAllFilesAndFoldersInPath($sourceFiles, $sourcePath);
     $sourceFiles = GeneralUtility::removePrefixPathFromList($sourceFiles, $sourcePath);
     // Set markers replacement values
     $replace = array('###LANG_ISO_LOWER###' => $localeLowerCase, '###LANG_ISO_UPPER###' => $localeUpperCase, '###LANG_ISO_CAMEL###' => $localeCamel, '###TYPO3_VERSION_RANGE###' => $languagePack->getTypo3VersionRange(), '###VERSION###' => $languagePack->getVersion(), '###LANG_NAME###' => $languagePack->getLanguage(), '###AUTHOR###' => $languagePack->getAuthor(), '###AUTHOR_EMAIL###' => $languagePack->getAuthorEmail(), '###AUTHOR_COMPANY###' => $languagePack->getAuthorCompany(), '###VERSION_BASE###' => $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$extensionKey]['version'], '###LANG_TCA_LABELS###' => $languagePack->getLocalizationLabels(), '###LANG_SQL_UPDATE###' => $languagePack->getUpdateQueries());
     // Create the language pack files
     $success = TRUE;
     foreach ($sourceFiles as $hash => $file) {
         $fileContent = GeneralUtility::getUrl($sourcePath . $file);
         foreach ($replace as $marker => $replacement) {
             $fileContent = str_replace($marker, $replacement, $fileContent);
         }
         $success = GeneralUtility::writeFile($languagePackExtensionPath . str_replace('.code', '.php', $file), $fileContent);
         if (!$success) {
             $content[] = LocalizationUtility::translate('couldNotWriteFile', $this->extensionName) . ' ' . $languagePackExtensionPath . $file;
             break;
         }
     }
     if ($success) {
         $classCacheManager = $this->objectManager->get('SJBR\\StaticInfoTables\\Cache\\ClassCacheManager');
         $installUtility = $this->objectManager->get('TYPO3\\CMS\\Extensionmanager\\Utility\\InstallUtility');
         $installed = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded($languagePackExtensionKey);
         if ($installed) {
             $content[] = LocalizationUtility::translate('languagePack', $this->extensionName) . ' ' . $languagePackExtensionKey . ' ' . LocalizationUtility::translate('languagePackUpdated', $this->extensionName);
         } else {
             $content[] = LocalizationUtility::translate('languagePackCreated', $this->extensionName) . ' ' . $languagePack->getLanguage() . ' (' . $locale . ')';
             $installUtility->install($languagePackExtensionKey);
             $content[] = LocalizationUtility::translate('languagePack', $this->extensionName) . ' ' . $languagePackExtensionKey . ' ' . LocalizationUtility::translate('wasInstalled', $this->extensionName);
         }
         $classCacheManager->reBuild();
     }
     return $content;
 }