feat: use i18n in components
This commit is contained in:
@@ -1,29 +1,35 @@
|
||||
<script lang="ts">
|
||||
import { downloadBlob } from '$lib/core/io';
|
||||
import { t } from '$lib/i18n/t';
|
||||
import { getMergedDict } from '$lib/i18n/locale.svelte';
|
||||
|
||||
interface Props {
|
||||
text: string;
|
||||
filename: string;
|
||||
toolId?: string;
|
||||
}
|
||||
|
||||
let { text, filename }: Props = $props();
|
||||
let { text, filename, toolId }: Props = $props();
|
||||
|
||||
const shown = $derived(
|
||||
toolId ? (getMergedDict().tools[toolId]?.results?.[text] ?? text) : text
|
||||
);
|
||||
|
||||
let copied = $state(false);
|
||||
|
||||
async function copy() {
|
||||
await navigator.clipboard.writeText(text);
|
||||
await navigator.clipboard.writeText(shown);
|
||||
copied = true;
|
||||
setTimeout(() => (copied = false), 1500);
|
||||
}
|
||||
|
||||
function download() {
|
||||
downloadBlob(new Blob([text], { type: 'text/plain' }), `${filename}.txt`);
|
||||
downloadBlob(new Blob([shown], { type: 'text/plain' }), `${filename}.txt`);
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="panel text-result">
|
||||
<textarea class="output" rows="10" readonly value={text} aria-label={t('textResult.outputAria')}></textarea>
|
||||
<textarea class="output" rows="10" readonly value={shown} aria-label={t('textResult.outputAria')}></textarea>
|
||||
<div class="actions">
|
||||
<button type="button" class="secondary" onclick={copy}>
|
||||
{copied ? t('textResult.copied') : t('textResult.copy')}
|
||||
|
||||
Reference in New Issue
Block a user