Skip to content

Commit cd8eda0

Browse files
authored
getLocale from next-intl #3862 (#3878)
1 parent 650acbf commit cd8eda0

4 files changed

Lines changed: 10 additions & 13 deletions

File tree

web/app/[locale]/(pages)/[...slug]/page.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ import type { Metadata } from 'next'
44
import dynamic from 'next/dynamic'
55
import { draftMode } from 'next/headers'
66
import { notFound } from 'next/navigation'
7-
import { locale as rootLocale } from 'next/root-params'
8-
import { getValidLanguagesLocales } from '@/languageConfig'
7+
import { getLocale } from 'next-intl/server'
98
import { decodeSlugs } from '@/lib/helpers/getFullUrl'
109
import { Flags } from '@/sanity/helpers/datasetHelpers'
1110
import { getNameFromIso } from '@/sanity/helpers/localization'
@@ -35,7 +34,7 @@ export async function generateMetadata({
3534
}: PageProps<'/[locale]/[...slug]'>): Promise<Metadata> {
3635
//array, separated by /. e.g. [news, last slug]
3736
const { slug: encodedSlug } = await params
38-
const locale = await rootLocale()
37+
const locale = await getLocale()
3938
const slug = decodeSlugs(encodedSlug) as string[]
4039

4140
const sanityLang = getNameFromIso(locale)

web/app/[locale]/(pages)/news/page.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { algoliasearch } from 'algoliasearch'
33
import type { Metadata } from 'next'
44
import { unstable_cache } from 'next/cache'
55
import dynamic from 'next/dynamic'
6-
import { locale as rootLocale } from 'next/root-params'
6+
import { getLocale } from 'next-intl/server'
77
import { algolia } from '@/lib/config'
88
import { Flags } from '@/sanity/helpers/datasetHelpers'
99
import { getNameFromIso } from '@/sanity/helpers/localization'
@@ -18,7 +18,7 @@ import NewsRoomTemplate from '@/templates/newsroom/Newsroom'
1818
const TopicPage = dynamic(() => import('@/templates/topic/TopicPage'))
1919

2020
export async function generateMetadata(): Promise<Metadata> {
21-
const locale = await rootLocale()
21+
const locale = await getLocale()
2222
const pageSlug = newsSlug[getNameFromIso(locale)]
2323
if (Flags.HAS_NEWSROOM) {
2424
const { data: metaData }: { data: any } = await routeSanityFetch({
@@ -70,7 +70,7 @@ const getInitialResponse = unstable_cache(
7070
)
7171

7272
export default async function NewsroomPage(_: PageProps<'/[locale]/news'>) {
73-
const locale = await rootLocale()
73+
const locale = await getLocale()
7474
const [siteMenuResult, pageResults] = await Promise.all([
7575
routeSanityFetch({
7676
query: Flags.HAS_FANCY_MENU ? globalMenuQuery : simpleMenuQuery,

web/app/[locale]/layout.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@ import { GoogleTagManager } from '@next/third-parties/google'
33
import localFont from 'next/font/local'
44
import { draftMode } from 'next/headers'
55
import NextLink from 'next/link'
6-
import { locale as rootLocale } from 'next/root-params'
76
import Script from 'next/script'
87
import { NextIntlClientProvider } from 'next-intl'
9-
import { getTranslations } from 'next-intl/server'
8+
import { getLocale, getTranslations } from 'next-intl/server'
109
import { PageProvider } from '@/contexts/pageContext'
11-
import { languages } from '@/languageConfig'
1210
import { getLocaleFromIso, getNameFromIso } from '@/sanity/helpers/localization'
1311
import { dataset } from '@/sanity/lib/api'
1412
import { routeSanityFetch, SanityLive } from '@/sanity/lib/live'
@@ -38,7 +36,7 @@ export default async function LocaleLayout({
3836
children,
3937
}: LayoutProps<'/[locale]'>) {
4038
const t = await getTranslations()
41-
const locale = await rootLocale()
39+
const locale = await getLocale()
4240

4341
const queryParams = {
4442
lang: getNameFromIso(locale) ?? 'en_GB',

web/app/[locale]/page.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { stegaClean } from '@sanity/client/stega'
22
import type { Metadata } from 'next'
33
import { draftMode } from 'next/headers'
44
import { notFound } from 'next/navigation'
5-
import { locale as rootLocale } from 'next/root-params'
5+
import { getLocale } from 'next-intl/server'
66
import { OrganizationJsonLd } from 'next-seo'
77
import { Flags } from '@/sanity/helpers/datasetHelpers'
88
import { getNameFromIso } from '@/sanity/helpers/localization'
@@ -16,7 +16,7 @@ import HomePage from '@/templates/homepage/HomePage'
1616
import { FriendlyCaptchaSdkWrapper } from './FriendlyCaptchaWrapper'
1717

1818
export async function generateMetadata(): Promise<Metadata> {
19-
const locale = await rootLocale()
19+
const locale = await getLocale()
2020
const { data: metaData }: { data: any } = await routeSanityFetch({
2121
query: homePageMetaQuery,
2222
params: {
@@ -33,7 +33,7 @@ export default async function Home(_: PageProps<'/[locale]'>) {
3333
//const isInPresentationToolContext =
3434
// (await cookies()).get('preview-fetch-dest')?.value === 'iframe'
3535
const { isEnabled: isDraftMode } = await draftMode()
36-
const locale = await rootLocale()
36+
const locale = await getLocale()
3737

3838
let pageContent = null
3939
const [siteMenuResult, homePageData] = await Promise.all([

0 commit comments

Comments
 (0)