mirror of
https://github.com/facebook/docusaurus.git
synced 2025-08-06 10:20:09 +02:00
refactor: capitalize locales when creating i18n config (#6048)
* refactor: capitalize locales when creating i18n config * Switch to toLocaleUpperCase method * Update packages/docusaurus/src/server/i18n.ts Co-authored-by: Joshua Chen <sidachen2003@gmail.com> Co-authored-by: Joshua Chen <sidachen2003@gmail.com>
This commit is contained in:
parent
35d3c02357
commit
68b75bf855
3 changed files with 9 additions and 4 deletions
|
@ -42,7 +42,6 @@ export default function LocaleDropdownNavbarItem({
|
||||||
target: '_self',
|
target: '_self',
|
||||||
autoAddBaseUrl: false,
|
autoAddBaseUrl: false,
|
||||||
className: locale === currentLocale ? 'dropdown__link--active' : '',
|
className: locale === currentLocale ? 'dropdown__link--active' : '',
|
||||||
style: {textTransform: 'capitalize'},
|
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -39,11 +39,11 @@ describe('defaultLocaleConfig', () => {
|
||||||
|
|
||||||
test('returns correct labels', () => {
|
test('returns correct labels', () => {
|
||||||
expect(getDefaultLocaleConfig('fr')).toEqual({
|
expect(getDefaultLocaleConfig('fr')).toEqual({
|
||||||
label: canComputeLabel ? 'français' : 'fr',
|
label: canComputeLabel ? 'Français' : 'fr',
|
||||||
direction: 'ltr',
|
direction: 'ltr',
|
||||||
});
|
});
|
||||||
expect(getDefaultLocaleConfig('fr-FR')).toEqual({
|
expect(getDefaultLocaleConfig('fr-FR')).toEqual({
|
||||||
label: canComputeLabel ? 'français (France)' : 'fr-FR',
|
label: canComputeLabel ? 'Français (France)' : 'fr-FR',
|
||||||
direction: 'ltr',
|
direction: 'ltr',
|
||||||
});
|
});
|
||||||
expect(getDefaultLocaleConfig('en')).toEqual({
|
expect(getDefaultLocaleConfig('en')).toEqual({
|
||||||
|
|
|
@ -15,7 +15,13 @@ function getDefaultLocaleLabel(locale: string) {
|
||||||
// Intl.DisplayNames is ES2021 - Node14+
|
// Intl.DisplayNames is ES2021 - Node14+
|
||||||
// https://v8.dev/features/intl-displaynames
|
// https://v8.dev/features/intl-displaynames
|
||||||
if (typeof Intl.DisplayNames !== 'undefined') {
|
if (typeof Intl.DisplayNames !== 'undefined') {
|
||||||
return new Intl.DisplayNames([locale], {type: 'language'}).of(locale);
|
const languageName = new Intl.DisplayNames(locale, {type: 'language'}).of(
|
||||||
|
locale,
|
||||||
|
);
|
||||||
|
return (
|
||||||
|
languageName.charAt(0).toLocaleUpperCase(locale) +
|
||||||
|
languageName.substring(1)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return locale;
|
return locale;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue