[TASK] Refactor TYPO3.l10n localize handling
authorLaurent Cherpit <laurent.cherpit@gmail.com>
Sat, 9 Jul 2011 20:41:14 +0000 (22:41 +0200)
committerXavier Perseguers <typo3@perseguers.ch>
Sun, 10 Jul 2011 14:00:54 +0000 (16:00 +0200)
- Change inclusion Order of the sysext/lang/res/js/be/typo3lang.js jsFile.
- Change TYPO3.l10n to sanitize TYPO3.lang array to store only string on it.
  Therefore use a private array to store a copy of lang objects with will
  be accessed via TYPO3.l10n.localize.

Change-Id: Ie05cd5baf39d8366328f8aa6193e39816721ee1c
Resolves: #28057
Reviewed-on: http://review.typo3.org/3227
Reviewed-by: Sebastian Kurfuerst
Tested-by: Sebastian Kurfuerst
Reviewed-by: Philipp Gampe
Tested-by: Philipp Gampe
Reviewed-by: Xavier Perseguers
Tested-by: Xavier Perseguers
t3lib/class.t3lib_pagerenderer.php
typo3/sysext/lang/res/js/be/typo3lang.js

index 265dc1a..eb5fa24 100644 (file)
@@ -1735,11 +1735,6 @@ class t3lib_PageRenderer implements t3lib_Singleton {
                }
                unset($this->inlineLanguageLabelFiles);
 
-                       // Include TYPO3.l18n object
-               if (TYPO3_MODE === 'BE') {
-                       $out .= '<script src="' . $this->processJsFile($this->backPath . 'sysext/lang/res/js/be/typo3lang.js') . '" type="text/javascript" charset="utf-8"></script>' . LF;
-               }
-
                        // Convert labels/settings back to UTF-8 since json_encode() only works with UTF-8:
                if ($this->getCharSet() !== 'utf-8') {
                        if ($this->inlineLanguageLabels) {
@@ -1771,6 +1766,11 @@ class t3lib_PageRenderer implements t3lib_Singleton {
                                        ' });' . $this->inlineJavascriptWrap[1];
                        unset ($this->extOnReadyCode);
 
+                               // Include TYPO3.l10n object
+                       if (TYPO3_MODE === 'BE') {
+                               $out .= '<script src="' . $this->processJsFile($this->backPath . 'sysext/lang/res/js/be/typo3lang.js') . '" type="text/javascript" charset="utf-8"></script>' . LF;
+                       }
+
                        if ($this->extJStheme) {
                                if (isset($GLOBALS['TBE_STYLES']['extJS']['theme'])) {
                                        $this->addCssFile($this->backPath . $GLOBALS['TBE_STYLES']['extJS']['theme'], 'stylesheet', 'all', '', TRUE, TRUE);
index 1cf5398..85cc526 100644 (file)
@@ -2,6 +2,7 @@
  *  Copyright notice
  *
  *  (c) 2010 Dominique Feyer <dominique.feyer@reelpeek.net>
+ *  Laurent Cherpit <laurent.cherpit@gmail.com>
  *  All rights reserved
  *
  *  This script is part of the TYPO3 project. The TYPO3 project is
 
 Ext.ns('TYPO3.l10n');
 
-TYPO3.l10n = {
+TYPO3.l10n = function() {
 
-       localize: function(label, replace, plural) {
-               if (typeof TYPO3.lang === 'undefined' || typeof TYPO3.lang[label] === 'undefined') return false;
+       /**
+        * Protected copy of translationUnits
+        * @private
+        */
+       var lang = [],
 
-               var i = plural || 0,
-                               translationUnit = TYPO3.lang[label],
-                               label = null, regexp = null;
+       sanitize = function() {
+               if (typeof TYPO3.lang !== 'undefined') {
+                       for (key in TYPO3.lang) {
+                               lang[key] = TYPO3.lang[key];
 
-               // Get localized label
-               if (Ext.isString(translationUnit)) {
-                       label = translationUnit;
-               } else {
-                       label = translationUnit[i]['target'];
+                               if (!Ext.isString(TYPO3.lang[key])) {
+                                       TYPO3.lang[key] = TYPO3.lang[key][0].target;
+                               }
+                       }
                }
+       };
+
+       return {
+
+               initialize: function() {
+                       sanitize();
+               },
+
+               localize: function(label, replace, plural) {
+                       if (typeof lang === 'undefined' || typeof lang[label] === 'undefined') return false;
+
+                       var i = plural || 0,
+                                       translationUnit = lang[label],
+                                       label = null, regexp = null;
 
-               // Replace
-               if (typeof replace !== 'undefined') {
-                       for (key in replace) {
-                               regexp = new RegExp('%' + key + '|%s');
-                               label = label.replace(regexp, replace[key]);
+                       // Get localized label
+                       if (Ext.isString(translationUnit)) {
+                               label = translationUnit;
+                       } else {
+                               label = translationUnit[i]['target'];
+                       }
+
+                       // Replace
+                       if (typeof replace !== 'undefined') {
+                               for (key in replace) {
+                                       regexp = new RegExp('%' + key + '|%s');
+                                       label = label.replace(regexp, replace[key]);
+                               }
                        }
-               }
 
-               return label;
-       }
+                       return label;
+               }
+       };
+}();
 
-}
\ No newline at end of file
+TYPO3.l10n.initialize();