mastered translations
This commit is contained in:
@@ -1,11 +1,5 @@
|
||||
<script>
|
||||
import { onMount } from 'svelte';
|
||||
import { t, loadTranslation } from './translations.js'
|
||||
let ready = false;
|
||||
onMount(async () => {
|
||||
await loadTranslation('en','Login');
|
||||
ready = true;
|
||||
});
|
||||
import { t } from '../translations.svelte.js';
|
||||
</script>
|
||||
<style>
|
||||
label { display: block; margin: 5px; }
|
||||
@@ -20,9 +14,8 @@
|
||||
}
|
||||
</style>
|
||||
|
||||
{#if ready}
|
||||
<fieldset>
|
||||
<legend>{t('Login','Login')}</legend>
|
||||
<legend>{t('login.Login')}</legend>
|
||||
<label>
|
||||
<input type="text" />
|
||||
<span>Email/Username</span>
|
||||
@@ -39,6 +32,3 @@
|
||||
<button>SRSoftware</button>
|
||||
<button>ORC ID</button>
|
||||
</fieldset>
|
||||
{:else}
|
||||
<p>Loading translations...</p>
|
||||
{/if}
|
||||
@@ -1,17 +0,0 @@
|
||||
const translations = {}
|
||||
|
||||
export async function loadTranslation(lang,page){
|
||||
if (!translations[lang]) translations[lang] = {};
|
||||
if (translations[lang][page]) return;
|
||||
var url = `${location.protocol}//${location.host.replace('5173','8080')}/api/translations/${lang}/${page}`;
|
||||
const resp = await fetch(url);
|
||||
const json = await resp.json();
|
||||
translations[lang][page] = json;
|
||||
}
|
||||
|
||||
export function t(page,key){
|
||||
const lang = 'en';
|
||||
if (!translations[lang]) return key;
|
||||
if (!translations[lang][page]) return key;
|
||||
return translations[lang][page][key] ? translations[lang][page][key] : key;
|
||||
}
|
||||
Reference in New Issue
Block a user