svelte-i18n
svelte-i18n copied to clipboard
How to use this library with typescript
How can I use internationalization in a typescript (.ts) file where I make http requests to display a success or error message.
This question might be best suited to StackOverflow, but here goes:
To get translated strings imperatively, that is, outside of a Svelte component, you'll need either to subscribe to the appropriate store, or to get the value using Svelte's get() accessor, like so:
import { _ } from "svelte-i18n";
import { get } from "svelte/store";
const str = get(_)("foo.bar"); // value is "baz"
This assumes you've elsewhere loaded locale strings from a file like so:
{
"foo": {
"bar": "baz"
}
}