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

fix: Update @formatjs/intl-localematcher to latest version #1140

Merged
merged 4 commits into from
Aug 20, 2024
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
4 changes: 2 additions & 2 deletions packages/next-intl/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
"next.js"
],
"dependencies": {
"@formatjs/intl-localematcher": "^0.2.32",
"@formatjs/intl-localematcher": "^0.5.4",
"negotiator": "^0.6.3",
"use-intl": "workspace:^"
},
Expand Down Expand Up @@ -144,7 +144,7 @@
},
{
"path": "dist/production/middleware.js",
"limit": "6.525 KB"
"limit": "11.515 KB"
},
{
"path": "dist/production/routing.js",
Expand Down
5 changes: 3 additions & 2 deletions packages/next-intl/src/middleware/resolveLocale.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('getAcceptLanguageLocale', () => {
).toBe('en');
});

it('resolves a more generic locale to a specific one', () => {
it('resolves a locale with a different region to one that matches at least the language', () => {
const requestHeaders = new Headers({
'accept-language': 'en-GB;q=0.9'
});
Expand All @@ -24,7 +24,8 @@ describe('getAcceptLanguageLocale', () => {
).toBe('en-US');
});

it('resolves the most specific locale', () => {
it('resolves the most specific locale, even if it is defined after a more generic one', () => {
// Related to https://github.com/formatjs/formatjs/issues/4469
const requestHeaders = new Headers({
'accept-language': 'de-DE,de;q=0.9,en-US;q=0.8'
});
Expand Down
9 changes: 8 additions & 1 deletion packages/next-intl/src/middleware/resolveLocale.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ function findDomainFromHost<AppLocales extends Locales>(
return undefined;
}

function orderLocales<AppLocales extends Locales>(locales: AppLocales) {
// Workaround for https://github.com/formatjs/formatjs/issues/4469
return locales.slice().sort((a, b) => b.length - a.length);
}

export function getAcceptLanguageLocale<AppLocales extends Locales>(
requestHeaders: Headers,
locales: AppLocales,
Expand All @@ -40,9 +45,11 @@ export function getAcceptLanguageLocale<AppLocales extends Locales>(
}
}).languages();
try {
const orderedLocales = orderLocales(locales);

locale = match(
languages,
locales as unknown as Array<string>,
orderedLocales as unknown as Array<string>,
defaultLocale
);
} catch (e) {
Expand Down
79 changes: 25 additions & 54 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading