-
Notifications
You must be signed in to change notification settings - Fork 382
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'lingui:main' into extract-files-obsolete-filx
- Loading branch information
Showing
54 changed files
with
12,813 additions
and
867 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
/// <reference types="next" /> | ||
/// <reference types="next/image-types/global" /> | ||
/// <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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,19 @@ | ||
/** @type {import('next').NextConfig} */ | ||
module.exports = { | ||
i18n: { | ||
// These are all the locales you want to support in | ||
// your application | ||
locales: ['en', 'sr', 'es', 'pseudo'], | ||
defaultLocale: 'en' | ||
// i18n: { | ||
// this option has been replaced by the middleware in src/ | ||
// when migrating to support app router | ||
// }, | ||
webpack: (config) => { | ||
config.module.rules.push({ | ||
test: /\.po$/, | ||
use: { | ||
loader: '@lingui/loader' | ||
} | ||
}) | ||
return config | ||
}, | ||
experimental: { | ||
swcPlugins: [ | ||
['@lingui/swc-plugin', {}], | ||
], | ||
}, | ||
swcPlugins: [['@lingui/swc-plugin', {}]] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { HomePage } from '../../../components/HomePage' | ||
import { withLinguiPage } from '../../../withLingui' | ||
|
||
export default withLinguiPage(HomePage) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import linguiConfig from '../../../lingui.config' | ||
import { allI18nInstances, allMessages } from '../../appRouterI18n' | ||
import { LinguiClientProvider } from '../../components/LinguiClientProvider' | ||
import { PageLangParam, withLinguiLayout } from '../../withLingui' | ||
import React from 'react' | ||
import { t } from '@lingui/macro' | ||
|
||
export async function generateStaticParams() { | ||
return linguiConfig.locales.map((lang) => ({ lang })) | ||
} | ||
|
||
export function generateMetadata({ params }: PageLangParam) { | ||
const i18n = allI18nInstances[params.lang]! | ||
|
||
return { | ||
title: t(i18n)`Translation Demo` | ||
} | ||
} | ||
|
||
export default withLinguiLayout(function RootLayout({ | ||
children, | ||
params: { lang } | ||
}) { | ||
return ( | ||
<html lang={lang}> | ||
<body className="bg-background text-foreground"> | ||
<main className="min-h-screen flex flex-col"> | ||
<LinguiClientProvider | ||
initialLocale={lang} | ||
initialMessages={allMessages[lang]!} | ||
> | ||
{children} | ||
</LinguiClientProvider> | ||
</main> | ||
</body> | ||
</html> | ||
) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export default function Index() { | ||
return ( | ||
<> | ||
This is the homepage of the demo app. This page is not localized. You can | ||
go to the <a href="/app-router-demo">App router demo</a> or the{' '} | ||
<a href="/pages-router-demo">Pages router demo</a>. | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import 'server-only' | ||
|
||
import linguiConfig from '../lingui.config' | ||
import { I18n, Messages, setupI18n } from '@lingui/core' | ||
|
||
const { locales } = linguiConfig | ||
// optionally use a stricter union type | ||
type SupportedLocales = string | ||
|
||
async function loadCatalog(locale: SupportedLocales): Promise<{ | ||
[k: string]: Messages | ||
}> { | ||
const { messages } = await import(`./locales/${locale}.po`) | ||
return { | ||
[locale]: messages | ||
} | ||
} | ||
const catalogs = await Promise.all(locales.map(loadCatalog)) | ||
|
||
// transform array of catalogs into a single object | ||
export const allMessages = catalogs.reduce((acc, oneCatalog) => { | ||
return { ...acc, ...oneCatalog } | ||
}, {}) | ||
|
||
type AllI18nInstances = { [K in SupportedLocales]: I18n } | ||
|
||
export const allI18nInstances: AllI18nInstances = locales.reduce( | ||
(acc, locale) => { | ||
const messages = allMessages[locale] ?? {} | ||
const i18n = setupI18n({ | ||
locale, | ||
messages: { [locale]: messages } | ||
}) | ||
return { ...acc, [locale]: i18n } | ||
}, | ||
{} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
examples/nextjs-swc/src/components/LinguiClientProvider.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
'use client' | ||
|
||
import { I18nProvider } from '@lingui/react' | ||
import { type Messages, setupI18n } from '@lingui/core' | ||
import { useState } from 'react' | ||
|
||
type Props = { | ||
children: React.ReactNode | ||
initialLocale: string | ||
initialMessages: Messages | ||
} | ||
|
||
export function LinguiClientProvider({ | ||
children, | ||
initialLocale, | ||
initialMessages | ||
}: Props) { | ||
const [i18n] = useState(() => { | ||
return setupI18n({ | ||
locale: initialLocale, | ||
messages: { [initialLocale]: initialMessages } | ||
}) | ||
}) | ||
return <I18nProvider i18n={i18n}>{children}</I18nProvider> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.