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

Narrow typed locale identifiers #2857

Open
2 of 4 tasks
warflash opened this issue Mar 18, 2024 · 0 comments
Open
2 of 4 tasks

Narrow typed locale identifiers #2857

warflash opened this issue Mar 18, 2024 · 0 comments

Comments

@warflash
Copy link
Contributor

warflash commented Mar 18, 2024

Describe the feature

const { locale, locales } = useI18n()

Currently locale is typed as string and locales is string[].
The suggestion is to use tighter types like locale -> "en" | "de" in the case of a config like:

	i18n: {
		locales: [
			{ code: "en", iso: "en-US", file: "en.json" },
			{ code: "de", iso: "de-DE", file: "de.json" },
		],
	},

That would make type safe access to typed records possible. e.g.

const MIN_SEARCH_LEN_BY_LOCALE = {
	en: 3,
	de: 3,
	ko: 1,
}

const { locale, locales } = useI18n()

const minLen = MIN_SEARCH_LEN_BY_LOCALE[locale] 

Additional information

  • Would you be willing to help implement this feature?
  • Could this feature be implemented as a module?

Final checks

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

No branches or pull requests

2 participants