Skip to content

Commit b350ea0

Browse files
authored
docs(examples): make example buildable and replace deprecated code (#2194)
1 parent ed491cc commit b350ea0

File tree

11 files changed

+101
-21
lines changed

11 files changed

+101
-21
lines changed

examples/nextjs-swc/next.config.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,17 @@ const nextConfig: NextConfig = {
1111
}
1212
}
1313
}
14-
}
14+
},
15+
webpack: (config) => {
16+
config.module.rules.push({
17+
test: /\.po$/,
18+
use: {
19+
loader: "@lingui/loader",
20+
},
21+
});
22+
23+
return config;
24+
},
1525
}
1626

1727
export default nextConfig

examples/nextjs-swc/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
},
1414
"dependencies": {
1515
"@lingui/core": "^5.1.2",
16+
"@lingui/macro": "^5.2.0",
1617
"@lingui/react": "^5.1.2",
1718
"negotiator": "^0.6.3",
1819
"next": "15.0.1",

examples/nextjs-swc/src/app/[lang]/app-router-demo/page.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { HomePage } from '../../../components/HomePage'
2-
import { initLingui } from '../../../initLingui'
2+
import {initLingui, PageLangParam} from '../../../initLingui'
33

4-
export default async function Page(props) {
4+
export default async function Page(props: PageLangParam) {
55
const lang = (await props.params).lang
66
initLingui(lang)
77
return <HomePage />

examples/nextjs-swc/src/app/[lang]/layout.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ import linguiConfig from '../../../lingui.config'
22
import { allMessages, getI18nInstance } from '../../appRouterI18n'
33
import { LinguiClientProvider } from '../../components/LinguiClientProvider'
44
import { initLingui, PageLangParam } from '../../initLingui'
5-
import React from 'react'
6-
import { t } from '@lingui/macro'
7-
import { setI18n } from '@lingui/react/server'
5+
import React, {PropsWithChildren} from 'react'
6+
import { msg } from '@lingui/core/macro'
87

98
export async function generateStaticParams() {
109
return linguiConfig.locales.map((lang) => ({ lang }))
@@ -14,11 +13,11 @@ export async function generateMetadata(props: PageLangParam) {
1413
const i18n = getI18nInstance((await props.params).lang)
1514

1615
return {
17-
title: t(i18n)`Translation Demo`
16+
title: i18n._(msg`Translation Demo`)
1817
}
1918
}
2019

21-
export default async function RootLayout({ children, params }) {
20+
export default async function RootLayout({ children, params }: PropsWithChildren<PageLangParam>) {
2221
const lang = (await params).lang
2322
initLingui(lang)
2423

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
import Link from "next/link";
2+
13
export default function Index() {
24
return (
35
<>
46
This is the homepage of the demo app. This page is not localized. You can
5-
go to the <a href="/app-router-demo">App router demo</a> or the{' '}
6-
<a href="/pages-router-demo">Pages router demo</a>.
7+
go to the <Link href="/app-router-demo">App router demo</Link> or the{' '}
8+
<Link href="/pages-router-demo">Pages router demo</Link>.
79
</>
810
)
911
}

examples/nextjs-swc/src/components/HomePage.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import React from 'react'
22
import { useLingui } from '@lingui/react'
33
import Head from 'next/head'
4-
import { t, Trans } from '@lingui/macro'
4+
import { Trans } from '@lingui/react/macro'
5+
import { msg } from '@lingui/core/macro'
56
import { Switcher } from './Switcher'
67
import { AboutText } from './AboutText'
78
import Developers from './Developers'
@@ -16,9 +17,9 @@ export const HomePage = () => {
1617
{/*
1718
The Next Head component is not being rendered in the React
1819
component tree and React Context is not being passed down to the components placed in the <Head>.
19-
That means we cannot use the <Trans> component here and instead have to use `t` macro.
20+
That means we cannot use the <Trans> component here and instead have to use lazy translation with a message descriptor.
2021
*/}
21-
<title>{t(i18n)`Translation Demo`}</title>
22+
<title>{i18n._(msg`Translation Demo`)}</title>
2223
<link rel="icon" href="/favicon.ico" />
2324
</Head>
2425

examples/nextjs-swc/src/locales/en.po

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ msgstr "Serbian"
3838
msgid "Spanish"
3939
msgstr "Spanish"
4040

41+
#: src/components/HomePage.tsx:22
4142
#: src/app/[lang]/layout.tsx:16
42-
#: src/components/HomePage.tsx:21
4343
msgid "Translation Demo"
4444
msgstr "Translation Demo"
4545

46-
#: src/components/HomePage.tsx:28
46+
#: src/components/HomePage.tsx:29
4747
msgid "Welcome to <0>Next.js!</0>"
4848
msgstr "Welcome to <0>Next.js!</0>"

examples/nextjs-swc/src/locales/es.po

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ msgstr "Serbio"
3838
msgid "Spanish"
3939
msgstr "Español"
4040

41+
#: src/components/HomePage.tsx:22
4142
#: src/app/[lang]/layout.tsx:16
42-
#: src/components/HomePage.tsx:21
4343
msgid "Translation Demo"
4444
msgstr "Demostración de Traducción"
4545

46-
#: src/components/HomePage.tsx:28
46+
#: src/components/HomePage.tsx:29
4747
msgid "Welcome to <0>Next.js!</0>"
4848
msgstr "Bienvenido a <0>Next.js!</0>"

examples/nextjs-swc/src/locales/pseudo.po

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ msgstr ""
3838
msgid "Spanish"
3939
msgstr ""
4040

41+
#: src/components/HomePage.tsx:22
4142
#: src/app/[lang]/layout.tsx:16
42-
#: src/components/HomePage.tsx:21
4343
msgid "Translation Demo"
4444
msgstr ""
4545

46-
#: src/components/HomePage.tsx:28
46+
#: src/components/HomePage.tsx:29
4747
msgid "Welcome to <0>Next.js!</0>"
4848
msgstr ""

examples/nextjs-swc/src/locales/sr.po

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ msgstr "Српски"
3838
msgid "Spanish"
3939
msgstr "Шпански"
4040

41+
#: src/components/HomePage.tsx:22
4142
#: src/app/[lang]/layout.tsx:16
42-
#: src/components/HomePage.tsx:21
4343
msgid "Translation Demo"
4444
msgstr "Демо Превод"
4545

46-
#: src/components/HomePage.tsx:28
46+
#: src/components/HomePage.tsx:29
4747
msgid "Welcome to <0>Next.js!</0>"
4848
msgstr "Добродошли у <0>Нект.јс!</0>"

examples/nextjs-swc/yarn.lock

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,6 +1136,25 @@ __metadata:
11361136
languageName: node
11371137
linkType: hard
11381138

1139+
"@lingui/core@npm:5.2.0":
1140+
version: 5.2.0
1141+
resolution: "@lingui/core@npm:5.2.0"
1142+
dependencies:
1143+
"@babel/runtime": ^7.20.13
1144+
"@lingui/message-utils": 5.2.0
1145+
unraw: ^3.0.0
1146+
peerDependencies:
1147+
"@lingui/babel-plugin-lingui-macro": 5.2.0
1148+
babel-plugin-macros: 2 || 3
1149+
peerDependenciesMeta:
1150+
"@lingui/babel-plugin-lingui-macro":
1151+
optional: true
1152+
babel-plugin-macros:
1153+
optional: true
1154+
checksum: 4e00fa9674f521f10bffab16f0f1602a13a356f92a5f0b0a65e49eb4a8e5fcd3dfc162c32b3869463561a27562ca9948c95f25917d03937f500f57acc22544db
1155+
languageName: node
1156+
linkType: hard
1157+
11391158
"@lingui/core@npm:^5.1.2":
11401159
version: 5.1.2
11411160
resolution: "@lingui/core@npm:5.1.2"
@@ -1180,6 +1199,34 @@ __metadata:
11801199
languageName: node
11811200
linkType: hard
11821201

1202+
"@lingui/macro@npm:^5.2.0":
1203+
version: 5.2.0
1204+
resolution: "@lingui/macro@npm:5.2.0"
1205+
dependencies:
1206+
"@lingui/core": 5.2.0
1207+
"@lingui/react": 5.2.0
1208+
peerDependencies:
1209+
"@lingui/babel-plugin-lingui-macro": 5.2.0
1210+
babel-plugin-macros: 2 || 3
1211+
peerDependenciesMeta:
1212+
"@lingui/babel-plugin-lingui-macro":
1213+
optional: true
1214+
babel-plugin-macros:
1215+
optional: true
1216+
checksum: 3235820d46d185e7278a8f7694c30696ad3809dfac5b15e7c72500b7e971d9475d450f076cfb4478b93a77cb97bd28f43e2e450f82c73c860f6ec265391f9f95
1217+
languageName: node
1218+
linkType: hard
1219+
1220+
"@lingui/message-utils@npm:5.2.0":
1221+
version: 5.2.0
1222+
resolution: "@lingui/message-utils@npm:5.2.0"
1223+
dependencies:
1224+
"@messageformat/parser": ^5.0.0
1225+
js-sha256: ^0.10.1
1226+
checksum: 14b759404de1877551d540d0f046b57e8c3670670fec302fe6b17e602260f43046a6c42132db7c170d726f46a2cc4000e976b9c5c457d8c0e02a11eb339325c8
1227+
languageName: node
1228+
linkType: hard
1229+
11831230
"@lingui/message-utils@npm:^5.1.2":
11841231
version: 5.1.2
11851232
resolution: "@lingui/message-utils@npm:5.1.2"
@@ -1190,6 +1237,25 @@ __metadata:
11901237
languageName: node
11911238
linkType: hard
11921239

1240+
"@lingui/react@npm:5.2.0":
1241+
version: 5.2.0
1242+
resolution: "@lingui/react@npm:5.2.0"
1243+
dependencies:
1244+
"@babel/runtime": ^7.20.13
1245+
"@lingui/core": 5.2.0
1246+
peerDependencies:
1247+
"@lingui/babel-plugin-lingui-macro": 5.2.0
1248+
babel-plugin-macros: 2 || 3
1249+
react: ^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0
1250+
peerDependenciesMeta:
1251+
"@lingui/babel-plugin-lingui-macro":
1252+
optional: true
1253+
babel-plugin-macros:
1254+
optional: true
1255+
checksum: b7dde030d986529f79b3878ec7866440c5eaff693c01625bd6a228e576d0df9b9806676b52c05f5f45199f922df87fdac08540ac39c497fcb11eea59421bf901
1256+
languageName: node
1257+
linkType: hard
1258+
11931259
"@lingui/react@npm:^5.1.2":
11941260
version: 5.1.2
11951261
resolution: "@lingui/react@npm:5.1.2"
@@ -4986,6 +5052,7 @@ __metadata:
49865052
"@lingui/cli": ^5.1.2
49875053
"@lingui/core": ^5.1.2
49885054
"@lingui/loader": ^5.1.2
5055+
"@lingui/macro": ^5.2.0
49895056
"@lingui/react": ^5.1.2
49905057
"@lingui/swc-plugin": ^5.0.1
49915058
"@types/negotiator": ^0.6.3

0 commit comments

Comments
 (0)