-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
changes #2
base: main
Are you sure you want to change the base?
changes #2
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { useLinguiSSR } from "@/i18n/i18n"; | ||
import { LinguiProvider } from "@/i18n/lingui-provider"; | ||
import { Trans } from "@lingui/macro"; | ||
|
||
export default async function LocaleLayout({ | ||
params, | ||
children, | ||
}: { | ||
params: any; | ||
children: React.ReactNode; | ||
}) { | ||
const i18n = await useLinguiSSR(params.locale); | ||
|
||
return ( | ||
<LinguiProvider locale={i18n.locale} messages={i18n.messages}> | ||
<Trans>Locale Layout</Trans> | ||
{children} | ||
</LinguiProvider> | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { Trans } from "@lingui/macro"; | ||
import { useLinguiSSR } from "@/i18n/i18n"; | ||
import Link from "next/link"; | ||
|
||
export default async function Nested({ params }) { | ||
// without this, the page crashes when navigating from the parent page (no full refresh) | ||
// uncomment it to make it work in all cases. | ||
//await useLinguiSSR(params.locale); | ||
|
||
return ( | ||
<> | ||
<br /> | ||
<Trans>Nested page</Trans> | ||
<br /> | ||
<Link href={`/${params.locale}`}> | ||
<Trans> | ||
<b>Parent page</b> | ||
</Trans> | ||
</Link> | ||
</> | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,16 @@ | ||
import React from "react" | ||
|
||
import { getI18n } from './i18n'; | ||
import { useLinguiSSR} from './i18n'; | ||
import { TransNoContext, TransProps } from '@lingui/react/server'; | ||
|
||
export function Trans(props: TransProps): React.ReactElement<any, any> | null { | ||
const i18n = getI18n() | ||
|
||
|
||
export async function Trans(props: TransProps): Promise<React.ReactElement<any, any> | null> { | ||
const i18n = await useLinguiSSR(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if somehow we could get the locale here, it wouldn't be necesary to |
||
|
||
if (!i18n) { | ||
throw new Error('Lingui for RSC is not initialized. Use `setI18n()` first in root of your RSC tree.'); | ||
} | ||
|
||
return <TransNoContext {...props} lingui={{ i18n }}/> | ||
return <TransNoContext {...props} lingui={{i18n}}/> | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i don't see where this
LinguiProvider
came from? it's not in thesrc/i18n/i18n.ts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@thekip, it's the same one that's already in the repo.
i18n.messages
is a getter that returns the messages for the current locale. To make it work correctly with the implementation of the provider that's in the repo, a private property with all messages should be passed: