fix(i18n): regression bug: i18n/<path> should always use locale key/id, not htmlLang (#11979)

This commit is contained in:
Sébastien Lorber
2026-04-30 11:29:45 +02:00
committed by GitHub
parent 52eb721cad
commit 11b594d8e3
2 changed files with 14 additions and 8 deletions
@@ -278,7 +278,7 @@ describe('loadI18n', () => {
defaultLocale: 'fr',
locales: ['en', 'fr', 'de'],
localeConfigs: {
fr: {label: 'Français', translate: false},
fr: {label: 'Français', translate: false, htmlLang: 'fr-FR'},
en: {translate: true, baseUrl: 'en-EN/whatever/else'},
de: {translate: false, baseUrl: '/de-DE/'},
},
@@ -295,7 +295,7 @@ describe('loadI18n', () => {
fr: {
label: 'Français',
direction: 'ltr',
htmlLang: 'fr',
htmlLang: 'fr-FR',
calendar: 'gregory',
path: 'fr',
translate: false,
@@ -458,7 +458,7 @@ describe('loadI18n', () => {
direction: 'ltr',
htmlLang: 'en-US',
label: 'American English',
path: 'en-US',
path: 'x1',
translate: false,
url: 'https://example.com',
});
+11 -5
View File
@@ -87,14 +87,20 @@ function getDefaultDirection(localeStr: string) {
}
export function getDefaultLocaleConfig(
// Locale "key/identifier"
// Can be anything, but usually a country / BCP47 code
locale: string,
// optionally provided in i18n.localConfigs, need to respect BCP47
htmlLang?: string,
): Omit<I18nLocaleConfig, 'translate' | 'url' | 'baseUrl'> {
try {
return {
label: getDefaultLocaleLabel(locale),
direction: getDefaultDirection(locale),
htmlLang: locale,
calendar: getDefaultCalendar(locale),
label: getDefaultLocaleLabel(htmlLang ?? locale),
direction: getDefaultDirection(htmlLang ?? locale),
htmlLang: htmlLang ?? locale,
calendar: getDefaultCalendar(htmlLang ?? locale),
// Fot the i18n/<path>, we don't use htmlLang on purpose
// see bug https://github.com/facebook/docusaurus/issues/11952
path: locale,
};
} catch (e) {
@@ -152,7 +158,7 @@ export async function loadI18n({
I18nLocaleConfig,
'translate' | 'url' | 'baseUrl'
> = {
...getDefaultLocaleConfig(localeConfigInput.htmlLang ?? locale),
...getDefaultLocaleConfig(locale, localeConfigInput.htmlLang),
...localeConfigInput,
};