kaisermann / svelte-i18n

Internationalization library for Svelte
MIT License
1.26k stars 80 forks source link

Add a register store? #244

Open LVitus opened 10 months ago

LVitus commented 10 months ago

Is your feature request related to a problem? Please describe. This would give a good overview over the registered locales. And enable one to easily implement a locales switcher referencing the registered locales as the source of thruth, this is also saving time when adding or modifying locals.

Describe the solution you'd like I would like a register store to be implemented, which has an array of objects representing each locale. The locale objects could have properties like:

{ languageCode: string; languageName: string; flagUrl: string; etc... }

The locale objects could replace the locale string in the register func, and the string passed currently becomes part of the object.

Describe alternatives you've considered Right now I am creating the mentioned array myself and I am looping over it and calling the register function for each of the objects. Maybe you could also implement a register locales function which accepts an array of locales objects and registers each locales.

registerStore.set([ { languageCode: "en", languageTitle: "English" }, { languageCode: "de-DE", languageTitle: "Deutsch" }, { languageCode: "ja-JP", languageTitle: "日本語" }, { languageCode: "fr-FR", languageTitle: "Français" } ]);

locales.forEach(locale => { register(locale.languageCode, () => import($lib/i18n/${locale.languageCode}.json)) });

How important is this feature to you? important yes

Additional context none