Skip to content
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

Is there any way to check whether a locale is supported/registered? #256

Open
JorensM opened this issue Aug 1, 2024 · 0 comments
Open

Comments

@JorensM
Copy link

JorensM commented Aug 1, 2024

Is your feature request related to a problem? Please describe.
My problem is that I want to check whether a given locale is available/registered.

Describe the solution you'd like
I'm not sure how svelte-i18n works internally, but I think it would be fairly easy to track an array of registered languages (if that isn't already being done). Depending on what would be more conventional in the context of this library, you could either create a store with an array of all registered locales, or you could create a utility function isLocaleRegistered(), or maybe even both. The former solution (having a store) would be more abstract and open ended though and would open opportunities for more diverse actions than just checking whether a locale is supported (for example listing all the available locales).

Describe alternatives you've considered
My current alternative is to make a custom function isLocaleSupported(lang) that just checks the lang against a predefined array of supported languages. The problem is that this creates 2 sources of truth, now each time I add or remove support for a locale, I also have to remember to update the array of supported locales.

How important is this feature to you?
Not too important, but it would be convenient.

P.S I'm also willing to make a PR for this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant