-
Notifications
You must be signed in to change notification settings - Fork 2k
Hosting Dashboard: Introduce I18nProvider to make translation work correctly #103299
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 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,26 @@ | ||||
import defaultCalypsoI18n from 'i18n-calypso'; | ||||
import { useEffect } from 'react'; | ||||
import { setupLocale } from 'calypso/boot/locale'; | ||||
import CalypsoI18nProvider from 'calypso/components/calypso-i18n-provider'; | ||||
import switchLocale from 'calypso/lib/i18n-utils/switch-locale'; | ||||
import { useAuth } from '../auth'; | ||||
|
||||
export function I18nProvider( { children }: { children: React.ReactNode } ) { | ||||
const { user } = useAuth(); | ||||
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. I checked out this locally. I found that the new language I set in
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. We probably need to invalidate React Query caches for anything that depends on https://tanstack.com/query/latest/docs/framework/react/guides/query-invalidation |
||||
|
||||
useEffect( () => { | ||||
if ( ! user.language ) { | ||||
return; | ||||
} | ||||
|
||||
const locale = setupLocale( user ); | ||||
|
||||
// The `switchLocale` function is normally called within the `setLocale` action. However, | ||||
// since we don't have access to the Redux store in this context, we need to call it manually. | ||||
if ( locale ) { | ||||
switchLocale( locale ); | ||||
} | ||||
}, [ user.language ] ); | ||||
|
||||
return <CalypsoI18nProvider i18n={ defaultCalypsoI18n }>{ children }</CalypsoI18nProvider>; | ||||
} |
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.
The
reduxStore
optionality feels a bit suboptimal here 😬 It's not clear what it means: is it because the global Redux store has not been initialized yet, or because we don't intend to have one at all? Definitely feels like a code smell to avoid.There could be some opportunities for decoupling and reusability, but in general, I agree with what @jsnajdr suggested above, which is, building a simpler version that works with the constraints at hand.