enh: codeblock i18n

This commit is contained in:
Timothy J. Baek 2024-08-08 15:07:24 +02:00
parent 13403cd7dc
commit d388c20373
2 changed files with 10 additions and 6 deletions

View File

@ -1,7 +1,7 @@
<script lang="ts"> <script lang="ts">
import hljs from 'highlight.js'; import hljs from 'highlight.js';
import { loadPyodide } from 'pyodide'; import { loadPyodide } from 'pyodide';
import { getContext } from 'svelte'; import { getContext, getAllContexts } from 'svelte';
import { copyToClipboard } from '$lib/utils'; import { copyToClipboard } from '$lib/utils';
import 'highlight.js/styles/github-dark.min.css'; import 'highlight.js/styles/github-dark.min.css';
@ -236,12 +236,12 @@ __builtins__.input = input`);
class="copy-code-button bg-none border-none p-1" class="copy-code-button bg-none border-none p-1"
on:click={() => { on:click={() => {
executePython(code); executePython(code);
}}>Run</button }}>{$i18n.t('Run')}</button
> >
{/if} {/if}
{/if} {/if}
<button class="copy-code-button bg-none border-none p-1" on:click={copyCode} <button class="copy-code-button bg-none border-none p-1" on:click={copyCode}
>{copied ? 'Copied' : 'Copy Code'}</button >{copied ? $i18n.t('Copied') : $i18n.t('Copy Code')}</button
> >
</div> </div>
</div> </div>

View File

@ -3,7 +3,10 @@
import type { Token } from 'marked'; import type { Token } from 'marked';
import { revertSanitizedResponseContent, unescapeHtml } from '$lib/utils'; import { revertSanitizedResponseContent, unescapeHtml } from '$lib/utils';
import { onMount } from 'svelte'; import { onMount, getContext, getAllContexts } from 'svelte';
const context = getAllContexts();
const i18n = getContext('i18n');
import Image from '$lib/components/common/Image.svelte'; import Image from '$lib/components/common/Image.svelte';
import CodeBlock from '$lib/components/chat/Messages/CodeBlock.svelte'; import CodeBlock from '$lib/components/chat/Messages/CodeBlock.svelte';
@ -44,7 +47,7 @@
return; return;
} }
new CodeBlock({ const element = new CodeBlock({
target: codeElement, target: codeElement,
props: { props: {
id: `${id}-${codes.length}`, id: `${id}-${codes.length}`,
@ -52,7 +55,8 @@
code: revertSanitizedResponseContent(code) code: revertSanitizedResponseContent(code)
}, },
hydrate: true, hydrate: true,
$$inline: true $$inline: true,
context: context
}); });
} }
}, 10); }, 10);