diff --git a/dev/Common/Translator.js b/dev/Common/Translator.js index a979eb817..ba9728276 100644 --- a/dev/Common/Translator.js +++ b/dev/Common/Translator.js @@ -3,7 +3,7 @@ import { Notification, UploadErrorCode } from 'Common/Enums'; import { langLink } from 'Common/Links'; import { doc, createElement } from 'Common/Globals'; -let I18N_DATA = window.snappymailI18N || {}; +let I18N_DATA = {}; export const trigger = ko.observable(false); @@ -49,10 +49,21 @@ const i18nToNode = element => { } }, + init = () => { + if (rl.I18N) { + I18N_DATA = rl.I18N; + Date.defineRelativeTimeFormat(rl.relativeTime || {}); + rl.I18N = null; + return 1; + } + }, + i18nKey = key => key.replace(/([a-z])([A-Z])/g, '$1_$2').toUpperCase(), getKeyByValue = (o, v) => Object.keys(o).find(key => o[key] === v); +init(); + /** * @param {Object} elements * @param {boolean=} animate = false @@ -127,13 +138,11 @@ export function reload(admin, language) { const script = createElement('script'); script.onload = () => { // reload the data - if (window.snappymailI18N) { - I18N_DATA = window.snappymailI18N; + if (init()) { i18nToNodes(doc); dispatchEvent(new CustomEvent('reload-time')); trigger(!trigger()); } - window.snappymailI18N = null; script.remove(); resolve(); }; diff --git a/dev/Common/Utils.js b/dev/Common/Utils.js index 89b55658a..359d92707 100644 --- a/dev/Common/Utils.js +++ b/dev/Common/Utils.js @@ -1,5 +1,5 @@ import { SaveSettingsStep } from 'Common/Enums'; -import { doc, createElement, elementById } from 'Common/Globals'; +import { doc, elementById } from 'Common/Globals'; export const isArray = Array.isArray, @@ -84,14 +84,13 @@ let __themeTimer = 0, * @returns {void} */ export function changeTheme(value, themeTrigger = ()=>{}) { - const themeLink = elementById('app-theme-link'), + const themeStyle = elementById('app-theme-style'), clearTimer = () => { __themeTimer = setTimeout(() => themeTrigger(SaveSettingsStep.Idle), 1000); __themeJson = null; }; - let themeStyle = elementById('app-theme-style'), - url = (themeLink && themeLink.href) || (themeStyle && themeStyle.dataset.href); + let url = themeStyle.dataset.href; if (url) { url = url.toString() @@ -118,19 +117,9 @@ export function changeTheme(value, themeTrigger = ()=>{}) { rl.fetchJSON(url, init) .then(data => { if (data && isArray(data) && 2 === data.length) { - if (themeLink && !themeStyle) { - themeStyle = createElement('style'); - themeStyle.id = 'app-theme-style'; - themeLink.after(themeStyle); - themeLink.remove(); - } - - if (themeStyle) { - themeStyle.textContent = data[1]; - themeStyle.dataset.href = url; - themeStyle.dataset.theme = data[0]; - } - + themeStyle.textContent = data[1]; + themeStyle.dataset.href = url; + themeStyle.dataset.theme = data[0]; themeTrigger(SaveSettingsStep.TrueResult); } }) diff --git a/dev/boot.js b/dev/boot.js index eca88cb51..3c09bf2e4 100644 --- a/dev/boot.js +++ b/dev/boot.js @@ -144,12 +144,7 @@ win.rl = { rl.hash.set(); if (appData) { - if (appData.NewThemeLink) { - eId('app-theme-link').href = appData.NewThemeLink; - } - loadScript(appData.StaticLibJsLink) - .then(() => loadScript(appData.LangLink)) .then(() => loadScript(appData.StaticAppJsLink)) .then(() => appData.PluginsLink ? loadScript(appData.PluginsLink) : Promise.resolve()) .then(() => win.__APP_BOOT ? win.__APP_BOOT(showError) : showError()) @@ -170,7 +165,7 @@ Storage('local'); // init section setInterval(setTimestamp, 60000); // 1m -[eId('app-css'),eId('app-theme-link')].forEach(css => css.href = css.dataset.href); +eId('app-css').href = eId('app-css').dataset.href; loadScript(`./?/${admin ? 'Admin' : ''}AppData/${rl.hash.get() || '0'}/${Math.random().toString().substr(2)}/`) .then(() => {}); diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions.php index 9e0513473..23662a735 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions.php @@ -508,12 +508,7 @@ class Actions public function GetSpecAuthTokenWithDeletion(): string { - $sResult = Utils::GetCookie(self::AUTH_SPEC_TOKEN_KEY, ''); - if (0 < strlen($sResult)) { - // TODO: Browser F5 issue - Utils::ClearCookie(self::AUTH_SPEC_TOKEN_KEY); - } - return $sResult; + return Utils::GetCookie(self::AUTH_SPEC_TOKEN_KEY, ''); } public function GetSpecAuthLogoutTokenWithDeletion(): string @@ -1252,7 +1247,6 @@ class Actions $sStaticCache = $this->StaticCache(); $aResult['Theme'] = $this->GetTheme($bAdmin); - $aResult['NewThemeLink'] = $this->ThemeLink($bAdmin); $aResult['Language'] = $this->ValidateLanguage($sLanguage, '', false); $aResult['UserLanguage'] = $this->ValidateLanguage($UserLanguageRaw, '', false, true); @@ -1260,8 +1254,6 @@ class Actions $aResult['LanguageAdmin'] = $this->ValidateLanguage($oConfig->Get('webmail', 'language_admin', 'en'), '', true); $aResult['UserLanguageAdmin'] = $this->ValidateLanguage($UserLanguageRaw, '', true, true); } - $aResult['LangLink'] = './?/Lang/0/' . ($bAdmin ? 'Admin' : 'App') . '/' . - ($bAdmin ? $aResult['LanguageAdmin'] : $aResult['Language']) . '/' . $sStaticCache . '/'; $aResult['PluginsLink'] = ''; if (0 < $this->Plugins()->Count() && $this->Plugins()->HaveJs($bAdmin)) { diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Localization.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Localization.php index 0d88e8c45..4661908da 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Localization.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Localization.php @@ -143,6 +143,6 @@ trait Localization } } - return "document.documentElement.lang = '{$sLanguage}';\nwindow.snappymailI18N={$sResult};\nDate.defineRelativeTimeFormat({$sTimeFormat});"; + return "document.documentElement.lang = '{$sLanguage}';\nrl.I18N={$sResult};\nrl.relativeTime = {$sTimeFormat};"; } } diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Service.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Service.php index 9ea8ddbd2..d9519f589 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Service.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Service.php @@ -158,26 +158,22 @@ class Service return $this; } - $aTemplateParameters = $this->indexTemplateParameters($bAdmin); + $this->oServiceActions->getAuthAccountHash($bAdmin); + $sLanguage = $this->oActions->GetLanguage($bAdmin); - // TODO: Browser F5 issue -// $this->oServiceActions->getAuthAccountHash($bAdmin); -// $sLanguage = $this->oActions->GetLanguage($bAdmin); + $aTemplateParameters = $this->indexTemplateParameters($bAdmin); $sCacheFileName = ''; if ($this->oActions->Config()->Get('labs', 'cache_system_data', true) && !empty($aTemplateParameters['{{BaseHash}}'])) { - // TODO: Browser F5 issue -// $sCacheFileName = 'TMPL:'.$sLanguage.$aTemplateParameters['{{BaseHash}}']; - $sCacheFileName = 'TMPL:'.$aTemplateParameters['{{BaseHash}}']; + $sCacheFileName = 'TMPL:'.$sLanguage.$aTemplateParameters['{{BaseHash}}']; $sResult = $this->oActions->Cacher()->Get($sCacheFileName); } if (0 === \strlen($sResult)) { -// $aTemplateParameters['{{BaseAppThemeCss}}'] = $this->oServiceActions->compileCss($this->oActions->GetTheme($bAdmin)); - // TODO: Browser F5 issue -// $aTemplateParameters['{{BaseLanguage}}'] = $this->oServiceActions->compileLanguage($sLanguage, $bAdmin); + $aTemplateParameters['{{BaseAppThemeCss}}'] = $this->oActions->compileCss($this->oActions->GetTheme($bAdmin), $bAdmin); + $aTemplateParameters['{{BaseLanguage}}'] = $this->oActions->compileLanguage($sLanguage, $bAdmin); $aTemplateParameters['{{BaseTemplates}}'] = $this->oServiceActions->compileTemplates($bAdmin, false); $sResult = \strtr(\file_get_contents(APP_VERSION_ROOT_PATH.'app/templates/Index.html'), $aTemplateParameters); diff --git a/snappymail/v/0.0.0/app/templates/Index.html b/snappymail/v/0.0.0/app/templates/Index.html index b37d1874d..35bd74a83 100644 --- a/snappymail/v/0.0.0/app/templates/Index.html +++ b/snappymail/v/0.0.0/app/templates/Index.html @@ -13,8 +13,8 @@