Clean up languages [skip ci]

This commit is contained in:
James Cole
2024-01-07 07:02:28 +01:00
parent 8043c86942
commit 0d2ae8ae23
76 changed files with 1355 additions and 1367 deletions

View File

@@ -18,16 +18,49 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
let loaded = false;
async function loadTranslations(i18n, locale) {
if (false === loaded) {
locale = locale.replace('-', '_');
const response = await fetch(`./v2/i18n/${locale}.json`);
const translations = await response.json();
i18n.store(translations);
import i18next from "i18next";
import ChainedBackend from "i18next-chained-backend";
import HttpBackend from "i18next-http-backend";
import LocalStorageBackend from "i18next-localstorage-backend";
let loaded = false;
let count = 0;
function loadTranslations(locale) {
if (false === loaded && 0 === count) {
console.log('Loading translations: ' + count);
const replacedLocale = locale.replace('-', '_');
loaded = true;
count++;
return i18next
.use(ChainedBackend)
.init({
fallbackLng: "en_US",
lng: replacedLocale,
debug: true,
// ... your i18next config
backend: {
backends: [
LocalStorageBackend,
HttpBackend
],
backendOptions: [{
expirationTime: 7 * 24 * 60 * 60 * 1000 // 7 days
}, {
// const response = await fetch(`./v2/i18n/${locale}.json`);
loadPath: './v2/i18n/{{lng}}.json'
}]
}
});
}
//loaded = true;
count++;
console.warn('Loading translations skipped because count is:' + count);
return Promise.resolve();
}
export {loadTranslations};