Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: capitalize locales when creating i18n config #6048

Merged
merged 3 commits into from
Dec 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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