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) { export default function i18nService(utilsService) {
this.utilsService = utilsService; if (utilsService.isEdge()) {
this.messages = {}; this.__edgeMessages = {};
const self = this;
var self = this; fetch('../_locales/en/messages.json').then((file) => {
return file.json();
if (self.utilsService.isEdge()) { }).then((locales) => {
var rawFile = new XMLHttpRequest(); for (const prop in locales) {
rawFile.open('GET', '../_locales/en/messages.json', false); if (locales.hasOwnProperty(prop)) {
rawFile.onreadystatechange = function () { self.__edgeMessages[prop] = chrome.i18n.getMessage(prop);
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({}, { return new Proxy({}, {