Code Monkey home page Code Monkey logo

Comments (5)

kaisermann avatar kaisermann commented on August 31, 2024 4

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.

kaisermann avatar kaisermann commented on August 31, 2024

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.

Antonyacosta78 avatar Antonyacosta78 commented on August 31, 2024

@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.

Antonyacosta78 avatar Antonyacosta78 commented on August 31, 2024

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.

kaisermann avatar kaisermann commented on August 31, 2024

Glad to know it helps 😁 And yeah, of course, PRs are always welcome!

from svelte-i18n.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.