mapcomplete/UI/Base/Tr.svelte

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

37 lines
921 B
Svelte
Raw Normal View History

2023-03-29 17:21:20 +02:00
<script lang="ts">
/**
* Properly renders a translation
*/
import { Translation } from "../i18n/Translation";
import { onDestroy } from "svelte";
import Locale from "../i18n/Locale";
import { Utils } from "../../Utils";
import FromHtml from "./FromHtml.svelte";
2023-04-07 02:45:34 +02:00
import WeblateLink from "./WeblateLink.svelte";
2023-03-29 17:21:20 +02:00
export let t: Translation;
export let tags: Record<string, string> | undefined = undefined;
2023-03-29 17:21:20 +02:00
// Text for the current language
let txt: string | undefined;
2023-03-31 03:28:11 +02:00
$: onDestroy(Locale.language.addCallbackAndRunD(l => {
2023-04-07 02:45:34 +02:00
const translation = t?.textFor(l);
if (translation === undefined) {
return;
2023-03-29 17:21:20 +02:00
}
2023-04-07 02:45:34 +02:00
if (tags) {
txt = Utils.SubstituteKeys(txt, tags);
} else {
txt = translation;
2023-03-29 17:21:20 +02:00
}
}));
</script>
2023-04-07 02:45:34 +02:00
{#if t}
<span class="inline-flex items-center">
<FromHtml src={txt}></FromHtml>
<WeblateLink context={t.context}></WeblateLink>
</span>
{/if}