Skip to content

Conversation

@hyoban
Copy link
Member

@hyoban hyoban commented Dec 29, 2025

Important

  1. Make sure you have read our contribution guidelines
  2. Ensure there is an associated issue and you have been assigned to it
  3. Use the correct syntax to link this PR: Fixes #<issue number>.

Summary

fixes #30311
fixes #30133

Screenshots

Before After
... ...

Checklist

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran dev/reformat(backend) and cd web && npx lint-staged(frontend) to appease the lint gods

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @hyoban, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly refactors the internationalization (i18n) system within the frontend application. The primary goal is to streamline locale management by transitioning from a custom context-based approach to a more standard and efficient hook-based method using react-i18next. This change not only simplifies the code for accessing locale information but also enhances both client-side language detection capabilities and server-side rendering performance for translations.

Highlights

  • I18n Context Refactor: The legacy I18NContext and useI18N have been replaced with a new useLocale hook that directly leverages react-i18next's useTranslation hook for accessing the current locale. This simplifies locale access and removes the need for use-context-selector in many components.
  • Client-side Language Detection: The i18next-browser-languagedetector library has been integrated into the i18n configuration, enabling automatic detection of the user's preferred language from the browser.
  • Server-side I18n Optimization: A serverOnlyContext utility has been introduced to cache i18n instances and locale information on the server, preventing redundant initialization and improving performance for server-side rendering.
  • Codebase Cleanup: Numerous files across the web directory have been updated to reflect these changes, removing direct useContext calls for I18NContext and updating imports to use the new useLocale hook.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the internationalization (i18n) implementation across the codebase by replacing direct usage of useContext(I18NContext) or useI18N() with a new useLocale() hook. The I18NContext and useI18N hook have been removed from the @/context/i18n module. The I18n component in web/app/components/i18n.tsx was updated to use useLocale() and no longer provides a context. Additionally, i18next-browser-languagedetector was introduced and configured in i18next-config.ts to automatically detect the user's language. Server-side rendering for i18n was also optimized by introducing serverOnlyContext to cache locale and i18n instances, preventing redundant initializations. Corresponding test files were updated to reflect these changes, mocking useLocale instead of I18NContext.Provider.

@hyoban hyoban marked this pull request as ready for review December 30, 2025 06:05
Copilot AI review requested due to automatic review settings December 30, 2025 06:05
@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Dec 30, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the i18n (internationalization) implementation by migrating from a React Context-based approach to using Jotai atoms for state management. The main changes include replacing the useI18N() hook with a simpler useLocale() hook, introducing server-side caching for locale detection and i18n instances, and updating all consumers throughout the codebase.

Key Changes

  • Introduced Jotai library for client-side locale state management with localeAtom
  • Added server-side caching utilities using React's cache() API for locale and i18n instances
  • Replaced context-based useI18N() hook with atom-based useLocale() hook across the entire codebase
  • Updated 50+ component files and test files to use the new API

Reviewed changes

Copilot reviewed 65 out of 66 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
web/utils/server-only-context.ts New utility for server-side caching using React cache API
web/package.json Added Jotai dependency for atom-based state management
web/pnpm-lock.yaml Lock file updates for Jotai package
web/i18n-config/server.ts Refactored server-side i18n with caching for locale detection and i18n instances
web/i18n-config/i18next-config.ts Removed empty line (formatting)
web/i18n-config/DEV.md Updated documentation to reflect useI18N → useLocale rename
web/context/i18n.ts Replaced Context-based implementation with Jotai atom-based hooks
web/app/components/i18n.tsx Updated to hydrate localeAtom instead of providing Context
web/app/components/with-i18n.tsx Removed obsolete HOC component
web/hooks/use-format-time-from-now.ts Updated to use useLocale() instead of useI18N()
web/hooks/use-format-time-from-now.spec.ts Updated test mocks for useLocale()
web/app/signin/_header.tsx Updated to use useLocale() and import setLocaleOnClient directly
web/app/signin/invite-settings/page.tsx Updated to import setLocaleOnClient directly instead of from context
web/app/signin/components/mail-and-password-auth.tsx Updated to use useLocale()
web/app/signin/components/mail-and-code-auth.tsx Updated to use useLocale()
web/app/signin/check-code/page.tsx Updated to use useLocale()
web/app/signup/components/input-mail.tsx Updated to use useLocale()
web/app/signup/check-code/page.tsx Updated to use useLocale()
web/app/reset-password/page.tsx Updated to use useLocale()
web/app/reset-password/check-code/page.tsx Updated to use useLocale()
web/app/components/workflow/nodes/document-extractor/panel.tsx Updated to use useLocale()
web/app/components/workflow/block-selector/rag-tool-recommendations/uninstalled-item.tsx Updated to use useLocale()
web/app/components/workflow/block-selector/market-place-plugin/item.tsx Updated to use useLocale()
web/app/components/tools/provider/tool-item.tsx Updated to use useLocale()
web/app/components/tools/provider/detail.tsx Updated to use useLocale()
web/app/components/tools/provider/custom-create-card.tsx Updated to use useLocale()
web/app/components/tools/mcp/detail/tool-item.tsx Updated to use useLocale()
web/app/components/tools/mcp/create-card.tsx Updated to use useLocale()
web/app/components/tools/edit-custom-collection-modal/test-api.tsx Updated to use useLocale()
web/app/components/tools/edit-custom-collection-modal/test-api.spec.tsx Updated test to mock useLocale() directly
web/app/components/plugins/provider-card.tsx Updated to use useLocale()
web/app/components/plugins/plugin-page/index.tsx Updated to use useLocale()
web/app/components/plugins/plugin-page/debug-info.tsx Updated to use useLocale()
web/app/components/plugins/plugin-detail-panel/detail-header.tsx Updated to use useLocale()
web/app/components/plugins/marketplace/list/index.spec.tsx Added useLocale mock to existing test
web/app/components/plugins/marketplace/list/card-wrapper.tsx Updated to use useLocale()
web/app/components/plugins/marketplace/description/index.tsx Renamed translate import alias back to getTranslation
web/app/components/header/account-setting/model-provider-page/hooks.ts Updated to use useLocale()
web/app/components/header/account-setting/model-provider-page/hooks.spec.ts Updated test to mock useLocale()
web/app/components/header/account-setting/members-page/invite-modal/index.tsx Updated to use useLocale()
web/app/components/header/account-setting/members-page/index.tsx Updated to use useLocale()
web/app/components/header/account-setting/language-page/index.tsx Updated to import setLocaleOnClient directly
web/app/components/develop/doc.tsx Updated to use useLocale()
web/app/components/datasets/documents/detail/batch-modal/csv-downloader.tsx Updated to use useLocale()
web/app/components/datasets/documents/create-from-pipeline/data-source/local-file/index.tsx Updated to use useLocale()
web/app/components/datasets/create/step-two/index.tsx Updated to use useLocale()
web/app/components/datasets/create/file-uploader/index.tsx Updated to use useLocale()
web/app/components/datasets/create-from-pipeline/list/built-in-pipeline-list.tsx Updated to use useLocale()
web/app/components/base/features/new-feature-panel/moderation/moderation-setting-modal.tsx Updated to use useLocale()
web/app/components/base/features/new-feature-panel/moderation/index.tsx Updated to use useLocale()
web/app/components/base/features/new-feature-panel/moderation/form-generation.tsx Updated to use useLocale()
web/app/components/base/agent-log-modal/tool-call.tsx Updated to use useLocale()
web/app/components/app/configuration/tools/external-data-tool-modal.tsx Updated to use useLocale()
web/app/components/app/configuration/config/agent/agent-tools/setting-built-in-tool.tsx Updated to use useLocale()
web/app/components/app/configuration/config/agent/agent-tools/setting-built-in-tool.spec.tsx Updated test to mock useLocale() directly
web/app/components/app/annotation/header-opts/index.tsx Updated to use useLocale()
web/app/components/app/annotation/header-opts/index.spec.tsx Updated test to mock useLocale()
web/app/components/app/annotation/batch-add-annotation-modal/csv-downloader.tsx Updated to use useLocale()
web/app/components/app/annotation/batch-add-annotation-modal/csv-downloader.spec.tsx Updated test to mock useLocale()
web/app/(shareLayout)/webapp-signin/components/mail-and-password-auth.tsx Updated to use useLocale()
web/app/(shareLayout)/webapp-signin/components/mail-and-code-auth.tsx Updated to use useLocale()
web/app/(shareLayout)/webapp-signin/check-code/page.tsx Updated to use useLocale()
web/app/(shareLayout)/webapp-reset-password/page.tsx Updated to use useLocale()
web/app/(shareLayout)/webapp-reset-password/check-code/page.tsx Updated to use useLocale()
web/app/(commonLayout)/app/(appDetailLayout)/[appId]/overview/time-range-picker/index.tsx Updated to use useLocale()
web/app/(commonLayout)/app/(appDetailLayout)/[appId]/overview/time-range-picker/date-picker.tsx Updated to use useLocale()
Files not reviewed (1)
  • web/pnpm-lock.yaml: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Dec 30, 2025
@hyoban hyoban merged commit 2399d00 into main Dec 30, 2025
16 checks passed
@hyoban hyoban deleted the 12-29-locales branch December 30, 2025 06:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Refactor/Chore] No refresh when switching language Support default system language detection

3 participants