Skip to content

Commit

Permalink
Merge pull request ethereum#12134 from ethereum/default-local-prefix
Browse files Browse the repository at this point in the history
Default locale prefix in url
  • Loading branch information
pettinarip authored Feb 21, 2024
2 parents b094f1b + 2e2de93 commit 76d6930
Show file tree
Hide file tree
Showing 16 changed files with 232 additions and 192 deletions.
7 changes: 5 additions & 2 deletions next-i18next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ const locales = BUILD_LOCALES
/** @type {import('next-i18next').UserConfig} */
module.exports = {
i18n: {
defaultLocale: "en",
// "default" locale is a hack to always display the locale prefix in the
// url. Ref: https://nextjs.org/docs/pages/building-your-application/routing/internationalization#prefixing-the-default-locale
defaultLocale: "default",
// supported locales defined in `i18n.config.json`
locales,
locales: ["default", ...locales],
localeDetection: false,
},
// define custom location for intl files, otherwise default to public/locales (https://github.com/i18next/next-i18next#2-translation-content)
localePath: "./src/intl",
Expand Down
1 change: 1 addition & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ module.exports = (phase, { defaultConfig }) => {
return config
},
i18n,
trailingSlash: true,
images: {
deviceSizes: [640, 750, 828, 1080, 1200, 1504, 1920],
},
Expand Down
4 changes: 0 additions & 4 deletions public/_redirects
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/en/ / 301!

/discord https://discord.gg/ethereum-org 301!

/*/discord https://discord.gg/ethereum-org 301!
Expand Down Expand Up @@ -175,5 +173,3 @@
/*/staking/withdraws /:splat/staking/withdrawals/ 301!

/*/guides/how-to-register-an-ethereum-account /:splat/guides/how-to-create-an-ethereum-account/ 301!

/en/stablecoins /stablecoins 301!
7 changes: 1 addition & 6 deletions src/components/Breadcrumbs/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,12 @@ type Crumb = {
// { fullPath: "/en/eth2/", text: "ETH2" },
// { fullPath: "/en/eth2/proof-of-stake/", text: "PROOF OF STAKE" },
// ]
const Breadcrumbs = ({
slug: originalSlug,
startDepth = 0,
...props
}: BreadcrumbsProps) => {
const Breadcrumbs = ({ slug, startDepth = 0, ...props }: BreadcrumbsProps) => {
const { t } = useTranslation("common")
const { locale, asPath } = useRouter()
const dir = isLangRightToLeft(locale! as Lang) ? "rtl" : "ltr"

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

Expand Down
2 changes: 1 addition & 1 deletion src/components/FeedbackWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ const FeedbackWidget = () => {
const surveyUrl = useSurvey(feedbackSubmitted)

const bottomOffset = useMemo(() => {
const pathsWithBottomNav = ["/staking", "/dao", "/defi", "/nft"]
const pathsWithBottomNav = ["/staking/", "/dao/", "/defi/", "/nft/"]
const CONDITIONAL_OFFSET = 6.75
let offset = 0
pathsWithBottomNav.forEach((path) => {
Expand Down
8 changes: 5 additions & 3 deletions src/components/LanguagePicker/useLanguagePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type {
} from "@/lib/types"

import { MatomoEventOptions, trackCustomEvent } from "@/lib/utils/matomo"
import { languages } from "@/lib/utils/translations"
import { filterRealLocales, languages } from "@/lib/utils/translations"

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

Expand All @@ -24,7 +24,7 @@ export const useLanguagePicker = (
menuState?: UseDisclosureReturn
) => {
const { t } = useTranslation("page-languages")
const { locale, locales } = useRouter()
const { locale, locales: rawLocales } = useRouter()
const refs = {
inputRef: useRef<HTMLInputElement>(null),
firstItemRef: useRef<HTMLAnchorElement>(null),
Expand All @@ -37,6 +37,8 @@ export const useLanguagePicker = (

// perform all the filtering and mapping when the filter value change
useEffect(() => {
const locales = filterRealLocales(rawLocales)

// Get the preferred languages for the users browser
const navLangs = typeof navigator !== "undefined" ? navigator.languages : []

Expand Down Expand Up @@ -149,7 +151,7 @@ export const useLanguagePicker = (
.includes(filterValue.toLowerCase())
)
)
}, [filterValue, locale, locales, t])
}, [filterValue, locale, rawLocales, t])

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

Expand Down
13 changes: 2 additions & 11 deletions src/components/PageMetadata.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,8 @@ const PageMetadata = ({
const path = asPath.replace(/[\?\#].*/, "")
const slug = path.split("/")

/**
* Set canonical URL w/ language path to avoid duplicate content
* If English, remove language path
* Remove trailing slash
* @example ethereum.org/about/ -> ethereum.org/about
* @example ethereum.org/pt-br/web3/ -> ethereum.org/pt-br/web3
*/
const url = new URL(
join(locale === DEFAULT_LOCALE ? "" : locale!, path),
SITE_URL
).href.replace(/\/$/, "")
// Set canonical URL w/ language path to avoid duplicate content
const url = new URL(join(locale!, path), SITE_URL).href
const canonical = canonicalUrl || url

/* Set fallback ogImage based on path */
Expand Down
Loading

0 comments on commit 76d6930

Please sign in to comment.