-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- User frontend - Default language is german with text stored in locales/de.json - This is part of the frontend build and so cannot be edited from the backend - All other languages are no longer part of the git repo - These are fetched as json files from the server - These can be edited from the backend - Admin frontend - Add interface for editing translations of frontend text - Backend - Add endpoint to update an 18n translation json file - resolves #79
- Loading branch information
Showing
23 changed files
with
714 additions
and
568 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<svelte:options runes={true} /> | ||
|
||
<script lang="ts"> | ||
import { | ||
Accordion, | ||
AccordionItem, | ||
ButtonGroup, | ||
Card, | ||
Input, | ||
InputAddon, | ||
Label, | ||
P, | ||
Table, | ||
TableBody, | ||
TableBodyCell, | ||
TableBodyRow, | ||
TableHead, | ||
TableHeadCell | ||
} from 'flowbite-svelte'; | ||
import { onMount } from 'svelte'; | ||
import { _ } from 'svelte-i18n'; | ||
import { getI18nJson, getTranslations } from '$lib/i18n'; | ||
import { languages } from '$lib/stores/langStore'; | ||
import { updateI18N } from '$lib/client/services.gen'; | ||
import SaveButton from '$lib/components/Admin/SaveButton.svelte'; | ||
import de from '../../../locales/de.json'; | ||
type Translation = Record<string, Record<string, string>>; | ||
let translations = $state({} as Record<string, Translation>); | ||
async function refreshTranslations() { | ||
for (const [lang, lang_id] of Object.entries($languages)) { | ||
if (lang !== 'de') { | ||
translations[lang] = await getI18nJson(lang_id); | ||
} | ||
} | ||
} | ||
async function saveChanges() { | ||
for (const lang of Object.keys(translations)) { | ||
const { data, error } = await updateI18N({ | ||
body: translations[lang], | ||
path: { | ||
language_id: $languages[lang] | ||
} | ||
}); | ||
if (error) { | ||
console.log(error); | ||
return; | ||
} else { | ||
console.log(data); | ||
} | ||
} | ||
await getTranslations(); | ||
} | ||
onMount(() => refreshTranslations()); | ||
</script> | ||
|
||
<Card size="xl" class="m-5"> | ||
<h3 class="mb-3 text-xl font-medium text-gray-900 dark:text-white">{$_('admin.translations')}</h3> | ||
<Accordion flush> | ||
{#each Object.entries(de) as [section_key, section]} | ||
<AccordionItem> | ||
<span slot="header" class="flex gap-2 text-base"> | ||
{section_key} | ||
</span> | ||
{#each Object.entries(section) as [item_key, item]} | ||
<div class="m-2 mb-4 rounded-md border p-2"> | ||
<Label class="mb-2">{item_key}</Label> | ||
<div class="mb-1"> | ||
<ButtonGroup class="w-full"> | ||
<InputAddon>de</InputAddon> | ||
<p class="w-full rounded-r-md border px-2">{item}</p> | ||
</ButtonGroup> | ||
</div> | ||
{#each Object.keys(translations) as lang} | ||
<div class="mb-1"> | ||
<ButtonGroup class="w-full"> | ||
<InputAddon>{lang}</InputAddon> | ||
<Input bind:value={translations[lang][section_key][item_key]} /> | ||
</ButtonGroup> | ||
</div> | ||
{/each} | ||
</div> | ||
{/each} | ||
<div class="my-2 content-center"> | ||
<SaveButton onclick={saveChanges} /> | ||
</div> | ||
</AccordionItem> | ||
{/each} | ||
</Accordion> | ||
</Card> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,43 @@ | ||
import { register, init } from 'svelte-i18n'; | ||
import { init, addMessages } from 'svelte-i18n'; | ||
import { languages } from '$lib/stores/langStore'; | ||
import { getLanguages } from '$lib/client'; | ||
import de from '../locales/de.json'; | ||
|
||
register('de', () => import('../locales/de.json')); | ||
register('en', () => import('../locales/en.json')); | ||
export async function getI18nJson(lang_id: number) { | ||
try { | ||
const res = await fetch(`${import.meta.env.VITE_MONDEY_API_URL}/static/i18n/${lang_id}.json`); | ||
if (!res.ok) { | ||
console.log( | ||
`getI18nJson failed for lang_id ${lang_id} with status ${res.status}, returning de translations` | ||
); | ||
return de; | ||
} | ||
return await res.json(); | ||
} catch { | ||
console.log(`getI18nJson failed for lang_id ${lang_id}, returning de translations`); | ||
return de; | ||
} | ||
} | ||
|
||
init({ | ||
fallbackLocale: 'de', | ||
initialLocale: 'de' | ||
}); | ||
async function getTranslation(lang: string, lang_id: number) { | ||
const json = await getI18nJson(lang_id); | ||
addMessages(lang, json); | ||
} | ||
|
||
export async function updateLanguages() { | ||
export async function getTranslations() { | ||
const { data, error } = await getLanguages(); | ||
if (!error && data) { | ||
languages.set(data); | ||
Object.entries(data).forEach(([lang, lang_id]) => { | ||
if (lang_id !== 1) { | ||
getTranslation(lang, lang_id); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
addMessages('de', de); | ||
init({ | ||
fallbackLocale: 'de', | ||
initialLocale: 'de' | ||
}); |
Oops, something went wrong.