}
function makeRequest (params) {
- const url = `${window.baseUrl}/api/l10n/index?${stringify(params)}`;
+ const url = '/api/l10n/index';
- return fetch(url, { credentials: 'same-origin' }).then(response => {
- if (response.status === 304) {
- return JSON.parse(localStorage.getItem('l10n.bundle'));
- } else if (response.status === 200) {
- return response.json();
- } else {
- throw new Error(response.status);
- }
- });
+ return request(url)
+ .setData(params)
+ .submit()
+ .then(response => {
+ if (response.status === 304) {
+ return JSON.parse(localStorage.getItem('l10n.bundle'));
+ } else if (response.status === 200) {
+ return response.json();
+ } else {
+ throw new Error(response.status);
+ }
+ });
}
+ function checkCachedBundle () {
+ const cached = localStorage.getItem('l10n.bundle');
+
+ if (!cached) {
+ return false;
+ }
+
+ try {
+ const parsed = JSON.parse(cached);
+ return parsed != null && typeof parsed === 'object';
+ } catch (e) {
+ return false;
+ }
+ }
+
export function requestMessages () {
const currentLocale = getCurrentLocale();
const cachedLocale = localStorage.getItem('l10n.locale');