Comments (5)
Oh, I certainly could do that. But what do you think about just changing the $locale
store value?
<script>
import { addMessages, t, locale } from 'svelte-i18n';
import en from './en.json';
import es from './es.json';
addMessages('en', en);
addMessages('es', es);
init({ fallbackLocale: 'en' });
</script>
<button on:click={ () => ($locale = 'es') } > Click here to change to spanish </button>
Or, if you need it outside your components script
tag: locale.set('es')
. Would that solve your issue? Or do you still prefer a more verbose/explicit way of changing it programatically? I'm not entirely against it, since I've done it with the $dictionary
and the addMessages
method.
from svelte-i18n.
Hey 👋
By "changing dictionaries" you mean literally switch all loaded dictionaries with different ones? Or to just switch the current locale and use it's dictionary?
Can you provide an example of usage of what you want?
from svelte-i18n.
@kaisermann I mean switching locales, sorry for the mistake. I am thinking in a function exported by the package in order to change between locales
Example:
<script>
import { addMessages, t, changeLocale } from 'svelte-i18n';
import en from './en.json';
import es from './es.json';
addMessages('en', en);
addMessages('es', es);
init({ fallbackLocale: 'en' });
</script>
<button on:click={ () => changeLocale('es') } > Click here to change to spanish </button>
from svelte-i18n.
No, that's just right, thank you!
Found out that was my mistake for not reading the wiki properly haha.
Anyways it could be good if the main readme had brief explainations on the features (just personal guess, i am more used to read readme files instead of wikis because those are more common). I don't mind writing some. Are you open to PRs?
from svelte-i18n.
Glad to know it helps 😁 And yeah, of course, PRs are always welcome!
from svelte-i18n.
Related Issues (20)
- `intl-getcanocicallocales` is probably not a good idea HOT 2
- CJS / ESM conflict HOT 22
- Change log version comparison links are off
- Production build using svelte-i18n ^3.7.4 throws "Named export 'IntlMessageFormat' not found." HOT 6
- Problems with LIB check in cli extractor HOT 1
- Sapper reference in Getting Started guide
- Allow to restrict some parts of the i18n file to unauthorized users in SvelteKit. HOT 3
- Is it possible when registering several json files to overwrite the previous key contents with latest file?
- Docs on how to use variables in translation strings HOT 1
- How to disable AM/PM in $time formatter
- Leading zeros for day/month when formatting date values
- Add a register store?
- Build error when deploying in vercel
- Provide a Readable<string> instead of pure string
- Svelte 5 support
- Disable automatic "lang" attribute setting
- Locale not set correctly on some page loads HOT 1
- Different context translations (translation in packages) HOT 2
- Override locale for a given string HOT 1
- Is there any way to check whether a locale is supported/registered?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from svelte-i18n.