Skip to content

Commit

Permalink
examples: update for next 15
Browse files Browse the repository at this point in the history
  • Loading branch information
timofei-iatsenko committed Oct 29, 2024
1 parent d0e45bc commit 4876a47
Show file tree
Hide file tree
Showing 10 changed files with 768 additions and 615 deletions.
2 changes: 1 addition & 1 deletion examples/nextjs-swc/next-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
/// <reference types="next/navigation-types/compat/navigation" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
// see https://nextjs.org/docs/app/building-your-application/configuring/typescript for more information.
19 changes: 0 additions & 19 deletions examples/nextjs-swc/next.config.js

This file was deleted.

17 changes: 17 additions & 0 deletions examples/nextjs-swc/next.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import type { NextConfig } from 'next'

const nextConfig: NextConfig = {
experimental: {
swcPlugins: [['@lingui/swc-plugin', {}]],
turbo: {
rules: {
'*.po': {
loaders: ['@lingui/loader'],
as: '*.js'
}
}
}
}
}

export default nextConfig
8 changes: 4 additions & 4 deletions examples/nextjs-swc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"dev": "next dev --turbopack",
"debug": "NODE_OPTIONS='--inspect' next dev",
"build": "yarn lingui:extract && next build",
"start": "next start",
Expand All @@ -15,20 +15,20 @@
"@lingui/core": "^4.11.0",
"@lingui/react": "^4.11.0",
"negotiator": "^0.6.3",
"next": "^14.2.3",
"next": "15.0.1",
"react": "18.2.0",
"react-dom": "18.2.0"
},
"devDependencies": {
"@lingui/cli": "^4.11.0",
"@lingui/loader": "^4.11.0",
"@lingui/macro": "^4.11.0",
"@lingui/swc-plugin": "4.0.7",
"@lingui/swc-plugin": "4.1.0",
"@types/negotiator": "^0.6.3",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"eslint": "^8.57.0",
"eslint-config-next": "^14.2.3",
"eslint-config-next": "15.0.1",
"typescript": "^5.4.5"
}
}
8 changes: 6 additions & 2 deletions examples/nextjs-swc/src/app/[lang]/app-router-demo/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { HomePage } from '../../../components/HomePage'
import { withLinguiPage } from '../../../withLingui'
import { initLingui } from '../../../initLingui'

export default withLinguiPage(HomePage)
export default async function Page(props) {
const lang = (await props.params).lang
initLingui(lang)
return <HomePage />
}
17 changes: 9 additions & 8 deletions examples/nextjs-swc/src/app/[lang]/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
import linguiConfig from '../../../lingui.config'
import { allMessages, getI18nInstance } from '../../appRouterI18n'
import { LinguiClientProvider } from '../../components/LinguiClientProvider'
import { PageLangParam, withLinguiLayout } from '../../withLingui'
import { initLingui, PageLangParam } from '../../initLingui'
import React from 'react'
import { t } from '@lingui/macro'
import { setI18n } from '@lingui/react/server'

export async function generateStaticParams() {
return linguiConfig.locales.map((lang) => ({ lang }))
}

export function generateMetadata({ params }: PageLangParam) {
const i18n = getI18nInstance(params.lang)
export async function generateMetadata(props: PageLangParam) {
const i18n = getI18nInstance((await props.params).lang)

return {
title: t(i18n)`Translation Demo`
}
}

export default withLinguiLayout(function RootLayout({
children,
params: { lang }
}) {
export default async function RootLayout({ children, params }) {
const lang = (await params).lang
initLingui(lang)

return (
<html lang={lang}>
<body className="bg-background text-foreground">
Expand All @@ -35,4 +36,4 @@ export default withLinguiLayout(function RootLayout({
</body>
</html>
)
})
}
12 changes: 12 additions & 0 deletions examples/nextjs-swc/src/initLingui.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { getI18nInstance } from './appRouterI18n'
import { setI18n } from '@lingui/react/server'

export type PageLangParam = {
params: Promise<{ lang: string }>
}

export function initLingui(lang: string) {
const i18n = getI18nInstance(lang)
setI18n(i18n)
return i18n
}
2 changes: 1 addition & 1 deletion examples/nextjs-swc/src/pagesRouterI18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useEffect } from 'react'
import { usePathname } from 'next/navigation'

export async function loadCatalog(locale: string) {
const catalog = await import(`@lingui/loader!./locales/${locale}.po`)
const catalog = await import(`./locales/${locale}.po`)
return catalog.messages
}

Expand Down
45 changes: 0 additions & 45 deletions examples/nextjs-swc/src/withLingui.tsx

This file was deleted.

Loading

0 comments on commit 4876a47

Please sign in to comment.