Skip to content

Commit

Permalink
chore(i18n): initialize spanish properly (detect es-419) (elk-zone#1428)
Browse files Browse the repository at this point in the history
  • Loading branch information
userquin authored Jan 24, 2023
1 parent 5527468 commit 0e021e4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: `{}`
Expand All @@ -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.

Expand Down
1 change: 1 addition & 0 deletions config/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)' },
Expand Down
9 changes: 8 additions & 1 deletion utils/language.ts
Original file line number Diff line number Diff line change
@@ -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
}
Expand Down

0 comments on commit 0e021e4

Please sign in to comment.