it seems like svelte does not support i18n...
I mean possibility to add language files and easily translate string in templates as well as in javascript code. e.t.c: this.$t('home.wellcome') will be translated to 'Welcome guest' from file /lang/en-US.json.
Is support of i18n planned?
Have you looked at Svelte's built-in Store? It seems like that could be used pretty well to grab strings from json files and to make them available to all components.
yes, I did, this can be a solution.
but I'm using not just Svelte but also Sapper and I seems to be tricky to implement it correctly both for server and client side.
It would be great to get full well-done solution sometime...
I tried to create my own store:
class MyStore extends Store ...
added to client:
init(
document.querySelector('#sapper'),
routes,
{
store: data => {
return new MyStore(data);
}
});
but I got:
client.js:11 Uncaught TypeError: _my_store__WEBPACK_IMPORTED_MODULE_2__.MyStore is not a constructor at Object.store (client.js:11)
it can't instantiate my class
B.T.W for the standart store it works...
I'm sorry, I forgot to add
export { MyStore };
finally solution with Store works fine
but in this case Store is not POJO anymore
it causes problem with transferring state from server to client in Sapper
as described here: https://github.com/sveltejs/sapper/issues/230
I have special function _ in store for this case, and it works very fine.
Did you try https://github.com/kaisermann/svelte-i18n ?
@Rich-Harris had an extensive thread on this some months back, incl on his Twitter feed, I remember correctly. Not sure what the outcome was; but rolling your own is very easy and svelte provides all the programming concepts you'd need in order to do so without adding much to your bundle-size.
@Conduitry what type of help is wanted?
Most helpful comment
Did you try https://github.com/kaisermann/svelte-i18n ?