/**
     * @test
     */
    public function getParsedDataHandlesLocallangXMLOverride()
    {
        /** @var $subject LocalizationFactory */
        $subject = new LocalizationFactory();
        $unique = 'locallangXMLOverrideTest' . substr($this->getUniqueId(), 0, 10);
        $xml = '<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
			<T3locallang>
				<data type="array">
					<languageKey index="default" type="array">
						<label index="buttons.logout">EXIT</label>
					</languageKey>
				</data>
			</T3locallang>';
        $file = PATH_site . 'typo3temp/' . $unique . '.xml';
        GeneralUtility::writeFileToTypo3tempDir($file, $xml);
        // Make sure there is no cached version of the label
        GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->getCache('l10n')->flush();
        // Get default value
        $defaultLL = $subject->getParsedData('EXT:lang/locallang_core.xlf', 'default', 'utf-8', 0);
        // Clear language cache again
        GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->getCache('l10n')->flush();
        // Set override file
        $GLOBALS['TYPO3_CONF_VARS']['SYS']['locallangXMLOverride']['EXT:lang/locallang_core.xlf'][$unique] = $file;
        /** @var $store \TYPO3\CMS\Core\Localization\LanguageStore */
        $store = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Localization\\LanguageStore');
        $store->flushData('EXT:lang/locallang_core.xlf');
        // Get override value
        $overrideLL = $subject->getParsedData('EXT:lang/locallang_core.xlf', 'default', 'utf-8', 0);
        // Clean up again
        unlink($file);
        $this->assertNotEquals($overrideLL['default']['buttons.logout'][0]['target'], '');
        $this->assertNotEquals($defaultLL['default']['buttons.logout'][0]['target'], $overrideLL['default']['buttons.logout'][0]['target']);
        $this->assertEquals($overrideLL['default']['buttons.logout'][0]['target'], 'EXIT');
    }
Ejemplo n.º 2
0
 /**
  * Returns parsed data from a given file and language key.
  *
  * @param string $fileReference Input is a file-reference (see \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName). That file is expected to be a supported locallang file format
  * @param string $languageKey Language key
  * @param string $charset Character set (option); if not set, determined by the language key
  * @param integer $errorMode Error mode (when file could not be found): 0 - syslog entry, 1 - do nothing, 2 - throw an exception
  * @param boolean $isLocalizationOverride TRUE if $fileReference is a localization override
  * @return array|boolean
  */
 public function getParsedData($fileReference, $languageKey, $charset, $errorMode, $isLocalizationOverride = FALSE)
 {
     $data = parent::getParsedData($fileReference, $languageKey, $charset, $errorMode, $isLocalizationOverride);
     if (FALSE === $this->isWhitelisted($fileReference) || TRUE === $this->isBlacklisted($fileReference)) {
         return $data;
     }
     $proxy = LanguageFileUtility::createProxyForFile($fileReference, (array) $data);
     return array($languageKey => $proxy);
 }
Ejemplo n.º 3
0
 /**
  * Loads the initially defined local lang file
  *
  * @return void
  */
 protected function loadLL()
 {
     $configuration = Util::getSolrConfiguration();
     $this->localLang[$this->languageFile] = $this->languageFactory->getParsedData($this->languageFile, $this->llKey, $GLOBALS['TSFE']->renderCharset, 3);
     $localLangConfiguration = $configuration->getLocalLangConfiguration();
     if (count($localLangConfiguration) == 0) {
         return;
     }
     // Overlaying labels from TypoScript (including fictitious language keys for non-system languages!):
     foreach ($localLangConfiguration as $language => $overrideLabels) {
         $language = substr($language, 0, -1);
         if (is_array($overrideLabels)) {
             foreach ($overrideLabels as $labelKey => $overrideLabel) {
                 if (!is_array($overrideLabel)) {
                     $this->localLang[$this->languageFile][$language][$labelKey] = array(array('source' => $overrideLabel));
                 }
             }
         }
     }
 }
Ejemplo n.º 4
0
 /**
  * Loads the initially defined local lang file
  *
  * @return void
  */
 protected function loadLL()
 {
     $configuration = $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_solr.'];
     $this->localLang[$this->languageFile] = $this->languageFactory->getParsedData($this->languageFile, $this->llKey, $GLOBALS['TSFE']->renderCharset, 3);
     // Overlaying labels from TypoScript (including fictitious language keys for non-system languages!):
     if (is_array($configuration['_LOCAL_LANG.'])) {
         foreach ($configuration['_LOCAL_LANG.'] as $language => $overrideLabels) {
             $language = substr($language, 0, -1);
             if (is_array($overrideLabels)) {
                 foreach ($overrideLabels as $labelKey => $overrideLabel) {
                     if (!is_array($overrideLabel)) {
                         $this->localLang[$this->languageFile][$language][$labelKey] = array(array('source' => $overrideLabel));
                     }
                 }
             }
         }
     }
 }
Ejemplo n.º 5
0
 /**
  * Overwrites pi_loadLL() to handle custom location of language files.
  *
  * Loads local-language values by looking for a "locallang" file in the
  * plugin class directory ($this->scriptRelPath) and if found includes it.
  * Also locallang values set in the TypoScript property "_LOCAL_LANG" are
  * merged onto the values found in the "locallang" file.
  * Supported file extensions xlf, xml, php
  *
  * @param string $languageFilePath path to the plugin language file in format EXT:....
  * @return void
  */
 public function pi_loadLL($languageFilePath = '')
 {
     if (!$this->LOCAL_LANG_loaded && $this->scriptRelPath) {
         $pathElements = pathinfo($this->scriptRelPath);
         $languageFileName = $pathElements['filename'];
         $basePath = 'EXT:' . $this->extKey . '/Resources/Private/Language/locallang.xlf';
         // Read the strings in the required charset (since TYPO3 4.2)
         $this->LOCAL_LANG = $this->languageFactory->getParsedData($basePath, $this->LLkey, $GLOBALS['TSFE']->renderCharset, 3);
         $alternativeLanguageKeys = GeneralUtility::trimExplode(',', $this->altLLkey, true);
         foreach ($alternativeLanguageKeys as $languageKey) {
             $tempLL = $this->languageFactory->getParsedData($basePath, $languageKey, $GLOBALS['TSFE']->renderCharset, 3);
             if ($this->LLkey !== 'default' && isset($tempLL[$languageKey])) {
                 $this->LOCAL_LANG[$languageKey] = $tempLL[$languageKey];
             }
         }
         // Overlaying labels from TypoScript (including fictitious language keys for non-system languages!):
         $translationInTypoScript = $this->typoScriptConfiguration->getLocalLangConfiguration();
         if (count($translationInTypoScript) == 0) {
             return;
         }
         // Clear the "unset memory"
         $this->LOCAL_LANG_UNSET = array();
         foreach ($translationInTypoScript as $languageKey => $languageArray) {
             // Remove the dot after the language key
             $languageKey = substr($languageKey, 0, -1);
             // Don't process label if the language is not loaded
             if (is_array($languageArray) && isset($this->LOCAL_LANG[$languageKey])) {
                 foreach ($languageArray as $labelKey => $labelValue) {
                     if (!is_array($labelValue)) {
                         $this->LOCAL_LANG[$languageKey][$labelKey][0]['target'] = $labelValue;
                         $this->LOCAL_LANG_charset[$languageKey][$labelKey] = 'utf-8';
                         if ($labelValue === '') {
                             $this->LOCAL_LANG_UNSET[$languageKey][$labelKey] = '';
                         }
                     }
                 }
             }
         }
     }
     $this->LOCAL_LANG_loaded = 1;
 }
Ejemplo n.º 6
0
 /**
  * This test will make sure method \TYPO3\CMS\Core\Utility\GeneralUtility::llXmlAutoFileName() will not prefix twice the
  * language key to the localization file.
  *
  * @test
  */
 public function canOverrideXliffWithFrenchOnly()
 {
     /** @var $factory LocalizationFactory */
     $factory = new LocalizationFactory();
     $GLOBALS['TYPO3_CONF_VARS']['SYS']['locallangXMLOverride']['fr'][$this->xliffFileNames['locallang']][] = $this->xliffFileNames['locallang_override_fr'];
     $LOCAL_LANG = $factory->getParsedData($this->xliffFileNames['locallang'], 'fr');
     $this->assertArrayHasKey('fr', $LOCAL_LANG, 'fr key not found in $LOCAL_LANG');
     $expectedLabels = array('label1' => 'Ceci est mon 1er libellé', 'label2' => 'Ceci est le libellé no. 2', 'label3' => 'Ceci est mon 3e libellé');
     foreach ($expectedLabels as $key => $expectedLabel) {
         $this->assertEquals($expectedLabel, $LOCAL_LANG['fr'][$key][0]['target']);
     }
 }