Skip to content

Commit 3565072

Browse files
authored
Merge pull request #16804 from ethereum/exclude-fil-pcm-b8f83
Deprecate and remove pcm and fil locales
2 parents 4e38224 + 9e7537c commit 3565072

File tree

99 files changed

+48
-13359
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+48
-13359
lines changed

i18n.config.json

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -377,24 +377,6 @@
377377
"dateFormat": "MM/DD/YYYY",
378378
"validISO639_1": true
379379
},
380-
{
381-
"code": "pcm",
382-
"crowdinCode": "pcm",
383-
"name": "Nigerian Pidgin",
384-
"localName": "Nigerian Pidgin",
385-
"langDir": "ltr",
386-
"dateFormat": "DD/MM/YYYY",
387-
"validISO639_1": false
388-
},
389-
{
390-
"code": "fil",
391-
"crowdinCode": "fil",
392-
"name": "Filipino",
393-
"localName": "Filipino",
394-
"langDir": "ltr",
395-
"dateFormat": "MM/DD/YYYY",
396-
"validISO639_1": false
397-
},
398380
{
399381
"code": "pl",
400382
"crowdinCode": "pl",

middleware.ts

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,44 @@ import createMiddleware from "next-intl/middleware"
33

44
import { routing } from "./src/i18n/routing"
55
import { DEFAULT_LOCALE } from "./src/lib/constants"
6+
import { getFirstSegment } from "./src/lib/utils/url"
67

78
const handleI18nRouting = createMiddleware(routing)
89

10+
// Locales that have been removed but may have external links pointing to them
11+
const DEPRECATED_LOCALES = new Set(["pcm", "fil", "ph"])
12+
13+
// Legacy locale codes that should redirect to their current equivalents
14+
const LOCALE_ALIASES: Record<string, string> = { no: "nb" }
15+
16+
function redirectTo(request: NextRequest, pathname: string, status: number) {
17+
const url = request.nextUrl.clone()
18+
url.pathname = pathname
19+
return NextResponse.redirect(url, status)
20+
}
21+
922
export default function middleware(request: NextRequest) {
10-
// Normalize to lowercase paths site-wide (URLs are case-insensitive by spec,
11-
// but our routes are defined in lowercase). Do this BEFORE i18n routing.
12-
const originalPath = request.nextUrl.pathname
13-
const lowerPath = originalPath.toLowerCase()
14-
if (originalPath !== lowerPath) {
15-
const url = request.nextUrl.clone()
16-
url.pathname = lowerPath
17-
return NextResponse.redirect(url, 301)
23+
const { pathname } = request.nextUrl
24+
25+
const lowerPath = pathname.toLowerCase()
26+
if (pathname !== lowerPath) {
27+
return redirectTo(request, lowerPath, 301)
28+
}
29+
30+
const firstSegment = getFirstSegment(lowerPath)
31+
32+
if (firstSegment && DEPRECATED_LOCALES.has(firstSegment)) {
33+
// Strip deprecated locale and redirect to default locale version
34+
const rest = lowerPath.slice(firstSegment.length + 1)
35+
const newPath = !rest ? "/" : rest
36+
return redirectTo(request, newPath, 302)
37+
}
38+
39+
if (firstSegment && firstSegment in LOCALE_ALIASES) {
40+
// Replace legacy locale code with current one
41+
const newLocale = LOCALE_ALIASES[firstSegment]
42+
const newPath = `/${newLocale}${lowerPath.slice(firstSegment.length + 1)}`
43+
return redirectTo(request, newPath, 301)
1844
}
1945

2046
// Handle i18n routing

next.config.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,6 @@ module.exports = (phase, { defaultConfig }) => {
162162
}
163163

164164
return [
165-
// Custom locale aliases redirects
166-
{ source: "/no/:path*", destination: "/nb/:path*", permanent: true },
167-
{ source: "/ph/:path*", destination: "/fil/:path*", permanent: true },
168-
169165
// All primary redirects
170166
...redirects.flatMap(([source, destination, permanent]) =>
171167
createRedirect(source, destination, permanent)

public/content/translations/fil/bridges/index.md

Lines changed: 0 additions & 139 deletions
This file was deleted.

0 commit comments

Comments
 (0)