-
Notifications
You must be signed in to change notification settings - Fork 422
fix(examples): devinxi Tanstack Start example #2267
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
Open
depsimon
wants to merge
17
commits into
lingui:main
Choose a base branch
from
depsimon:tanstack-start-vite
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
e431791
Devinxi Tanstack Start example
depsimon 130c6f1
Share the same i18n instance in routes
depsimon 8cf412a
examples(tanstack-start): do not use global i18n in SSR app
timofei-iatsenko 007a65f
examples(tanstack-start): parse cookie only when needed
depsimon 4ef1bb4
examples(tanstack-start): remove unused imports
depsimon b73ab8d
examples(tanstack-start): add missing translations
depsimon 891290f
examples(tanstack-start): hydrate catalog from server
depsimon d6c2c27
examples(tanstack-start): prefer using the `msg` macro
depsimon 0c42e25
examples(tanstack-start): add URL-based localization
depsimon ba8bffb
examples(tanstack-start): apply prettier
depsimon 186dd0f
examples(tanstack-start): add content navigation
depsimon 86eec04
Merge branch 'lingui:main' into tanstack-start-vite
depsimon ccb980a
Upgrade example to Tanstack Start RC
depsimon aeb0a16
Cleanup
depsimon d22e47a
Use global start context
depsimon 14ac071
Fix initI8n
depsimon 2dff3b9
Apply prettier
depsimon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
63 changes: 63 additions & 0 deletions
63
examples/tanstack-start/src/modules/lingui/router-plugin.tsx
This file contains hidden or 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,63 @@ | ||
| import { Fragment, type PropsWithChildren } from 'react' | ||
| import { I18nProvider } from "@lingui/react" | ||
| import type { AnyRouter } from '@tanstack/react-router' | ||
| import { setupI18n, type I18n } from '@lingui/core' | ||
|
|
||
| type AdditionalOptions = { | ||
| WrapProvider?: (props: { children: any }) => React.JSX.Element | ||
| } | ||
|
|
||
| export type ValidateRouter<TRouter extends AnyRouter> = | ||
| NonNullable<TRouter['options']['context']> extends { | ||
| i18n: I18n | ||
| } | ||
| ? TRouter | ||
| : never | ||
|
|
||
| export function routerWithLingui<TRouter extends AnyRouter>( | ||
| router: ValidateRouter<TRouter>, | ||
| i18n: I18n, | ||
| additionalOpts?: AdditionalOptions, | ||
| ): TRouter { | ||
| const ogOptions = router.options | ||
|
|
||
| router.options = { | ||
| ...router.options, | ||
| dehydrate: () => { | ||
| return { | ||
| ...ogOptions.dehydrate?.(), | ||
| // When critical data is dehydrated, we also dehydrate the i18n messages | ||
| dehydratedI18n: { | ||
| locale: i18n.locale, | ||
| messages: i18n.messages, | ||
| }, | ||
| } | ||
| }, | ||
| hydrate: (dehydrated: any) => { | ||
| ogOptions.hydrate?.(dehydrated) | ||
| // On the client, hydrate the i18n catalog with the dehydrated data | ||
| i18n.loadAndActivate({ | ||
| locale: dehydrated.dehydratedI18n.locale, | ||
| messages: dehydrated.dehydratedI18n.messages, | ||
| }) | ||
| }, | ||
| context: { | ||
| ...ogOptions.context, | ||
| // Pass the query client to the context, so we can access it in loaders | ||
| i18n, | ||
| }, | ||
| // Wrap the app in a I18nProvider | ||
| Wrap: ({ children }: PropsWithChildren) => { | ||
| const OuterWrapper = additionalOpts?.WrapProvider || Fragment | ||
| const OGWrap = ogOptions.Wrap || Fragment | ||
|
|
||
| return <OuterWrapper> | ||
| <I18nProvider i18n={i18n}> | ||
| <OGWrap>{children}</OGWrap> | ||
| </I18nProvider> | ||
| </OuterWrapper> | ||
| }, | ||
| } | ||
|
|
||
| return router | ||
| } |
This file contains hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.