mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-12-15 19:09:50 +00:00
Clean up languages [skip ci]
This commit is contained in:
@@ -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};
|
||||
|
||||
Reference in New Issue
Block a user