forked from Mirrors/elk
chore(i18n): initialize spanish properly (detect es-419) (#1428)
This commit is contained in:
parent
5527468258
commit
0e021e4388
3 changed files with 12 additions and 4 deletions
|
@ -93,7 +93,7 @@ We are using [vue-i18n](https://vue-i18n.intlify.dev/) via [nuxt-i18n](https://i
|
|||
|
||||
1. Add a new file in [locales](./locales) folder with the language code as the filename.
|
||||
2. Copy [en-US](./locales/en-US.json) and translate the strings.
|
||||
3. Add the language to the `locales` array in [config/i18n.ts](./config/i18n.ts#L60), below `en` and `ar`:
|
||||
3. Add the language to the `locales` array in [config/i18n.ts](./config/i18n.ts#L61), below `en` and `ar`:
|
||||
- If your language have multiple country variants, add the generic one for language only (only if there are a lot of common entries, you can always add it as a new one)
|
||||
- Add all country variants in [country variants object](./config/i18n.ts#L12)
|
||||
- Add all country variants files with empty `messages` object: `{}`
|
||||
|
@ -102,8 +102,8 @@ We are using [vue-i18n](https://vue-i18n.intlify.dev/) via [nuxt-i18n](https://i
|
|||
- If the generic language already exists:
|
||||
- If the translation doesn't differ from the generic language, then add the corresponding translations in the corresponding file
|
||||
- If the translation differs from the generic language, then add the corresponding translations in the corresponding file and remove it from the country variants entry
|
||||
4. If the language is `right-to-left`, add `dir` option with `rtl` value, for example, for [ar](./config/i18n.ts#L70)
|
||||
5. If the language requires special pluralization rules, add `pluralRule` callback option, for example, for [ar](./config/i18n.ts#L71)
|
||||
4. If the language is `right-to-left`, add `dir` option with `rtl` value, for example, for [ar](./config/i18n.ts#L71)
|
||||
5. If the language requires special pluralization rules, add `pluralRule` callback option, for example, for [ar](./config/i18n.ts#L72)
|
||||
|
||||
Check [Pluralization rule callback](https://vue-i18n.intlify.dev/guide/essentials/pluralization.html#custom-pluralization) for more info.
|
||||
|
||||
|
|
|
@ -42,6 +42,7 @@ const countryLocaleVariants: Record<string, LocaleObjectData[]> = {
|
|||
// { code: 'es-DO', name: 'Español (República Dominicana)' },
|
||||
// { code: 'es-EC', name: 'Español (Ecuador)' },
|
||||
{ code: 'es-ES', name: 'Español (España)' },
|
||||
// TODO: Support es-419, if we include spanish country variants remove also fix on utils/language.ts module
|
||||
{ code: 'es-419', name: 'Español (Latinoamérica)' },
|
||||
// { code: 'es-GT', name: 'Español (Guatemala)' },
|
||||
// { code: 'es-HN', name: 'Español (Honduras)' },
|
||||
|
|
|
@ -1,6 +1,13 @@
|
|||
export function matchLanguages(languages: string[], acceptLanguages: readonly string[]): string | null {
|
||||
{
|
||||
const lang = acceptLanguages.map(userLang => languages.find(lang => lang.startsWith(userLang))).filter(v => !!v)[0]
|
||||
// const lang = acceptLanguages.map(userLang => languages.find(lang => lang.startsWith(userLang))).filter(v => !!v)[0]
|
||||
// TODO: Support es-419, remove this code if we include spanish country variants
|
||||
const lang = acceptLanguages.map(userLang => languages.find((lang) => {
|
||||
if (userLang.startsWith('es-') && userLang !== 'es-ES')
|
||||
return lang === 'es-419'
|
||||
|
||||
return lang.startsWith(userLang)
|
||||
})).filter(v => !!v)[0]
|
||||
if (lang)
|
||||
return lang
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue