diff --git a/packages/adapter-svelte/README.md b/packages/adapter-svelte/README.md index 28e5779f..3de8dd76 100644 --- a/packages/adapter-svelte/README.md +++ b/packages/adapter-svelte/README.md @@ -259,12 +259,17 @@ 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: + +
+ 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 + + + + +{#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', + 'Goodbye, click here to delete your first project': + 'Goodbye, click here to delete 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 }} +/> +``` +
+ + + +