-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Internationalization support #1034
Comments
There is this #1023 But I suppose that's a variation of (a) just moving the repetition to This seems like another case for dependency injection. |
What about // main.js
const store = new Store({
translate: str => {
// some logic happens
}
});
const app = new App({ target, store }); <p>{{$translate('hello')}}</p>
|
Thanks guys :) Having the translate method defined as a part of the store works fine. I thought the purpose of the store is to hold the data and not the utility methods. The only concern I have is that it might be unexpected for people to have it there, but maybe it just shouldn't be passed this way. A |
Seems like it would not work with Svelte3 ... |
I've written a library using the store approach. There's also the svelte-i18n, but I didn't use because the bundle is too bloated (about 73kB gz) |
sync svelte docs Co-authored-by: Rich-Harris <[email protected]>
I'm opening this issue to discuss what would be the suggested pattern to handle translations with svelte. The ideal output of this discussion might be examples for docs, maybe a new feature that makes it simpler, not sure yet. Let's assume that we build a big app that handles few languages. Some ideas:
a)
Import where needed:
Pros: simple, works out of the box, available only where needed
Cons: repetition of the import
b)
Pass it to all child components inside of the top component
Pros: no repetition, saves keystrokes
Cons: global dependency, available everywhere
c)
Pass it to all child components outside of the top component
Pros: no repetition, saves keystrokes
Cons: global dependency, available everywhere
I don't have a strong opinion which one is better, any other ideas? Maybe there's an option to do so already and I missed it :) Please let me know what you think.
The text was updated successfully, but these errors were encountered: