refactor(i18n): about locales#83
Conversation
Greptile SummaryThis PR refactors the i18n (internationalization) architecture from React Context API to Jotai atom-based state management. Key Changes:
Critical Issue Found:
Confidence Score: 2/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant Browser
participant ServerComponent
participant getLocaleOnServer
participant serverOnlyContext
participant getTranslation
participant I18nInstance
participant ClientComponent
participant JotaiAtom
Note over Browser,JotaiAtom: Server-Side Rendering Phase
Browser->>ServerComponent: Request page
ServerComponent->>getLocaleOnServer: Get locale for request
getLocaleOnServer->>serverOnlyContext: Check cached locale
alt No cache
getLocaleOnServer->>getLocaleOnServer: Read cookies/headers
getLocaleOnServer->>getLocaleOnServer: Match locale
getLocaleOnServer->>serverOnlyContext: Cache locale
end
getLocaleOnServer-->>ServerComponent: Return locale
ServerComponent->>getTranslation: Get translations (locale, namespace)
getTranslation->>serverOnlyContext: Check cached i18n instance
alt No instance
getTranslation->>I18nInstance: Create shared instance (en-US)
getTranslation->>serverOnlyContext: Cache instance
end
getTranslation->>I18nInstance: Load namespace if needed
getTranslation->>I18nInstance: getFixedT(locale, namespace)
getTranslation-->>ServerComponent: Return {t, i18n}
ServerComponent-->>Browser: Render HTML with locale
Note over Browser,JotaiAtom: Client-Side Hydration Phase
Browser->>ClientComponent: Hydrate React app
ClientComponent->>JotaiAtom: useHydrateAtoms(localeAtom, locale)
ClientComponent->>ClientComponent: setLocaleOnClient(locale)
Note over Browser,JotaiAtom: Client-Side Usage
ClientComponent->>JotaiAtom: useLocale()
JotaiAtom-->>ClientComponent: Return current locale
ClientComponent->>ClientComponent: useTranslation() via react-i18next
|
| return (path?: string, pathMap?: { [index: string]: string }): string => { | ||
| const pathUrl = path || '' | ||
| let targetPath = (pathMap) ? pathMap[locale] || pathUrl : pathUrl | ||
| let targetPath = (pathMap) ? pathMap[docLanguage] || pathUrl : pathUrl |
There was a problem hiding this comment.
logic: Using docLanguage instead of locale breaks existing pathMap usage. The docLanguage returns lowercase values like 'zh-hans' while existing code uses locale keys like 'zh-Hans' (see history-panel.tsx:49).
Suggested change
| let targetPath = (pathMap) ? pathMap[docLanguage] || pathUrl : pathUrl | |
| let targetPath = (pathMap) ? pathMap[locale] || pathUrl : pathUrl |
Prompt To Fix With AI
This is a comment left during a code review.
Path: web/context/i18n.ts
Line: 29:29
Comment:
**logic:** Using `docLanguage` instead of `locale` breaks existing `pathMap` usage. The `docLanguage` returns lowercase values like `'zh-hans'` while existing code uses locale keys like `'zh-Hans'` (see `history-panel.tsx:49`).
```suggestion
let targetPath = (pathMap) ? pathMap[locale] || pathUrl : pathUrl
```
How can I resolve this? If you propose a fix, please make it concise.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Benchmark PR from qodo-benchmark#279