Index: Classes/ViewHelpers/TranslateViewHelper.php =================================================================== --- Classes/ViewHelpers/TranslateViewHelper.php (revision 483) +++ Classes/ViewHelpers/TranslateViewHelper.php (working copy) @@ -22,8 +22,6 @@ * @version $Id:$ */ class Tx_Fluid_ViewHelpers_TranslateViewHelper extends Tx_Fluid_Core_AbstractViewHelper { - protected static $initialized = FALSE; - /** * @var string */ @@ -34,7 +32,7 @@ * * @var string **/ - protected $LOCAL_LANG = array(); + protected static $LOCAL_LANG = array(); /** * Local Language content charset for individual labels (overriding) @@ -41,7 +39,7 @@ * * @var string **/ - protected $LOCAL_LANG_charset = array(); + protected static $LOCAL_LANG_charset = array(); /** * Key of the language to use @@ -48,7 +46,7 @@ * * @var string **/ - protected $languageKey = 'default'; + protected static $languageKey = 'default'; /** * Pointer to alternative fall-back language to use @@ -55,8 +53,15 @@ * * @var string **/ - protected $alternativeLanguageKey = ''; - + protected static $alternativeLanguageKey = ''; + + /** + * The extension name for which this instance of the view helper was called. + * + * @var string + */ + protected $extensionName = ''; + /** * Translate a given key or use the tag body as default. * @@ -66,9 +71,9 @@ * @author Christopher Hlubek */ public function render($key, $htmlEscape = FALSE) { - if (!self::$initialized) { + $this->extensionName = $this->variableContainer->get('view')->getRequest()->getExtensionName(); + if (!isset(self::$LOCAL_LANG[$this->extensionName])) { $this->initializeLocalization(); - self::$initialized = TRUE; } $defaultValue = $this->renderChildren(); $translation = $this->translate($key, $defaultValue, $htmlEscape); @@ -74,7 +79,7 @@ $translation = $this->translate($key, $defaultValue, $htmlEscape); return (is_string($translation) && !empty($translation)) ? $translation : ''; } - + /** * Loads local-language values by looking for a "locallang.php" 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.php" file. @@ -82,24 +87,28 @@ * @return void */ protected function initializeLocalization() { - $extensionName = $this->variableContainer->get('view')->getRequest()->getExtensionName(); - $languageFilePath = t3lib_extMgm::extPath(strtolower($extensionName)) . $this->languagePath . 'locallang.php'; + $languageFilePath = t3lib_extMgm::extPath(strtolower($this->extensionName)) . $this->languagePath . 'locallang.php'; if ($GLOBALS['TSFE']->config['config']['language']) { - $this->languageKey = $GLOBALS['TSFE']->config['config']['language']; + self::$languageKey = $GLOBALS['TSFE']->config['config']['language']; if ($GLOBALS['TSFE']->config['config']['language_alt']) { - $this->alternativeLanguageKey = $GLOBALS['TSFE']->config['config']['language_alt']; + self::$alternativeLanguageKey = $GLOBALS['TSFE']->config['config']['language_alt']; } } - $this->LOCAL_LANG = t3lib_div::readLLfile($languageFilePath, $this->languageKey, $GLOBALS['TSFE']->renderCharset); - if ($this->alternativeLanguageKey) { - $tempLOCAL_LANG = t3lib_div::readLLfile($languageFilePath, $this->alternativeLanguageKey); - $this->LOCAL_LANG = array_merge(is_array($this->LOCAL_LANG) ? $this->LOCAL_LANG : array(), $tempLOCAL_LANG); + self::$LOCAL_LANG[$this->extensionName] = t3lib_div::readLLfile($languageFilePath, self::$languageKey, $GLOBALS['TSFE']->renderCharset); + if (self::$alternativeLanguageKey) { + $tempLOCAL_LANG = t3lib_div::readLLfile($languageFilePath, self::$alternativeLanguageKey); + self::$LOCAL_LANG[$this->extensionName] = array_merge( + is_array(self::$LOCAL_LANG[$this->extensionName]) + ? self::$LOCAL_LANG[$this->extensionName] + : array(), + $tempLOCAL_LANG + ); } $configurationManager = t3lib_div::makeInstance('Tx_ExtBase_Configuration_Manager'); - $settings = $configurationManager->getSettings($extensionName); + $settings = $configurationManager->getSettings($this->extensionName); if (is_array($settings['_LOCAL_LANG'])) { foreach ($settings['_LOCAL_LANG'] as $k => $lA) { if (is_array($lA)) { @@ -105,9 +114,9 @@ if (is_array($lA)) { foreach($lA as $llK => $llV) { if (!is_array($llV)) { - $this->LOCAL_LANG[$k][$llK] = $llV; + self::$LOCAL_LANG[$this->extensionName][$k][$llK] = $llV; // For labels coming from the TypoScript (database) the charset is assumed to be "forceCharset" and if that is not set, assumed to be that of the individual system languages - $this->LOCAL_LANG_charset[$k][$llK] = $GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset'] ? $GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset'] : $GLOBALS['TSFE']->csConvObj->charSetArray[$k]; + self::$LOCAL_LANG_charset[$this->extensionName][$k][$llK] = $GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset'] ? $GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset'] : $GLOBALS['TSFE']->csConvObj->charSetArray[$k]; } } } @@ -114,7 +123,7 @@ } } } - + /** * Returns the localized label of the LOCAL_LANG key, $key * Notice that for debugging purposes prefixes for the output values can be set with the internal vars ->LLtestPrefixAlt and ->LLtestPrefix @@ -124,14 +133,14 @@ * @param boolean If true, the output label is passed through htmlspecialchars() * @return string The value from LOCAL_LANG. */ - function translate($key, $default = '', $filterTranslation = FALSE) { + protected function translate($key, $default = '', $filterTranslation = FALSE) { // The "from" charset of csConv() is only set for strings from TypoScript via _LOCAL_LANG - if (isset($this->LOCAL_LANG[$this->languageKey][$key])) { - $translation = $GLOBALS['TSFE']->csConv($this->LOCAL_LANG[$this->languageKey][$key], $this->LOCAL_LANG_charset[$this->languageKey][$key]); - } elseif ($this->alternativeLanguageKey && isset($this->LOCAL_LANG[$this->alternativeLanguageKey][$key])) { - $translation = $GLOBALS['TSFE']->csConv($this->LOCAL_LANG[$this->alternativeLanguageKey][$key], $this->LOCAL_LANG_charset[$this->alternativeLanguageKey][$key]); + if (isset(self::$LOCAL_LANG[$this->extensionName][self::$languageKey][$key])) { + $translation = $GLOBALS['TSFE']->csConv(self::$LOCAL_LANG[$this->extensionName][self::$languageKey][$key], self::$LOCAL_LANG_charset[$this->extensionName][self::$languageKey][$key]); + } elseif (self::$alternativeLanguageKey && isset(self::$LOCAL_LANG[$this->extensionName][self::$alternativeLanguageKey][$key])) { + $translation = $GLOBALS['TSFE']->csConv(self::$LOCAL_LANG[$this->extensionName][self::$alternativeLanguageKey][$key], self::$LOCAL_LANG_charset[$this->extensionName][self::$alternativeLanguageKey][$key]); } elseif (isset($this->LOCAL_LANG['default'][$key])) { - $translation = $this->LOCAL_LANG['default'][$key]; // No charset conversion because default is english and thereby ASCII + $translation = self::$LOCAL_LANG[$this->extensionName]['default'][$key]; // No charset conversion because default is english and thereby ASCII } else { $translation = $default; }