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 1 commit
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
Next Next commit
refactor: capitalize locales when creating i18n config
  • Loading branch information
lex111 committed Dec 4, 2021
commit cc58b8d4e02c7b54deea99a9b362cf7d2f9804d8
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
5 changes: 4 additions & 1 deletion packages/docusaurus/src/server/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ 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).toUpperCase() + languageName.slice(1);
slorber marked this conversation as resolved.
Show resolved Hide resolved
}
return locale;
}
Expand Down