61 lines
1.9 KiB
JavaScript
61 lines
1.9 KiB
JavaScript
import config from "../utils/config";
|
|
import api from "./apiutil";
|
|
import _ from "../utils/libs/core.min.js";
|
|
import { getToken } from "../utils/authUtil";
|
|
/* eslint-disable */
|
|
/*
|
|
Locale:
|
|
Methods
|
|
- This module is responsible for handling all localized text operations
|
|
- It stores a local in memory cache of the keys and returns them from cache whenever possible
|
|
- Method: Get keys one at a time or in an array
|
|
- a method that accepts lt keys and returns their text
|
|
- If a key is not in the cache here then it fetches it from the server
|
|
- Method: pre-fetch / Cache keys
|
|
- Used to pre-fetch a bunch of keys at once if necessary
|
|
- A caller will call this with the list of keys it will need in advance, the ones that are not present in the cache will be fetched from the server and the cache populated
|
|
- No text is actually returned at this point, it's just a pre-setup kind of thing to ensure better perf later
|
|
- Method: Clear cache
|
|
- Clear the local cache entirely
|
|
|
|
|
|
*/
|
|
|
|
const lt = {};
|
|
|
|
export default {
|
|
async Get(keys) {
|
|
this.PreFetch(keys);
|
|
//TODO: return they keys / lt array
|
|
},
|
|
async PreFetch(keys) {
|
|
//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])) {
|
|
NeedIt.push(keys[i]);
|
|
}
|
|
}
|
|
fetch(config.apiUrl + "locale/subset", {
|
|
method: "post",
|
|
mode: "cors",
|
|
headers: {
|
|
Accept: "application/json, text/plain, */*",
|
|
"Content-Type": "application/json",
|
|
Authorization: "Bearer " + getToken()
|
|
},
|
|
body: JSON.stringify(NeedIt)
|
|
})
|
|
.then(api.status)
|
|
.then(api.json)
|
|
|
|
.then(() => {
|
|
return Promise.resolve(true);
|
|
}) //succeeded, nothing to return
|
|
.catch(function(error) {
|
|
return Promise.reject(error);
|
|
});
|
|
},
|
|
ClearCache() {}
|
|
};
|