mirror of
https://github.com/the-djmaze/snappymail.git
synced 2024-11-13 02:55:24 +08:00
Cleanup language loader
This commit is contained in:
parent
b68d04aacd
commit
0528bcf911
1 changed files with 17 additions and 30 deletions
|
@ -218,36 +218,23 @@ export function getUploadErrorDescByCode(code) {
|
||||||
* @param {string} language
|
* @param {string} language
|
||||||
*/
|
*/
|
||||||
export function reload(admin, language) {
|
export function reload(admin, language) {
|
||||||
const start = Date.now();
|
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
return fetch(langLink(language, admin), {cache: 'reload'})
|
const script = doc.createElement('script');
|
||||||
.then(response => {
|
script.onload = () => {
|
||||||
if (response.ok && response.headers.get('Content-Type').includes('application/javascript')) {
|
// reload the data
|
||||||
return response.text();
|
if (window.rainloopI18N) {
|
||||||
}
|
I18N_DATA = window.rainloopI18N || {};
|
||||||
reject(new Error('Invalid response'))
|
i18nToNodes(doc);
|
||||||
}, error => {
|
dispatchEvent(new CustomEvent('reload-time'));
|
||||||
reject(new Error(error.message))
|
trigger(!trigger());
|
||||||
})
|
}
|
||||||
.then(data => {
|
window.rainloopI18N = null;
|
||||||
var script = doc.createElement('script');
|
script.remove();
|
||||||
script.text = data;
|
resolve();
|
||||||
doc.head.appendChild(script).remove();
|
};
|
||||||
setTimeout(
|
script.onerror = () => reject(new Error('Language '+language+' failed'));
|
||||||
() => {
|
script.src = langLink(language, admin);
|
||||||
// reload the data
|
// script.async = true;
|
||||||
if (window.rainloopI18N) {
|
doc.head.append(script);
|
||||||
I18N_DATA = window.rainloopI18N || {};
|
|
||||||
i18nToNodes(doc);
|
|
||||||
dispatchEvent(new CustomEvent('reload-time'));
|
|
||||||
trigger(!trigger());
|
|
||||||
}
|
|
||||||
window.rainloopI18N = null;
|
|
||||||
resolve();
|
|
||||||
},
|
|
||||||
500 < Date.now() - start ? 1 : 500
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue