Skip to content

Commit

Permalink
refactor: clean up app directory i18n
Browse files Browse the repository at this point in the history
  • Loading branch information
alexgoff committed Nov 6, 2024
1 parent e598e22 commit 1d4fb00
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 73 deletions.
3 changes: 1 addition & 2 deletions lib/i18n/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ i18n
detection: {
excludeCacheFor: languages,
lookupCookie: cookieName,
lookupQuerystring: "locale",
order: ["path", "querystring", "cookie", "navigator", "htmlTag"],
order: ["htmlTag", "cookie", "navigator"],
},
preload: runsOnServerSide ? languages : [],
});
Expand Down
2 changes: 1 addition & 1 deletion lib/i18n/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { cookieName, fallbackLng } from "./settings";

export const getLocale = cache(() => {
return (
headers().get("x-next-intl-locale") ||
headers().get("x-next-i18n-router-locale") ||
cookies().get(cookieName)?.value ||
fallbackLng
);
Expand Down
13 changes: 5 additions & 8 deletions middleware.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { NextResponse } from "next/server";
import createIntlMiddleware from "next-intl/middleware";
import { fallbackLng, languages } from "./lib/i18n/settings";
import { i18nRouter } from "next-i18n-router";
import { cookieName, fallbackLng, languages } from "./lib/i18n/settings";

const ignorableFileExtensions = ["woff", "ico", "png", "jpeg", "jpg"];

Expand Down Expand Up @@ -37,15 +37,12 @@ export function middleware(request) {
return NextResponse.redirect(redirectUrl);
}
} else {
const handleI18nRouting = createIntlMiddleware({
// A list of all locales that are supported
const res = i18nRouter(request, {
locales: languages,
localePrefix: "as-needed",

// If this locale is matched, pathnames work without a prefix (e.g. `/about`)
defaultLocale: fallbackLng,
localeCookie: cookieName,
routingStrategy: "dynamicSegment",
});
const res = handleI18nRouting(request);

logEntry.httpRequest.status = res.status;
logEntry.httpRequest.redirected = res.redirected;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
"jwt-decode": "^3.1.2",
"next": "^14.2.10",
"next-build-id": "^3.0.0",
"next-intl": "^3.19.1",
"next-i18n-router": "^5.5.1",
"npm-run-all": "^4.1.5",
"react": "^18.3.1",
"react-dom": "^18.3.1",
Expand Down
76 changes: 15 additions & 61 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1826,44 +1826,12 @@
resolved "https://registry.yarnpkg.com/@floating-ui/utils/-/utils-0.2.2.tgz#d8bae93ac8b815b2bd7a98078cf91e2724ef11e5"
integrity sha512-J4yDIIthosAsRZ5CPYP/jQvUAQtlZTTD/4suA08/FEnlxqW3sKS9iAhgsa9VYLZ6vDHn/ixJgIqRQPotoBjxIw==

"@formatjs/[email protected]":
version "2.0.0"
resolved "https://registry.yarnpkg.com/@formatjs/ecma402-abstract/-/ecma402-abstract-2.0.0.tgz#39197ab90b1c78b7342b129a56a7acdb8f512e17"
integrity sha512-rRqXOqdFmk7RYvj4khklyqzcfQl9vEL/usogncBHRZfZBDOwMGuSRNFl02fu5KGHXdbinju+YXyuR+Nk8xlr/g==
dependencies:
"@formatjs/intl-localematcher" "0.5.4"
tslib "^2.4.0"

"@formatjs/[email protected]", "@formatjs/fast-memoize@^2.2.0":
version "2.2.0"
resolved "https://registry.yarnpkg.com/@formatjs/fast-memoize/-/fast-memoize-2.2.0.tgz#33bd616d2e486c3e8ef4e68c99648c196887802b"
integrity sha512-hnk/nY8FyrL5YxwP9e4r9dqeM6cAbo8PeU9UjyXojZMNvVad2Z06FAVHyR3Ecw6fza+0GH7vdJgiKIVXTMbSBA==
dependencies:
tslib "^2.4.0"

"@formatjs/[email protected]":
version "2.7.8"
resolved "https://registry.yarnpkg.com/@formatjs/icu-messageformat-parser/-/icu-messageformat-parser-2.7.8.tgz#f6d7643001e9bb5930d812f1f9a9856f30fa0343"
integrity sha512-nBZJYmhpcSX0WeJ5SDYUkZ42AgR3xiyhNCsQweFx3cz/ULJjym8bHAzWKvG5e2+1XO98dBYC0fWeeAECAVSwLA==
dependencies:
"@formatjs/ecma402-abstract" "2.0.0"
"@formatjs/icu-skeleton-parser" "1.8.2"
tslib "^2.4.0"

"@formatjs/[email protected]":
version "1.8.2"
resolved "https://registry.yarnpkg.com/@formatjs/icu-skeleton-parser/-/icu-skeleton-parser-1.8.2.tgz#2252c949ae84ee66930e726130ea66731a123c9f"
integrity sha512-k4ERKgw7aKGWJZgTarIcNEmvyTVD9FYh0mTrrBMHZ1b8hUu6iOJ4SzsZlo3UNAvHYa+PnvntIwRPt1/vy4nA9Q==
dependencies:
"@formatjs/ecma402-abstract" "2.0.0"
tslib "^2.4.0"

"@formatjs/[email protected]", "@formatjs/intl-localematcher@^0.5.4":
version "0.5.4"
resolved "https://registry.yarnpkg.com/@formatjs/intl-localematcher/-/intl-localematcher-0.5.4.tgz#caa71f2e40d93e37d58be35cfffe57865f2b366f"
integrity sha512-zTwEpWOzZ2CiKcB93BLngUX59hQkuZjT2+SAQEscSm52peDW/getsawMcWF1rGRpMCX6D7nSJA3CzJ8gn13N/g==
"@formatjs/intl-localematcher@^0.5.2":
version "0.5.5"
resolved "https://registry.yarnpkg.com/@formatjs/intl-localematcher/-/intl-localematcher-0.5.5.tgz#b24f100f30658104d5f6db35b0b8d97235298681"
integrity sha512-t5tOGMgZ/i5+ALl2/offNqAQq/lfUnKLEw0mXQI4N4bqpedhrSE+fyKLpwnd22sK0dif6AV+ufQcTsKShB9J1g==
dependencies:
tslib "^2.4.0"
tslib "^2.7.0"

"@graphql-typed-document-node/core@^3.1.1":
version "3.1.1"
Expand Down Expand Up @@ -8010,16 +7978,6 @@ interpret@^1.0.0:
resolved "https://registry.yarnpkg.com/interpret/-/interpret-1.4.0.tgz#665ab8bc4da27a774a40584e812e3e0fa45b1a1e"
integrity sha512-agE4QfB2Lkp9uICn7BAqoscw4SZP9kTE2hxiFI3jBPmXJfdqiahTbUuKGsMoN2GtqL9AxhYioAcVvgsb1HvRbA==

intl-messageformat@^10.5.14:
version "10.5.14"
resolved "https://registry.yarnpkg.com/intl-messageformat/-/intl-messageformat-10.5.14.tgz#e5bb373f8a37b88fbe647d7b941f3ab2a37ed00a"
integrity sha512-IjC6sI0X7YRjjyVH9aUgdftcmZK7WXdHeil4KwbjDnRWjnVitKpAx3rr6t6di1joFp5188VqKcobOPA6mCLG/w==
dependencies:
"@formatjs/ecma402-abstract" "2.0.0"
"@formatjs/fast-memoize" "2.2.0"
"@formatjs/icu-messageformat-parser" "2.7.8"
tslib "^2.4.0"

ip@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/ip/-/ip-2.0.0.tgz#4cf4ab182fee2314c75ede1276f8c80b479936da"
Expand Down Expand Up @@ -9369,14 +9327,13 @@ next-build-id@^3.0.0:
resolved "https://registry.yarnpkg.com/next-build-id/-/next-build-id-3.0.0.tgz#bfb7a1e2df03882688758f0a4a67e6e837043f42"
integrity sha512-B3JCsL/9Z/wkmo3EySukQHCgx89Aw0i4LPi2MEhCboQBJ6wpkYTIu1z6hOYKuw/S1Wy8ZRqCEq0dVY/ST6jGqg==

next-intl@^3.19.1:
version "3.19.1"
resolved "https://registry.yarnpkg.com/next-intl/-/next-intl-3.19.1.tgz#b78cabb7940d7ac9048935eb5f71d529f197121b"
integrity sha512-KlJSomzbB5dNkWBIiSIRaoy5zqwLgHNV5Zw0ULhkHjNnPN7aLFFv2G+VOQKle630sNH2JiKc9nsmi6PM1GdkhA==
next-i18n-router@^5.5.1:
version "5.5.1"
resolved "https://registry.yarnpkg.com/next-i18n-router/-/next-i18n-router-5.5.1.tgz#3d4c34d431e38aa4ba8f52cd54d4387fc70db6d2"
integrity sha512-uJGYUAQS33LbRT3Jx+kurR/E79iPQo1jWZUYmc+614UkPt58k2XYyGloSvHR74b21i4K/d6eksdBj6T2WojjdA==
dependencies:
"@formatjs/intl-localematcher" "^0.5.4"
"@formatjs/intl-localematcher" "^0.5.2"
negotiator "^0.6.3"
use-intl "^3.19.1"

next@^14.2.10:
version "14.2.10"
Expand Down Expand Up @@ -12440,6 +12397,11 @@ tslib@^2.5.0:
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.6.0.tgz#b295854684dbda164e181d259a22cd779dcd7bc3"
integrity sha512-7At1WUettjcSRHXCyYtTselblcHl9PJFFVKiCAy/bY97+BPZXSQ2wbq0P9s8tK2G7dFQfNnlJnPAiArVBVBsfA==

tslib@^2.7.0:
version "2.8.0"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.8.0.tgz#d124c86c3c05a40a91e6fdea4021bd31d377971b"
integrity sha512-jWVzBLplnCmoaTr13V9dYbiQ99wvZRd0vNWaDRg+aVYRcjDF3nDksxFDE/+fkXnKhpnUUkmx5pK/v8mCtLVqZA==

tsutils@^3.21.0:
version "3.21.0"
resolved "https://registry.yarnpkg.com/tsutils/-/tsutils-3.21.0.tgz#b48717d394cea6c1e096983eed58e9d61715b623"
Expand Down Expand Up @@ -12726,14 +12688,6 @@ urql@^4.1.0:
"@urql/core" "^5.0.0"
wonka "^6.3.2"

use-intl@^3.19.1:
version "3.19.1"
resolved "https://registry.yarnpkg.com/use-intl/-/use-intl-3.19.1.tgz#2d3b69e72d908215fd8e3d454289c7dfe36c6e8c"
integrity sha512-FUblDZJ/iuXusroBxvzVwXmgjHIef2YHJ0ASRmkMV8whlcRr6QJozBZUR/xB4I0+MMbWDD4GPugUK+MxE2coJA==
dependencies:
"@formatjs/fast-memoize" "^2.2.0"
intl-messageformat "^10.5.14"

use-resize-observer@^9.0.2:
version "9.0.2"
resolved "https://registry.yarnpkg.com/use-resize-observer/-/use-resize-observer-9.0.2.tgz#25830221933d9b6e931850023305eb9d24379a6b"
Expand Down

0 comments on commit 1d4fb00

Please sign in to comment.