mastered translations

This commit is contained in:
2025-06-27 22:57:41 +02:00
parent 6ef4576cb2
commit f81fa50f27
6 changed files with 57 additions and 42 deletions

View File

@@ -0,0 +1,19 @@
export const translations = $state({
values: {}
})
export async function loadTranslation(lang){
var url = `${location.protocol}//${location.host.replace('5173','8080')}/api/translations/${lang}`;
translations.values = await fetch(url).then(resp => resp.json());
}
export function t(key){
var keys = key.split('.');
let set = translations.values;
for (let key of keys){
if (set[key]) {
set = set[key];
} else return key;
}
return set;
}