From 04c719467dfc8a527adc102d33a1e8bc408bd752 Mon Sep 17 00:00:00 2001 From: Ian Hogers Date: Sat, 20 Jul 2024 09:47:50 +1000 Subject: [PATCH 1/2] Update README.md Added Multiple Snippet Translation Component Example --- packages/adapter-svelte/README.md | 135 +++++++++++++++++++++++++++++- 1 file changed, 134 insertions(+), 1 deletion(-) diff --git a/packages/adapter-svelte/README.md b/packages/adapter-svelte/README.md index 28e5779f..0fa2b3fc 100644 --- a/packages/adapter-svelte/README.md +++ b/packages/adapter-svelte/README.md @@ -259,12 +259,14 @@ You may run into the error **`Error [ERR_MODULE_NOT_FOUND]: Cannot find package -## recipes +## Recipes ### How do I render a component inside a Translation? By default `typesafe-i18n` at this time does not provide such a functionality. But you could easily write a function like this: +### Wrap Piece of Translation with a component: + ```svelte + + + +{#each replacerData as part} + {#if typeof part === 'string'} + {part} + {:else} + {@render part.method(part.content)} + {/if} +{/each} +``` + +Your translations would look something like this: +```ts +const en = { + 'Hi {name:string}, click here to create your first project': + 'Hi {name:string}, click here to create your first project' +} +``` +_(By using the same value for the translation as the key you have an easy overview of what snippets can be used)_ + +Use it inside your application + +```svelte +{#snippet someSnippet(text: string)} +

+ {text} +

+{/snippet} + +{#snippet anotherSnippet(text: string)} +

+ {text} +

+{/snippet} +here to create your first project"]("SanCoca")} + replacers={{ someSnippet, anotherSnippet }} +/> +``` + From ec19f9349b9d2a9f34889cf8f3aeafbd63a9eea3 Mon Sep 17 00:00:00 2001 From: Ian Hogers Date: Sun, 21 Jul 2024 10:44:08 +1000 Subject: [PATCH 2/2] Update README.md Added typesafe `TranslationSnippetWrapper` example --- packages/adapter-svelte/README.md | 245 +++++++++++++++++++++++++++++- 1 file changed, 242 insertions(+), 3 deletions(-) diff --git a/packages/adapter-svelte/README.md b/packages/adapter-svelte/README.md index 0fa2b3fc..3de8dd76 100644 --- a/packages/adapter-svelte/README.md +++ b/packages/adapter-svelte/README.md @@ -267,6 +267,9 @@ By default `typesafe-i18n` at this time does not provide such a functionality. B ### Wrap Piece of Translation with a component: +
+ Single Text Wrapper + ```svelte + + + +{#each replacerData as part} + {#if typeof part === 'string'} + {part} + {:else} + {@render part.method(part.content)} + {/if} +{/each} +``` + +
+ + + +--- + +
+ Basic Version + #### TranslationSnippetWrapper + _This example uses lodash for the sorting_ + ```svelte