Skip to content

Commit

Permalink
refactor: capitalize locales when creating i18n config (#6048)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
lex111 and Josh-Cena authored Dec 8, 2021
1 parent 35d3c02 commit 68b75bf
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ export default function LocaleDropdownNavbarItem({
target: '_self',
autoAddBaseUrl: false,
className: locale === currentLocale ? 'dropdown__link--active' : '',
style: {textTransform: 'capitalize'},
};
});

Expand Down
4 changes: 2 additions & 2 deletions packages/docusaurus/src/server/__tests__/i18n.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ describe('defaultLocaleConfig', () => {

test('returns correct labels', () => {
expect(getDefaultLocaleConfig('fr')).toEqual({
label: canComputeLabel ? 'français' : 'fr',
label: canComputeLabel ? 'Français' : 'fr',
direction: 'ltr',
});
expect(getDefaultLocaleConfig('fr-FR')).toEqual({
label: canComputeLabel ? 'français (France)' : 'fr-FR',
label: canComputeLabel ? 'Français (France)' : 'fr-FR',
direction: 'ltr',
});
expect(getDefaultLocaleConfig('en')).toEqual({
Expand Down
8 changes: 7 additions & 1 deletion packages/docusaurus/src/server/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@ function getDefaultLocaleLabel(locale: string) {
// Intl.DisplayNames is ES2021 - Node14+
// https://v8.dev/features/intl-displaynames
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;
}
Expand Down

0 comments on commit 68b75bf

Please sign in to comment.