This commit is contained in:
2018-11-13 22:44:16 +00:00
parent 15daaebab9
commit a31093d50d
4 changed files with 12 additions and 20 deletions

View File

@@ -1,25 +1,22 @@
/* xeslint-disable */
import store from "../store";
import config from "../utils/config";
import api from "./apiutil";
import _ from "../utils/libs/core.min.js";
//Keep the localized text keys here temporarily
//TODO: rehydrate on page refresh / put in sessionstorage
var lt = {};
export default {
get(key) {
if (!_.has(lt, key)) {
if (!_.has(store.state.localeText, key)) {
return "?" + key + "?";
}
return lt[key];
return store.state.localeText[key];
},
fetch(keys) {
return new Promise(function(resolve, reject) {
//step 1: build an array of keys that we don't have already
var NeedIt = [];
for (var i = 0; i < keys.length; i++) {
if (!_.has(lt, keys[i])) {
if (!_.has(store.state.localeText, keys[i])) {
NeedIt.push(keys[i]);
}
}
@@ -31,18 +28,13 @@ export default {
method: "post",
mode: "cors",
headers: api.AuthorizedHeaders(),
// headers: {
// Accept: "application/json, text/plain, */*",
// "Content-Type": "application/json",
// Authorization: "Bearer " + getToken()
// },
body: JSON.stringify(NeedIt)
})
.then(api.status)
.then(api.json)
.then(response => {
_.forEach(response.data, function(item) {
lt[item.key] = item.value;
store.commit("addLocaleText", item);
});
resolve();
})
@@ -50,8 +42,5 @@ export default {
reject(error);
});
});
},
clearCache() {
lt = {};
}
};