fetch edge messages

This commit is contained in:
Kyle Spearrin 2017-11-04 23:35:46 -04:00
parent bd109f4ed9
commit 4fb2d879ec
1 changed files with 11 additions and 20 deletions

View File

@ -1,27 +1,18 @@
export default function i18nService(utilsService) {
this.utilsService = utilsService;
this.messages = {};
if (utilsService.isEdge()) {
this.__edgeMessages = {};
const self = this;
fetch('../_locales/en/messages.json').then((file) => {
return file.json();
}).then((locales) => {
for (const prop in locales) {
if (locales.hasOwnProperty(prop)) {
self.__edgeMessages[prop] = chrome.i18n.getMessage(prop);
}
}
});
var self = this;
if (self.utilsService.isEdge()) {
var rawFile = new XMLHttpRequest();
rawFile.open('GET', '../_locales/en/messages.json', false);
rawFile.onreadystatechange = function () {
if (rawFile.readyState === 4) {
if (rawFile.status === 200 || rawFile.status === 0) {
var locales = JSON.parse(rawFile.responseText);
for (var property in locales) {
if (locales.hasOwnProperty(property)) {
self.messages[property] = chrome.i18n.getMessage(property);
}
}
}
}
};
rawFile.send(null);
return self.messages;
return this.__edgeMessages;
}
return new Proxy({}, {