(1) Where should getContext be defined?
getContext is provided by Svelte. Link to documentation: svelte.dev/tutorial/context-api So, import { getContext } from 'svelte';
getContext
import { getContext } from 'svelte';
(2) Does it fit?
index.svelte is fine, though I don't think it should go inside a <svelte:head> tag.
index.svelte
<svelte:head>
I would place that in the Svelte script section of your file, not in the markup. (add the script tag directly to the root)
script
<script> import { initLocalizationContext } from "../i18n/index.ts"; initLocalizationContext(); </script> <svelte:head> [...]
(3) Is the complete program as described in the post available somewhere to try?
Unfortunately it is not, all the snippets are adapted copies of a non-public codebase I worked on.
I encourage you to go through the tutorial on the Svelte site: svelte.dev/tutorial/basics . It does not take long to complete and shows very well most of Svelte features. I feel like this page svelte.dev/tutorial/adding-data and this page svelte.dev/tutorial/context-api could have provided answers your questions.
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
(1) Where should getContext be defined?
getContext
is provided by Svelte.Link to documentation: svelte.dev/tutorial/context-api
So,
import { getContext } from 'svelte';
(2) Does it fit?
index.svelte
is fine, though I don't think it should go inside a<svelte:head>
tag.I would place that in the Svelte script section of your file, not in the markup. (add the
script
tag directly to the root)(3) Is the complete program as described in the post available somewhere to try?
Unfortunately it is not, all the snippets are adapted copies of a non-public codebase I worked on.
I encourage you to go through the tutorial on the Svelte site: svelte.dev/tutorial/basics . It does not take long to complete and shows very well most of Svelte features. I feel like this page svelte.dev/tutorial/adding-data and this page svelte.dev/tutorial/context-api could have provided answers your questions.