Index: typo3/backend.php =================================================================== --- typo3/backend.php (Revision 10086) +++ typo3/backend.php (Arbeitskopie) @@ -120,6 +120,7 @@ // add default BE javascript $this->js = ''; $this->jsFiles = array( + 'locallang' => $this->getLocalLangFileName(), 'modernizr' => 'contrib/modernizr/modernizr.min.js', 'swfupload' => 'contrib/swfupload/swfupload.js', 'swfupload.swfobject' => 'contrib/swfupload/plugins/swfupload.swfobject.js', @@ -412,6 +413,134 @@ } /** + * Returns the file name to the LLL JavaScript, containing the localized labels, + * which can be used in JavaScript code. + * + * @return string File name of the JS file, relative to TYPO3_mainDir + */ + protected function getLocalLangFileName() { + $code = $this->generateLocalLang(); + $filePath = 'typo3temp/locallang-BE-' . sha1($code) . '.js'; + if (!file_exists(PATH_site . $filePath)) { + // writeFileToTypo3tempDir() returns NULL on success (please double-read!) + if (t3lib_div::writeFileToTypo3tempDir(PATH_site . $filePath, $code) !== NULL) { + throw new RuntimeException('LocalLangFile could not be written to ' . $filePath, 1295193026); + } + } + return '../' . $filePath; + } + + /** + * Reads labels required in JavaScript code from the localization system and returns them as JSON + * array in TYPO3.LLL. + * + * @return string JavaScript code containing the LLL labels in TYPO3.LLL + */ + protected function generateLocalLang() { + $coreLabels = array( + 'waitTitle' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_logging_in') , + 'refresh_login_failed' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_failed'), + 'refresh_login_failed_message' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_failed_message'), + 'refresh_login_title' => sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_title'), htmlspecialchars($GLOBALS['BE_USER']->user['username'])), + 'login_expired' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.login_expired'), + 'refresh_login_username' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_username'), + 'refresh_login_password' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_password'), + 'refresh_login_emptyPassword' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_emptyPassword'), + 'refresh_login_button' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_button'), + 'refresh_logout_button' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_logout_button'), + 'please_wait' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.please_wait'), + 'loadingIndicator' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:loadingIndicator'), + 'be_locked' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.be_locked'), + 'refresh_login_countdown_singular' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_countdown_singular'), + 'refresh_login_countdown' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_countdown'), + 'login_about_to_expire' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.login_about_to_expire'), + 'login_about_to_expire_title' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.login_about_to_expire_title'), + 'refresh_login_refresh_button' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_refresh_button'), + 'refresh_direct_logout_button' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_direct_logout_button'), + 'tabs_closeAll' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:tabs.closeAll'), + 'tabs_closeOther' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:tabs.closeOther'), + 'tabs_close' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:tabs.close'), + 'tabs_openInBrowserWindow' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:tabs.openInBrowserWindow'), + 'donateWindow_title' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:donateWindow.title'), + 'donateWindow_message' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:donateWindow.message'), + 'donateWindow_button_donate' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:donateWindow.button_donate'), + 'donateWindow_button_disable' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:donateWindow.button_disable'), + 'donateWindow_button_postpone' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:donateWindow.button_postpone'), + 'csh_tooltip_loading' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:csh_tooltip_loading'), + ); + + $labels = array( + 'fileUpload' => array( + 'windowTitle', + 'buttonSelectFiles', + 'buttonStartUpload', + 'buttonCancelAll', + 'progressText', + 'infoComponentMaxFileSize', + 'infoComponentFileUploadLimit', + 'infoComponentFileTypeLimit', + 'infoComponentOverrideFiles', + 'infoFileQueueEmpty', + 'infoFileQueued', + 'infoFileFinished', + 'infoFileUploading', + 'processRunning', + 'uploadWait', + 'uploadStarting', + 'uploadProgress', + 'uploadSuccess', + 'errorQueueLimitExceeded', + 'errorQueueFileSizeLimit', + 'errorQueueZeroByteFile', + 'errorQueueInvalidFiletype', + 'errorUploadHttp', + 'errorUploadMissingUrl', + 'errorUploadIO', + 'errorUploadSecurityError', + 'errorUploadLimit', + 'errorUploadFailed', + 'errorUploadFileIDNotFound', + 'errorUploadFileValidation', + 'errorUploadFileCancelled', + 'errorUploadStopped', + 'allErrorMessageTitle', + 'allErrorMessageText', + 'allError401', + 'allError2038', + ), + 'liveSearch' => array( + 'title', + 'helpTitle', + 'emptyText', + 'loadingText', + 'listEmptyText', + 'showAllResults', + 'helpDescription', + 'helpDescriptionPages', + 'helpDescriptionContent', + ), + ); + $generatedLabels = array(); + $generatedLabels['core'] = $coreLabels; + + // first loop over all categories (fileUpload, liveSearch, ..) + foreach ($labels as $categoryName => $categoryLabels) { + // then loop over every single label + foreach ($categoryLabels as $label) { + // LLL identifier must be called $categoryName_$label, e.g. liveSearch_loadingText + $generatedLabels[$categoryName][$label] = $GLOBALS['LANG']->getLL($categoryName . '_' . $label); + } + } + + // Convert labels/settings back to UTF-8 since json_encode() only works with UTF-8: + if ($GLOBALS['LANG']->charSet !== 'utf-8') { + $GLOBALS['LANG']->csConvObj->convArray($generatedLabels, $GLOBALS['LANG']->charSet, 'utf-8'); + } + + return 'TYPO3.LLL = ' . json_encode($generatedLabels) . ';'; + } + + /** * Generates the JavaScript code for the backend. * * @return void @@ -466,101 +595,12 @@ 'maxFileSize' => t3lib_div::getMaxUploadFileSize() ) ); - $t3LLLcore = array( - 'waitTitle' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_logging_in') , - 'refresh_login_failed' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_failed'), - 'refresh_login_failed_message' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_failed_message'), - 'refresh_login_title' => sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_title'), htmlspecialchars($GLOBALS['BE_USER']->user['username'])), - 'login_expired' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.login_expired'), - 'refresh_login_username' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_username'), - 'refresh_login_password' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_password'), - 'refresh_login_emptyPassword' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_emptyPassword'), - 'refresh_login_button' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_button'), - 'refresh_logout_button' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_logout_button'), - 'please_wait' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.please_wait'), - 'loadingIndicator' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:loadingIndicator'), - 'be_locked' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.be_locked'), - 'refresh_login_countdown_singular' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_countdown_singular'), - 'refresh_login_countdown' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_countdown'), - 'login_about_to_expire' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.login_about_to_expire'), - 'login_about_to_expire_title' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.login_about_to_expire_title'), - 'refresh_login_refresh_button' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_login_refresh_button'), - 'refresh_direct_logout_button' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:mess.refresh_direct_logout_button'), - 'tabs_closeAll' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:tabs.closeAll'), - 'tabs_closeOther' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:tabs.closeOther'), - 'tabs_close' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:tabs.close'), - 'tabs_openInBrowserWindow' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:tabs.openInBrowserWindow'), - 'donateWindow_title' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:donateWindow.title'), - 'donateWindow_message' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:donateWindow.message'), - 'donateWindow_button_donate' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:donateWindow.button_donate'), - 'donateWindow_button_disable' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:donateWindow.button_disable'), - 'donateWindow_button_postpone' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:donateWindow.button_postpone'), - 'csh_tooltip_loading' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:csh_tooltip_loading'), - ); - $t3LLLfileUpload = array( - 'windowTitle' => $GLOBALS['LANG']->getLL('fileUpload_windowTitle'), - 'buttonSelectFiles' => $GLOBALS['LANG']->getLL('fileUpload_buttonSelectFiles'), - 'buttonStartUpload' => $GLOBALS['LANG']->getLL('fileUpload_buttonStartUpload'), - 'buttonCancelAll' => $GLOBALS['LANG']->getLL('fileUpload_buttonCancelAll'), - 'progressText' => $GLOBALS['LANG']->getLL('fileUpload_progressText'), - 'infoComponentMaxFileSize' => $GLOBALS['LANG']->getLL('fileUpload_infoComponentMaxFileSize'), - 'infoComponentFileUploadLimit' => $GLOBALS['LANG']->getLL('fileUpload_infoComponentFileUploadLimit'), - 'infoComponentFileTypeLimit' => $GLOBALS['LANG']->getLL('fileUpload_infoComponentFileTypeLimit'), - 'infoComponentOverrideFiles' => $GLOBALS['LANG']->getLL('fileUpload_infoComponentOverrideFiles'), - 'infoFileQueueEmpty' => $GLOBALS['LANG']->getLL('fileUpload_infoFileQueueEmpty'), - 'infoFileQueued' => $GLOBALS['LANG']->getLL('fileUpload_infoFileQueued'), - 'infoFileFinished' => $GLOBALS['LANG']->getLL('fileUpload_infoFileFinished'), - 'infoFileUploading' => $GLOBALS['LANG']->getLL('fileUpload_infoFileQueued'), - 'processRunning' => $GLOBALS['LANG']->getLL('fileUpload_processRunning'), - 'uploadWait' => $GLOBALS['LANG']->getLL('fileUpload_uploadWait'), - 'uploadStarting' => $GLOBALS['LANG']->getLL('fileUpload_uploadStarting'), - 'uploadProgress' => $GLOBALS['LANG']->getLL('fileUpload_uploadProgress'), - 'uploadSuccess' => $GLOBALS['LANG']->getLL('fileUpload_uploadSuccess'), - 'errorQueueLimitExceeded' => $GLOBALS['LANG']->getLL('fileUpload_errorQueueLimitExceeded'), - 'errorQueueFileSizeLimit' => $GLOBALS['LANG']->getLL('fileUpload_errorQueueFileSizeLimit'), - 'errorQueueZeroByteFile' => $GLOBALS['LANG']->getLL('fileUpload_errorQueueZeroByteFile'), - 'errorQueueInvalidFiletype' => $GLOBALS['LANG']->getLL('fileUpload_errorQueueInvalidFiletype'), - 'errorUploadHttp' => $GLOBALS['LANG']->getLL('fileUpload_errorUploadHttpError'), - 'errorUploadMissingUrl' => $GLOBALS['LANG']->getLL('fileUpload_errorUploadMissingUrl'), - 'errorUploadIO' => $GLOBALS['LANG']->getLL('fileUpload_errorUploadIO'), - 'errorUploadSecurityError' => $GLOBALS['LANG']->getLL('fileUpload_errorUploadSecurityError'), - 'errorUploadLimit' => $GLOBALS['LANG']->getLL('fileUpload_errorUploadLimit'), - 'errorUploadFailed' => $GLOBALS['LANG']->getLL('fileUpload_errorUploadFailed'), - 'errorUploadFileIDNotFound' => $GLOBALS['LANG']->getLL('fileUpload_errorUploadFileIDNotFound'), - 'errorUploadFileValidation' => $GLOBALS['LANG']->getLL('fileUpload_errorUploadFileValidation'), - 'errorUploadFileCancelled' => $GLOBALS['LANG']->getLL('fileUpload_errorUploadFileCancelled'), - 'errorUploadStopped' => $GLOBALS['LANG']->getLL('fileUpload_errorUploadStopped'), - 'allErrorMessageTitle' => $GLOBALS['LANG']->getLL('fileUpload_allErrorMessageTitle'), - 'allErrorMessageText' => $GLOBALS['LANG']->getLL('fileUpload_allErrorMessageText'), - 'allError401' => $GLOBALS['LANG']->getLL('fileUpload_allError401'), - 'allError2038' => $GLOBALS['LANG']->getLL('fileUpload_allError2038'), - ); - $t3LLLliveSearch = array( - 'title' => $GLOBALS['LANG']->getLL('liveSearch_title'), - 'helpTitle' => $GLOBALS['LANG']->getLL('liveSearch_helpTitle'), - 'emptyText' => $GLOBALS['LANG']->getLL('liveSearch_emptyText'), - 'loadingText' => $GLOBALS['LANG']->getLL('liveSearch_loadingText'), - 'listEmptyText' => $GLOBALS['LANG']->getLL('liveSearch_listEmptyText'), - 'showAllResults' => $GLOBALS['LANG']->getLL('liveSearch_showAllResults'), - 'helpDescription' => $GLOBALS['LANG']->getLL('liveSearch_helpDescription'), - 'helpDescriptionPages' => $GLOBALS['LANG']->getLL('liveSearch_helpDescriptionPages'), - 'helpDescriptionContent' => $GLOBALS['LANG']->getLL('liveSearch_helpDescriptionContent') - ); - // Convert labels/settings back to UTF-8 since json_encode() only works with UTF-8: if ($GLOBALS['LANG']->charSet !== 'utf-8') { $t3Configuration['username'] = $GLOBALS['LANG']->csConvObj->conv($t3Configuration['username'], $GLOBALS['LANG']->charSet, 'utf-8'); - $GLOBALS['LANG']->csConvObj->convArray($t3LLLcore, $GLOBALS['LANG']->charSet, 'utf-8'); - $GLOBALS['LANG']->csConvObj->convArray($t3LLLfileUpload, $GLOBALS['LANG']->charSet, 'utf-8'); - $GLOBALS['LANG']->csConvObj->convArray($t3LLLliveSearch, $GLOBALS['LANG']->charSet, 'utf-8'); } $this->js .= ' TYPO3.configuration = ' . json_encode($t3Configuration) . '; - TYPO3.LLL = { - core : ' . json_encode($t3LLLcore) . ', - fileUpload: ' . json_encode($t3LLLfileUpload) . ', - liveSearch: ' . json_encode($t3LLLliveSearch) . ' - }; /** * TypoSetup object.