mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-10-09 14:52:00 +00:00
Support fr-ca, es-mx and es-419 site UI locales
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
import { describe, expect, it } from 'bun:test';
|
||||
|
||||
import { es } from './es';
|
||||
import { fr } from './fr';
|
||||
import { isAvailableLanguage, languages, loadLanguage } from './index';
|
||||
|
||||
describe('regional language variants', () => {
|
||||
it.each([
|
||||
['fr-ca', fr],
|
||||
['es-mx', es],
|
||||
['es-419', es],
|
||||
] as const)('loads %s with its own metadata and the base strings', async (locale, base) => {
|
||||
expect(isAvailableLanguage(locale)).toBe(true);
|
||||
|
||||
const language = await loadLanguage(locale);
|
||||
|
||||
expect(language).toEqual({ ...base, ...languages[locale] });
|
||||
expect(language.locale).toBe(locale);
|
||||
});
|
||||
});
|
||||
@@ -25,6 +25,10 @@ const languageDefinitions = {
|
||||
metadata: { locale: 'fr', language: 'Français', flag: '🇫🇷' },
|
||||
load: () => import('./fr').then((module) => module.fr),
|
||||
},
|
||||
'fr-ca': {
|
||||
metadata: { locale: 'fr-ca', language: 'Français (Canada)', flag: '🇨🇦' },
|
||||
load: () => import('./fr').then((module) => withMetadata(module.fr, 'fr-ca')),
|
||||
},
|
||||
de: {
|
||||
metadata: { locale: 'de', language: 'Deutsch', flag: '🇩🇪' },
|
||||
load: () => import('./de').then((module) => module.de),
|
||||
@@ -33,6 +37,14 @@ const languageDefinitions = {
|
||||
metadata: { locale: 'es', language: 'Español', flag: '🇪🇸' },
|
||||
load: () => import('./es').then((module) => module.es),
|
||||
},
|
||||
'es-mx': {
|
||||
metadata: { locale: 'es-mx', language: 'Español (México)', flag: '🇲🇽' },
|
||||
load: () => import('./es').then((module) => withMetadata(module.es, 'es-mx')),
|
||||
},
|
||||
'es-419': {
|
||||
metadata: { locale: 'es-419', language: 'Español (Latinoamérica)', flag: '🌎' },
|
||||
load: () => import('./es').then((module) => withMetadata(module.es, 'es-419')),
|
||||
},
|
||||
it: {
|
||||
metadata: { locale: 'it', language: 'Italiano', flag: '🇮🇹' },
|
||||
load: () => import('./it').then((module) => module.it),
|
||||
@@ -177,6 +189,14 @@ const languageDefinitions = {
|
||||
|
||||
export type TranslationLocale = keyof typeof languageDefinitions;
|
||||
|
||||
// Regional variants reuse their base language's strings but keep their own locale, name and flag.
|
||||
function withMetadata(
|
||||
base: TranslationLanguage,
|
||||
locale: 'fr-ca' | 'es-mx' | 'es-419'
|
||||
): TranslationLanguage {
|
||||
return { ...base, ...languageDefinitions[locale].metadata };
|
||||
}
|
||||
|
||||
export const languages = Object.fromEntries(
|
||||
Object.entries(languageDefinitions).map(([locale, definition]) => [locale, definition.metadata])
|
||||
) as {
|
||||
|
||||
Reference in New Issue
Block a user