You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
22 lines
665 B
22 lines
665 B
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,...args){ |
|
let set = translations.values; |
|
let keys = key.split('.'); |
|
for (let token of keys){ |
|
if (!set[token]){ |
|
console.log('Missing translation for '+key); |
|
return keys[keys.length-1].replace('_',' '); |
|
} |
|
set = set[token]; |
|
} |
|
for (var i in args) set = set.replace(`{${i}}`,args[i]); |
|
return set; |
|
} |