1
0

chore(i18n): move country variants to avoid changing contributing guide (#1403)

This commit is contained in:
Joaquín Sánchez 2023-01-24 15:42:57 +01:00 committed by GitHub
parent 8b34b8b6e6
commit 82694b87b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 52 additions and 52 deletions

View File

@ -93,17 +93,17 @@ 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. 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. 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#L12), below `en` and `ar`: 3. Add the language to the `locales` array in [config/i18n.ts](./config/i18n.ts#L60), 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) - 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#L97) - Add all country variants in [country variants object](./config/i18n.ts#L12)
- Add all country variants files with empty `messages` object: `{}` - Add all country variants files with empty `messages` object: `{}`
- Translate the strings in the generic language file - Translate the strings in the generic language file
- Later, when anyone wants to add the corresponding translations for the country variant, you can override all entries in the corresponding file: check `en` (english variants), and override the entries in all country files, if you omit them, `i18n` module will use the language entry. You will need also copy from base file to the rest of country variants those messages not being shared (the Elk team is working on resolving this, assuming it can be resolved). - Later, when anyone wants to add the corresponding translations for the country variant, you can override all entries in the corresponding file: check `en` (english variants), and override the entries in all country files, if you omit them, `i18n` module will use the language entry. You will need also copy from base file to the rest of country variants those messages not being shared (the Elk team is working on resolving this, assuming it can be resolved).
- If the generic language already exists: - 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 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 - 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#L22) 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#L23) 5. If the language requires special pluralization rules, add `pluralRule` callback option, for example, for [ar](./config/i18n.ts#L71)
Check [Pluralization rule callback](https://vue-i18n.intlify.dev/guide/essentials/pluralization.html#custom-pluralization) for more info. Check [Pluralization rule callback](https://vue-i18n.intlify.dev/guide/essentials/pluralization.html#custom-pluralization) for more info.

View File

@ -9,6 +9,54 @@ interface LocaleObjectData extends LocaleObject {
pluralRule?: PluralizationRule pluralRule?: PluralizationRule
} }
const countryLocaleVariants: Record<string, LocaleObjectData[]> = {
ar: [
// { code: 'ar-DZ', name: 'Arabic (Algeria)' },
// { code: 'ar-BH', name: 'Arabic (Bahrain)' },
{ code: 'ar-EG', name: 'العربية' },
// { code: 'ar-EG', name: 'Arabic (Egypt)' },
// { code: 'ar-IQ', name: 'Arabic (Iraq)' },
// { code: 'ar-JO', name: 'Arabic (Jordan)' },
// { code: 'ar-KW', name: 'Arabic (Kuwait)' },
// { code: 'ar-LB', name: 'Arabic (Lebanon)' },
// { code: 'ar-LY', name: 'Arabic (Libya)' },
// { code: 'ar-MA', name: 'Arabic (Morocco)' },
// { code: 'ar-OM', name: 'Arabic (Oman)' },
// { code: 'ar-QA', name: 'Arabic (Qatar)' },
// { code: 'ar-SA', name: 'Arabic (Saudi Arabia)' },
// { code: 'ar-SY', name: 'Arabic (Syria)' },
// { code: 'ar-TN', name: 'Arabic (Tunisia)' },
// { code: 'ar-AE', name: 'Arabic (U.A.E.)' },
// { code: 'ar-YE', name: 'Arabic (Yemen)' },
],
en: [
{ code: 'en-US', name: 'English (US)' },
{ code: 'en-GB', name: 'English (UK)' },
],
es: [
// { code: 'es-AR', name: 'Español (Argentina)' },
// { code: 'es-BO', name: 'Español (Bolivia)' },
// { code: 'es-CL', name: 'Español (Chile)' },
// { code: 'es-CO', name: 'Español (Colombia)' },
// { code: 'es-CR', name: 'Español (Costa Rica)' },
// { code: 'es-DO', name: 'Español (República Dominicana)' },
// { code: 'es-EC', name: 'Español (Ecuador)' },
{ code: 'es-ES', name: 'Español (España)' },
{ code: 'es-419', name: 'Español (Latinoamérica)' },
// { code: 'es-GT', name: 'Español (Guatemala)' },
// { code: 'es-HN', name: 'Español (Honduras)' },
// { code: 'es-MX', name: 'Español (México)' },
// { code: 'es-NI', name: 'Español (Nicaragua)' },
// { code: 'es-PA', name: 'Español (Panamá)' },
// { code: 'es-PE', name: 'Español (Perú)' },
// { code: 'es-PR', name: 'Español (Puerto Rico)' },
// { code: 'es-SV', name: 'Español (El Salvador)' },
// { code: 'es-US', name: 'Español (Estados Unidos)' },
// { code: 'es-UY', name: 'Español (Uruguay)' },
// { code: 'es-VE', name: 'Español (Venezuela)' },
],
}
const locales: LocaleObjectData[] = [ const locales: LocaleObjectData[] = [
{ {
code: 'en', code: 'en',
@ -120,54 +168,6 @@ const locales: LocaleObjectData[] = [
}, },
] ]
const countryLocaleVariants: Record<string, LocaleObjectData[]> = {
ar: [
// { code: 'ar-DZ', name: 'Arabic (Algeria)' },
// { code: 'ar-BH', name: 'Arabic (Bahrain)' },
{ code: 'ar-EG', name: 'العربية' },
// { code: 'ar-EG', name: 'Arabic (Egypt)' },
// { code: 'ar-IQ', name: 'Arabic (Iraq)' },
// { code: 'ar-JO', name: 'Arabic (Jordan)' },
// { code: 'ar-KW', name: 'Arabic (Kuwait)' },
// { code: 'ar-LB', name: 'Arabic (Lebanon)' },
// { code: 'ar-LY', name: 'Arabic (Libya)' },
// { code: 'ar-MA', name: 'Arabic (Morocco)' },
// { code: 'ar-OM', name: 'Arabic (Oman)' },
// { code: 'ar-QA', name: 'Arabic (Qatar)' },
// { code: 'ar-SA', name: 'Arabic (Saudi Arabia)' },
// { code: 'ar-SY', name: 'Arabic (Syria)' },
// { code: 'ar-TN', name: 'Arabic (Tunisia)' },
// { code: 'ar-AE', name: 'Arabic (U.A.E.)' },
// { code: 'ar-YE', name: 'Arabic (Yemen)' },
],
en: [
{ code: 'en-US', name: 'English (US)' },
{ code: 'en-GB', name: 'English (UK)' },
],
es: [
// { code: 'es-AR', name: 'Español (Argentina)' },
// { code: 'es-BO', name: 'Español (Bolivia)' },
// { code: 'es-CL', name: 'Español (Chile)' },
// { code: 'es-CO', name: 'Español (Colombia)' },
// { code: 'es-CR', name: 'Español (Costa Rica)' },
// { code: 'es-DO', name: 'Español (República Dominicana)' },
// { code: 'es-EC', name: 'Español (Ecuador)' },
{ code: 'es-ES', name: 'Español (España)' },
{ code: 'es-419', name: 'Español (Latinoamérica)' },
// { code: 'es-GT', name: 'Español (Guatemala)' },
// { code: 'es-HN', name: 'Español (Honduras)' },
// { code: 'es-MX', name: 'Español (México)' },
// { code: 'es-NI', name: 'Español (Nicaragua)' },
// { code: 'es-PA', name: 'Español (Panamá)' },
// { code: 'es-PE', name: 'Español (Perú)' },
// { code: 'es-PR', name: 'Español (Puerto Rico)' },
// { code: 'es-SV', name: 'Español (El Salvador)' },
// { code: 'es-US', name: 'Español (Estados Unidos)' },
// { code: 'es-UY', name: 'Español (Uruguay)' },
// { code: 'es-VE', name: 'Español (Venezuela)' },
],
}
const buildLocales = () => { const buildLocales = () => {
const useLocales = Object.values(locales).reduce((acc, data) => { const useLocales = Object.values(locales).reduce((acc, data) => {
const locales = countryLocaleVariants[data.code] const locales = countryLocaleVariants[data.code]