Compare commits

...

2 Commits

Author SHA1 Message Date
b7c97ead2b Merge pull request 'Reactive Translations' (#86) from tonitch/front/Reactive_Translations into master
All checks were successful
Build and test backend / Build-backend (push) Successful in 2m8s
Build and test backend / Test-backend (push) Successful in 1m21s
deploy to production / deploy-frontend (push) Successful in 25s
deploy to production / deploy-backend (push) Successful in 2m19s
Build and test FrontEnd / Build-frontend (push) Successful in 25s
Reviewed-on: #86
Reviewed-by: Maxime <231026@umons.ac.be>
Reviewed-by: Wal <karpinskiwal@gmail.com>
2024-03-10 20:35:32 +01:00
84fe1df671 Reactive Translations
All checks were successful
Build and test backend / Build-backend (pull_request) Successful in 1m59s
Build and test backend / Test-backend (pull_request) Successful in 2m1s
Build and test FrontEnd / Build-frontend (pull_request) Successful in 23s
Make Translated text reactive so that when switching lang, text is
reload on the fly

Fixes: #77
2024-03-09 19:14:57 +01:00

View File

@ -10,9 +10,10 @@
*/
import { getCookie, setCookie } from './utils.js';
import { reactive } from 'vue';
const default_lang = "EN";
let langs;
const langs = reactive({});
/**
@ -27,8 +28,8 @@ let langs;
export default function i18n(key, options) {
let ret = langs[key];
if(options != null){
for (let key in options) {
ret = ret.replaceAll("$" + key, options[key]);
for (let option in options) {
ret = ret.replaceAll("$" + option, options[option]);
}
}
return ret;
@ -47,14 +48,12 @@ export async function loadLangs(lang){
const content = await (await fetch(filename)).text();
const lines = content.split("\n");
let filteredLines = {};
for (let line of lines) {
if(!line.trim().startsWith("#") && line.trim() != ""){
let split = line.indexOf("=")
filteredLines[line.substr(0, split)] = line.substr(split+1, line.length);
langs[line.substr(0, split)] = line.substr(split+1, line.length);
};
}
langs = filteredLines;
}
await loadLangs();