Skip to content

Commit 76d6930

Browse files
authored
Merge pull request #12134 from ethereum/default-local-prefix
Default locale prefix in url
2 parents b094f1b + 2e2de93 commit 76d6930

File tree

16 files changed

+232
-192
lines changed

16 files changed

+232
-192
lines changed

next-i18next.config.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@ const locales = BUILD_LOCALES
99
/** @type {import('next-i18next').UserConfig} */
1010
module.exports = {
1111
i18n: {
12-
defaultLocale: "en",
12+
// "default" locale is a hack to always display the locale prefix in the
13+
// url. Ref: https://nextjs.org/docs/pages/building-your-application/routing/internationalization#prefixing-the-default-locale
14+
defaultLocale: "default",
1315
// supported locales defined in `i18n.config.json`
14-
locales,
16+
locales: ["default", ...locales],
17+
localeDetection: false,
1518
},
1619
// define custom location for intl files, otherwise default to public/locales (https://github.com/i18next/next-i18next#2-translation-content)
1720
localePath: "./src/intl",

next.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ module.exports = (phase, { defaultConfig }) => {
3434
return config
3535
},
3636
i18n,
37+
trailingSlash: true,
3738
images: {
3839
deviceSizes: [640, 750, 828, 1080, 1200, 1504, 1920],
3940
},

public/_redirects

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/en/ / 301!
2-
31
/discord https://discord.gg/ethereum-org 301!
42

53
/*/discord https://discord.gg/ethereum-org 301!
@@ -175,5 +173,3 @@
175173
/*/staking/withdraws /:splat/staking/withdrawals/ 301!
176174

177175
/*/guides/how-to-register-an-ethereum-account /:splat/guides/how-to-create-an-ethereum-account/ 301!
178-
179-
/en/stablecoins /stablecoins 301!

src/components/Breadcrumbs/index.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,12 @@ type Crumb = {
3636
// { fullPath: "/en/eth2/", text: "ETH2" },
3737
// { fullPath: "/en/eth2/proof-of-stake/", text: "PROOF OF STAKE" },
3838
// ]
39-
const Breadcrumbs = ({
40-
slug: originalSlug,
41-
startDepth = 0,
42-
...props
43-
}: BreadcrumbsProps) => {
39+
const Breadcrumbs = ({ slug, startDepth = 0, ...props }: BreadcrumbsProps) => {
4440
const { t } = useTranslation("common")
4541
const { locale, asPath } = useRouter()
4642
const dir = isLangRightToLeft(locale! as Lang) ? "rtl" : "ltr"
4743

4844
const hasHome = asPath !== "/"
49-
const slug = originalSlug.replace(`/${locale}/`, "/")
5045
const slugChunk = slug.split("/")
5146
const sliced = slugChunk.filter((item) => !!item)
5247

src/components/FeedbackWidget.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ const FeedbackWidget = () => {
9191
const surveyUrl = useSurvey(feedbackSubmitted)
9292

9393
const bottomOffset = useMemo(() => {
94-
const pathsWithBottomNav = ["/staking", "/dao", "/defi", "/nft"]
94+
const pathsWithBottomNav = ["/staking/", "/dao/", "/defi/", "/nft/"]
9595
const CONDITIONAL_OFFSET = 6.75
9696
let offset = 0
9797
pathsWithBottomNav.forEach((path) => {

src/components/LanguagePicker/useLanguagePicker.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import type {
1111
} from "@/lib/types"
1212

1313
import { MatomoEventOptions, trackCustomEvent } from "@/lib/utils/matomo"
14-
import { languages } from "@/lib/utils/translations"
14+
import { filterRealLocales, languages } from "@/lib/utils/translations"
1515

1616
import progressDataJson from "@/data/translationProgress.json"
1717

@@ -24,7 +24,7 @@ export const useLanguagePicker = (
2424
menuState?: UseDisclosureReturn
2525
) => {
2626
const { t } = useTranslation("page-languages")
27-
const { locale, locales } = useRouter()
27+
const { locale, locales: rawLocales } = useRouter()
2828
const refs = {
2929
inputRef: useRef<HTMLInputElement>(null),
3030
firstItemRef: useRef<HTMLAnchorElement>(null),
@@ -37,6 +37,8 @@ export const useLanguagePicker = (
3737

3838
// perform all the filtering and mapping when the filter value change
3939
useEffect(() => {
40+
const locales = filterRealLocales(rawLocales)
41+
4042
// Get the preferred languages for the users browser
4143
const navLangs = typeof navigator !== "undefined" ? navigator.languages : []
4244

@@ -149,7 +151,7 @@ export const useLanguagePicker = (
149151
.includes(filterValue.toLowerCase())
150152
)
151153
)
152-
}, [filterValue, locale, locales, t])
154+
}, [filterValue, locale, rawLocales, t])
153155

154156
const { isOpen, ...menu } = useDisclosure()
155157

src/components/PageMetadata.tsx

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,8 @@ const PageMetadata = ({
4444
const path = asPath.replace(/[\?\#].*/, "")
4545
const slug = path.split("/")
4646

47-
/**
48-
* Set canonical URL w/ language path to avoid duplicate content
49-
* If English, remove language path
50-
* Remove trailing slash
51-
* @example ethereum.org/about/ -> ethereum.org/about
52-
* @example ethereum.org/pt-br/web3/ -> ethereum.org/pt-br/web3
53-
*/
54-
const url = new URL(
55-
join(locale === DEFAULT_LOCALE ? "" : locale!, path),
56-
SITE_URL
57-
).href.replace(/\/$/, "")
47+
// Set canonical URL w/ language path to avoid duplicate content
48+
const url = new URL(join(locale!, path), SITE_URL).href
5849
const canonical = canonicalUrl || url
5950

6051
/* Set fallback ogImage based on path */

0 commit comments

Comments
 (0)