Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.
Python agentagentic-aiagentic-frameworkagentic-workflowaiautomationclaudedeepseekgenaigptllmlow-codemcpnextjsno-codeopenaipythonskillsworkflow
refactor(web): remove useMixedTranslation, better resource loading (#30630)
Stephen Zhoue335cd0ef42f
diff --git a/web/__tests__/goto-anything/search-error-handling.test.ts b/web/__tests__/goto-anything/search-error-handling.test.tsindex 3a495834cd3..42eb8295839 100644--- a/web/__tests__/goto-anything/search-error-handling.test.ts+++ b/web/__tests__/goto-anything/search-error-handling.test.ts@@ -14,6 +14,14 @@ import { fetchAppList } from '@/service/apps'import { postMarketplace } from '@/service/base'import { fetchDatasets } from '@/service/datasets'+// Mock react-i18next before importing modules that use it+vi.mock('react-i18next', () => ({+ getI18n: () => ({+ t: (key: string) => key,+ language: 'en',+ }),+}))+// Mock API functionsvi.mock('@/service/base', () => ({postMarketplace: vi.fn(),diff --git a/web/app/(commonLayout)/plugins/page.tsx b/web/app/(commonLayout)/plugins/page.tsxindex 2df9cf23c4f..81bda3a8a31 100644--- a/web/app/(commonLayout)/plugins/page.tsx+++ b/web/app/(commonLayout)/plugins/page.tsx@@ -1,14 +1,12 @@import Marketplace from '@/app/components/plugins/marketplace'import PluginPage from '@/app/components/plugins/plugin-page'import PluginsPanel from '@/app/components/plugins/plugin-page/plugins-panel'-import { getLocaleOnServer } from '@/i18n-config/server'const PluginList = async () => {- const locale = await getLocaleOnServer()return (<PluginPageplugins={<PluginsPanel />}- marketplace={<Marketplace locale={locale} pluginTypeSwitchClassName="top-[60px]" showSearchParams={false} />}+ marketplace={<Marketplace pluginTypeSwitchClassName="top-[60px]" showSearchParams={false} />}/>)}diff --git a/web/app/components/base/chat/chat-with-history/hooks.spec.tsx b/web/app/components/base/chat/chat-with-history/hooks.spec.tsxindex 32ef133453c..a6d51d8643c 100644--- a/web/app/components/base/chat/chat-with-history/hooks.spec.tsx+++ b/web/app/components/base/chat/chat-with-history/hooks.spec.tsx@@ -17,7 +17,7 @@ vi.mock('@/hooks/use-app-favicon', () => ({useAppFavicon: vi.fn(),}))-vi.mock('@/i18n-config/i18next-config', () => ({+vi.mock('@/i18n-config/client', () => ({changeLanguage: vi.fn().mockResolvedValue(undefined),}))diff --git a/web/app/components/base/chat/chat-with-history/hooks.tsx b/web/app/components/base/chat/chat-with-history/hooks.tsxindex 5ff8e61ff61..ed1981b5300 100644--- a/web/app/components/base/chat/chat-with-history/hooks.tsx+++ b/web/app/components/base/chat/chat-with-history/hooks.tsx@@ -25,7 +25,7 @@ import { useToastContext } from '@/app/components/base/toast'import { InputVarType } from '@/app/components/workflow/types'import { useWebAppStore } from '@/context/web-app-context'import { useAppFavicon } from '@/hooks/use-app-favicon'-import { changeLanguage } from '@/i18n-config/i18next-config'+import { changeLanguage } from '@/i18n-config/client'import {delConversation,pinConversation,diff --git a/web/app/components/base/chat/embedded-chatbot/hooks.spec.tsx b/web/app/components/base/chat/embedded-chatbot/hooks.spec.tsxindex ca6a90c4d8c..066fb8ebe92 100644--- a/web/app/components/base/chat/embedded-chatbot/hooks.spec.tsx+++ b/web/app/components/base/chat/embedded-chatbot/hooks.spec.tsx@@ -13,7 +13,7 @@ import { shareQueryKeys } from '@/service/use-share'import { CONVERSATION_ID_INFO } from '../constants'import { useEmbeddedChatbot } from './hooks'-vi.mock('@/i18n-config/i18next-config', () => ({+vi.mock('@/i18n-config/client', () => ({changeLanguage: vi.fn().mockResolvedValue(undefined),}))diff --git a/web/app/components/base/chat/embedded-chatbot/hooks.tsx b/web/app/components/base/chat/embedded-chatbot/hooks.tsxindex 803e9058370..9028d10000d 100644--- a/web/app/components/base/chat/embedded-chatbot/hooks.tsx+++ b/web/app/components/base/chat/embedded-chatbot/hooks.tsx@@ -23,7 +23,7 @@ import { useToastContext } from '@/app/components/base/toast'import { addFileInfos, sortAgentSorts } from '@/app/components/tools/utils'import { InputVarType } from '@/app/components/workflow/types'import { useWebAppStore } from '@/context/web-app-context'-import { changeLanguage } from '@/i18n-config/i18next-config'+import { changeLanguage } from '@/i18n-config/client'import { updateFeedback } from '@/service/share'import {useInvalidateShareConversations,diff --git a/web/app/components/goto-anything/actions/commands/account.tsx b/web/app/components/goto-anything/actions/commands/account.tsxindex 6465932a75b..d1fa36b6f0f 100644--- a/web/app/components/goto-anything/actions/commands/account.tsx+++ b/web/app/components/goto-anything/actions/commands/account.tsx@@ -1,7 +1,7 @@import type { SlashCommandHandler } from './types'import { RiUser3Line } from '@remixicon/react'import * as React from 'react'-import i18n from '@/i18n-config/i18next-config'+import { getI18n } from 'react-i18next'import { registerCommands, unregisterCommands } from './command-bus'// Account command dependency types - no external dependencies needed@@ -21,6 +21,7 @@ export const accountCommand: SlashCommandHandler<AccountDeps> = {},async search(args: string, locale: string = 'en') {+ const i18n = getI18n()return [{id: 'account',title: i18n.t('account.account', { ns: 'common', lng: locale }),diff --git a/web/app/components/goto-anything/actions/commands/community.tsx b/web/app/components/goto-anything/actions/commands/community.tsxindex fcd9a150004..685149402d1 100644--- a/web/app/components/goto-anything/actions/commands/community.tsx+++ b/web/app/components/goto-anything/actions/commands/community.tsx@@ -1,7 +1,7 @@import type { SlashCommandHandler } from './types'import { RiDiscordLine } from '@remixicon/react'import * as React from 'react'-import i18n from '@/i18n-config/i18next-config'+import { getI18n } from 'react-i18next'import { registerCommands, unregisterCommands } from './command-bus'// Community command dependency types@@ -22,6 +22,7 @@ export const communityCommand: SlashCommandHandler<CommunityDeps> = {},async search(args: string, locale: string = 'en') {+ const i18n = getI18n()return [{id: 'community',title: i18n.t('userProfile.community', { ns: 'common', lng: locale }),diff --git a/web/app/components/goto-anything/actions/commands/docs.tsx b/web/app/components/goto-anything/actions/commands/docs.tsxindex 9f09d320943..8b04e841570 100644--- a/web/app/components/goto-anything/actions/commands/docs.tsx+++ b/web/app/components/goto-anything/actions/commands/docs.tsx@@ -1,8 +1,8 @@import type { SlashCommandHandler } from './types'import { RiBookOpenLine } from '@remixicon/react'import * as React from 'react'+import { getI18n } from 'react-i18next'import { defaultDocBaseUrl } from '@/context/i18n'-import i18n from '@/i18n-config/i18next-config'import { getDocLanguage } from '@/i18n-config/language'import { registerCommands, unregisterCommands } from './command-bus'@@ -19,6 +19,7 @@ export const docsCommand: SlashCommandHandler<DocDeps> = {// Direct execution functionexecute: () => {+ const i18n = getI18n()const currentLocale = i18n.languageconst docLanguage = getDocLanguage(currentLocale)const url = `${defaultDocBaseUrl}/${docLanguage}`@@ -26,6 +27,7 @@ export const docsCommand: SlashCommandHandler<DocDeps> = {},async search(args: string, locale: string = 'en') {+ const i18n = getI18n()return [{id: 'doc',title: i18n.t('userProfile.helpCenter', { ns: 'common', lng: locale }),@@ -41,6 +43,7 @@ export const docsCommand: SlashCommandHandler<DocDeps> = {},register(_deps: DocDeps) {+ const i18n = getI18n()registerCommands({'navigation.doc': async (_args) => {// Get the current language from i18ndiff --git a/web/app/components/goto-anything/actions/commands/forum.tsx b/web/app/components/goto-anything/actions/commands/forum.tsxindex e32632b4b52..36116ceb1f8 100644--- a/web/app/components/goto-anything/actions/commands/forum.tsx+++ b/web/app/components/goto-anything/actions/commands/forum.tsx@@ -1,7 +1,7 @@import type { SlashCommandHandler } from './types'import { RiFeedbackLine } from '@remixicon/react'import * as React from 'react'-import i18n from '@/i18n-config/i18next-config'+import { getI18n } from 'react-i18next'import { registerCommands, unregisterCommands } from './command-bus'// Forum command dependency types@@ -22,6 +22,7 @@ export const forumCommand: SlashCommandHandler<ForumDeps> = {},async search(args: string, locale: string = 'en') {+ const i18n = getI18n()return [{id: 'forum',title: i18n.t('userProfile.forum', { ns: 'common', lng: locale }),diff --git a/web/app/components/goto-anything/actions/commands/language.tsx b/web/app/components/goto-anything/actions/commands/language.tsxindex df94fd49ce2..f4bafc1d582 100644--- a/web/app/components/goto-anything/actions/commands/language.tsx+++ b/web/app/components/goto-anything/actions/commands/language.tsx@@ -1,6 +1,6 @@import type { CommandSearchResult } from '../types'import type { SlashCommandHandler } from './types'-import i18n from '@/i18n-config/i18next-config'+import { getI18n } from 'react-i18next'import { languages } from '@/i18n-config/language'import { registerCommands, unregisterCommands } from './command-bus'@@ -14,6 +14,7 @@ const buildLanguageCommands = (query: string): CommandSearchResult[] => {const list = languages.filter(item => item.supported && (!q || item.name.toLowerCase().includes(q) || String(item.value).toLowerCase().includes(q)))+ const i18n = getI18n()return list.map(item => ({id: `lang-${item.value}`,title: item.name,diff --git a/web/app/components/goto-anything/actions/commands/slash.tsx b/web/app/components/goto-anything/actions/commands/slash.tsxindex ec0f333cd46..6aad67731f7 100644--- a/web/app/components/goto-anything/actions/commands/slash.tsx+++ b/web/app/components/goto-anything/actions/commands/slash.tsx@@ -2,8 +2,8 @@import type { ActionItem } from '../types'import { useTheme } from 'next-themes'import { useEffect } from 'react'+import { getI18n } from 'react-i18next'import { setLocaleOnClient } from '@/i18n-config'-import i18n from '@/i18n-config/i18next-config'import { accountCommand } from './account'import { executeCommand } from './command-bus'import { communityCommand } from './community'@@ -14,6 +14,8 @@ import { slashCommandRegistry } from './registry'import { themeCommand } from './theme'import { zenCommand } from './zen'+const i18n = getI18n()+export const slashAction: ActionItem = {key: '/',shortcut: '/',diff --git a/web/app/components/goto-anything/actions/commands/theme.tsx b/web/app/components/goto-anything/actions/commands/theme.tsxindex 335182af670..ba1416229dd 100644--- a/web/app/components/goto-anything/actions/commands/theme.tsx+++ b/web/app/components/goto-anything/actions/commands/theme.tsx@@ -2,7 +2,7 @@ import type { CommandSearchResult } from '../types'import type { SlashCommandHandler } from './types'import { RiComputerLine, RiMoonLine, RiSunLine } from '@remixicon/react'import * as React from 'react'-import i18n from '@/i18n-config/i18next-config'+import { getI18n } from 'react-i18next'import { registerCommands, unregisterCommands } from './command-bus'// Theme dependency types@@ -32,6 +32,7 @@ const THEME_ITEMS = [] as constconst buildThemeCommands = (query: string, locale?: string): CommandSearchResult[] => {+ const i18n = getI18n()const q = query.toLowerCase()const list = THEME_ITEMS.filter(item =>!qdiff --git a/web/app/components/goto-anything/actions/commands/zen.tsx b/web/app/components/goto-anything/actions/commands/zen.tsxindex d6d9f1e5a2f..1645e40fd91 100644--- a/web/app/components/goto-anything/actions/commands/zen.tsx+++ b/web/app/components/goto-anything/actions/commands/zen.tsx@@ -1,8 +1,8 @@import type { SlashCommandHandler } from './types'import { RiFullscreenLine } from '@remixicon/react'import * as React from 'react'+import { getI18n } from 'react-i18next'import { isInWorkflowPage } from '@/app/components/workflow/constants'-import i18n from '@/i18n-config/i18next-config'import { registerCommands, unregisterCommands } from './command-bus'// Zen command dependency types - no external dependencies needed@@ -32,6 +32,7 @@ export const zenCommand: SlashCommandHandler<ZenDeps> = {execute: toggleZenMode,async search(_args: string, locale: string = 'en') {+ const i18n = getI18n()return [{id: 'zen',title: i18n.t('gotoAnything.actions.zenTitle', { ns: 'app', lng: locale }) || 'Zen Mode',diff --git a/web/app/components/header/account-setting/data-source-page-new/install-from-marketplace.tsx b/web/app/components/header/account-setting/data-source-page-new/install-from-marketplace.tsxindex 956352d6d30..f02e276f550 100644--- a/web/app/components/header/account-setting/data-source-page-new/install-from-marketplace.tsx+++ b/web/app/components/header/account-setting/data-source-page-new/install-from-marketplace.tsx@@ -15,7 +15,6 @@ import Divider from '@/app/components/base/divider'import Loading from '@/app/components/base/loading'import List from '@/app/components/plugins/marketplace/list'import ProviderCard from '@/app/components/plugins/provider-card'-import { getLocaleOnClient } from '@/i18n-config'import { cn } from '@/utils/classnames'import { getMarketplaceUrl } from '@/utils/var'import {@@ -33,7 +32,6 @@ const InstallFromMarketplace = ({const { t } = useTranslation()const { theme } = useTheme()const [collapse, setCollapse] = useState(false)- const locale = getLocaleOnClient()const {plugins: allPlugins,isLoading: isAllPluginsLoading,@@ -70,7 +68,6 @@ const InstallFromMarketplace = ({marketplaceCollectionPluginsMap={{}}plugins={allPlugins}showInstallButton- locale={locale}cardContainerClassName="grid grid-cols-2 gap-2"cardRender={cardRender}emptyClassName="h-auto"diff --git a/web/app/components/header/account-setting/language-page/index.tsx b/web/app/components/header/account-setting/language-page/index.tsxindex 5d888281e9b..2a0604421fb 100644--- a/web/app/components/header/account-setting/language-page/index.tsx+++ b/web/app/components/header/account-setting/language-page/index.tsx@@ -2,13 +2,13 @@import type { Item } from '@/app/components/base/select'import type { Locale } from '@/i18n-config'+import { useRouter } from 'next/navigation'import { useState } from 'react'import { useTranslation } from 'react-i18next'import { useContext } from 'use-context-selector'import { SimpleSelect } from '@/app/components/base/select'import { ToastContext } from '@/app/components/base/toast'import { useAppContext } from '@/context/app-context'-import { useLocale } from '@/context/i18n'import { setLocaleOnClient } from '@/i18n-config'import { languages } from '@/i18n-config/language'@@ -25,6 +25,7 @@ export default function LanguagePage() {const { notify } = useContext(ToastContext)const [editing, setEditing] = useState(false)const { t } = useTranslation()+ const router = useRouter()const handleSelectLanguage = async (item: Item) => {const url = '/account/interface-language'@@ -35,7 +36,8 @@ export default function LanguagePage() {await updateUserProfile({ url, body: { [bodyKey]: item.value } })notify({ type: 'success', message: t('actionMsg.modifiedSuccessfully', { ns: 'common' }) })- setLocaleOnClient(item.value.toString() as Locale)+ setLocaleOnClient(item.value.toString() as Locale, false)+ router.refresh()}catch (e) {notify({ type: 'error', message: (e as Error).message })diff --git a/web/app/components/header/account-setting/model-provider-page/install-from-marketplace.tsx b/web/app/components/header/account-setting/model-provider-page/install-from-marketplace.tsxindex 0e7506bf966..289146f2d2a 100644--- a/web/app/components/header/account-setting/model-provider-page/install-from-marketplace.tsx+++ b/web/app/components/header/account-setting/model-provider-page/install-from-marketplace.tsx@@ -14,7 +14,6 @@ import Divider from '@/app/components/base/divider'import Loading from '@/app/components/base/loading'import List from '@/app/components/plugins/marketplace/list'import ProviderCard from '@/app/components/plugins/provider-card'-import { getLocaleOnClient } from '@/i18n-config'import { cn } from '@/utils/classnames'import { getMarketplaceUrl } from '@/utils/var'import {@@ -32,7 +31,6 @@ const InstallFromMarketplace = ({const { t } = useTranslation()const { theme } = useTheme()const [collapse, setCollapse] = useState(false)- const locale = getLocaleOnClient()const {plugins: allPlugins,isLoading: isAllPluginsLoading,@@ -69,7 +67,6 @@ const InstallFromMarketplace = ({marketplaceCollectionPluginsMap={{}}plugins={allPlugins}showInstallButton- locale={locale}cardContainerClassName="grid grid-cols-2 gap-2"cardRender={cardRender}emptyClassName="h-auto"diff --git a/web/app/components/i18n-server.tsx b/web/app/components/i18n-server.tsxdeleted file mode 100644index 01dc5f0f131..00000000000--- a/web/app/components/i18n-server.tsx+++ /dev/null@@ -1,22 +0,0 @@-import * as React from 'react'-import { getLocaleOnServer } from '@/i18n-config/server'-import { ToastProvider } from './base/toast'-import I18N from './i18n'--export type II18NServerProps = {- children: React.ReactNode-}--const I18NServer = async ({- children,-}: II18NServerProps) => {- const locale = await getLocaleOnServer()-- return (- <I18N {...{ locale }}>- <ToastProvider>{children}</ToastProvider>- </I18N>- )-}--export default I18NServerdiff --git a/web/app/components/i18n.tsx b/web/app/components/i18n.tsxdeleted file mode 100644index e9af2face9c..00000000000--- a/web/app/components/i18n.tsx+++ /dev/null@@ -1,45 +0,0 @@-'use client'--import type { FC } from 'react'-import type { Locale } from '@/i18n-config'-import { usePrefetchQuery } from '@tanstack/react-query'-import { useHydrateAtoms } from 'jotai/utils'-import * as React from 'react'-import { useEffect, useState } from 'react'-import { localeAtom } from '@/context/i18n'-import { setLocaleOnClient } from '@/i18n-config'-import { getSystemFeatures } from '@/service/common'-import Loading from './base/loading'--export type II18nProps = {- locale: Locale- children: React.ReactNode-}-const I18n: FC<II18nProps> = ({- locale,- children,-}) => {- useHydrateAtoms([[localeAtom, locale]])- const [loading, setLoading] = useState(true)-- usePrefetchQuery({- queryKey: ['systemFeatures'],- queryFn: getSystemFeatures,- })-- useEffect(() => {- setLocaleOnClient(locale, false).then(() => {- setLoading(false)- })- }, [locale])-- if (loading)- return <div className="flex h-screen w-screen items-center justify-center"><Loading type="app" /></div>-- return (- <>- {children}- </>- )-}-export default React.memo(I18n)diff --git a/web/app/components/plugins/base/deprecation-notice.tsx b/web/app/components/plugins/base/deprecation-notice.tsxindex c2ddfa69757..513b27a2cf4 100644--- a/web/app/components/plugins/base/deprecation-notice.tsx+++ b/web/app/components/plugins/base/deprecation-notice.tsx@@ -1,4 +1,5 @@import type { FC } from 'react'+import { useTranslation } from '#i18n'import { RiAlertFill } from '@remixicon/react'import { camelCase } from 'es-toolkit/string'import Link from 'next/link'@@ -6,14 +7,12 @@ import * as React from 'react'import { useMemo } from 'react'import { Trans } from 'react-i18next'import { cn } from '@/utils/classnames'-import { useMixedTranslation } from '../marketplace/hooks'type DeprecationNoticeProps = {status: 'deleted' | 'active'deprecatedReason: stringalternativePluginId: stringalternativePluginURL: string- locale?: stringclassName?: stringinnerWrapperClassName?: stringiconWrapperClassName?: string@@ -34,13 +33,12 @@ const DeprecationNotice: FC<DeprecationNoticeProps> = ({deprecatedReason,alternativePluginId,alternativePluginURL,- locale,className,innerWrapperClassName,iconWrapperClassName,textClassName,}) => {- const { t } = useMixedTranslation(locale)+ const { t } = useTranslation()const deprecatedReasonKey = useMemo(() => {if (!deprecatedReason)diff --git a/web/app/components/plugins/card/index.spec.tsx b/web/app/components/plugins/card/index.spec.tsxindex 4a3e5a587bb..fd97534ec4b 100644--- a/web/app/components/plugins/card/index.spec.tsx+++ b/web/app/components/plugins/card/index.spec.tsx@@ -502,31 +502,6 @@ describe('Card', () => {})})- // ================================- // Locale Tests- // ================================- describe('Locale', () => {- it('should use locale from props when provided', () => {- const plugin = createMockPlugin({- label: { 'en-US': 'English Title', 'zh-Hans': '中文标题' },- })-- render(<Card payload={plugin} locale="zh-Hans" />)-- expect(screen.getByText('中文标题')).toBeInTheDocument()- })-- it('should fallback to default locale when prop locale not found', () => {- const plugin = createMockPlugin({- label: { 'en-US': 'English Title' },- })-- render(<Card payload={plugin} locale="fr-FR" />)-- expect(screen.getByText('English Title')).toBeInTheDocument()- })- })-// ================================// Memoization Tests// ================================diff --git a/web/app/components/plugins/card/index.tsx b/web/app/components/plugins/card/index.tsxindex ada26801de8..85784211167 100644--- a/web/app/components/plugins/card/index.tsx+++ b/web/app/components/plugins/card/index.tsx@@ -1,15 +1,13 @@'use client'import type { Plugin } from '../types'-import type { Locale } from '@/i18n-config'+import { useTranslation } from '#i18n'import { RiAlertFill } from '@remixicon/react'import * as React from 'react'-import { useMixedTranslation } from '@/app/components/plugins/marketplace/hooks'import { useGetLanguage } from '@/context/i18n'import useTheme from '@/hooks/use-theme'import {renderI18nObject,} from '@/i18n-config'-import { getLanguage } from '@/i18n-config/language'import { Theme } from '@/types/app'import { cn } from '@/utils/classnames'import Partner from '../base/badges/partner'@@ -33,7 +31,6 @@ export type Props = {footer?: React.ReactNodeisLoading?: booleanloadingFileName?: string- locale?: LocalelimitedInstall?: boolean}@@ -48,13 +45,11 @@ const Card = ({footer,isLoading = false,loadingFileName,- locale: localeFromProps,limitedInstall = false,}: Props) => {- const defaultLocale = useGetLanguage()- const locale = localeFromProps ? getLanguage(localeFromProps) : defaultLocale- const { t } = useMixedTranslation(localeFromProps)- const { categoriesMap } = useCategories(t, true)+ const locale = useGetLanguage()+ const { t } = useTranslation()+ const { categoriesMap } = useCategories(true)const { category, type, name, org, label, brief, icon, icon_dark, verified, badges = [] } = payloadconst { theme } = useTheme()const iconSrc = theme === Theme.dark && icon_dark ? icon_dark : icondiff --git a/web/app/components/plugins/hooks.ts b/web/app/components/plugins/hooks.tsindex 262935205b1..65d073cc2f2 100644--- a/web/app/components/plugins/hooks.ts+++ b/web/app/components/plugins/hooks.ts@@ -1,4 +1,3 @@-import type { TFunction } from 'i18next'import type { CategoryKey, TagKey } from './constants'import { useMemo } from 'react'import { useTranslation } from 'react-i18next'@@ -13,9 +12,8 @@ export type Tag = {label: string}-export const useTags = (translateFromOut?: TFunction) => {- const { t: translation } = useTranslation()- const t = translateFromOut || translation+export const useTags = () => {+ const { t } = useTranslation()const tags = useMemo(() => {return tagKeys.map((tag) => {@@ -53,9 +51,8 @@ type Category = {label: string}-export const useCategories = (translateFromOut?: TFunction, isSingle?: boolean) => {- const { t: translation } = useTranslation()- const t = translateFromOut || translation+export const useCategories = (isSingle?: boolean) => {+ const { t } = useTranslation()const categories = useMemo(() => {return categoryKeys.map((category) => {diff --git a/web/app/components/plugins/marketplace/empty/index.spec.tsx b/web/app/components/plugins/marketplace/empty/index.spec.tsxindex 4cbc85a3090..bc8e701dfcc 100644--- a/web/app/components/plugins/marketplace/empty/index.spec.tsx+++ b/web/app/components/plugins/marketplace/empty/index.spec.tsx@@ -7,9 +7,9 @@ import Line from './line'// Mock external dependencies only// ================================-// Mock useMixedTranslation hook-vi.mock('../hooks', () => ({- useMixedTranslation: (_locale?: string) => ({+// Mock i18n translation hook+vi.mock('#i18n', () => ({+ useTranslation: () => ({t: (key: string, options?: { ns?: string }) => {// Build full key with namespace prefix if providedconst fullKey = options?.ns ? `${options.ns}.${key}` : key@@ -471,36 +471,6 @@ describe('Empty', () => {})})- // ================================- // Locale Prop Tests- // ================================- describe('Locale Prop', () => {- it('should pass locale to useMixedTranslation', () => {- render(<Empty locale="zh-CN" />)-- // Translation should still work- expect(screen.getByText('No plugin found')).toBeInTheDocument()- })-- it('should handle undefined locale', () => {- render(<Empty locale={undefined} />)-- expect(screen.getByText('No plugin found')).toBeInTheDocument()- })-- it('should handle en-US locale', () => {- render(<Empty locale="en-US" />)-- expect(screen.getByText('No plugin found')).toBeInTheDocument()- })-- it('should handle ja-JP locale', () => {- render(<Empty locale="ja-JP" />)-- expect(screen.getByText('No plugin found')).toBeInTheDocument()- })- })-// ================================// Placeholder Cards Layout Tests// ================================@@ -634,7 +604,6 @@ describe('Empty', () => {text="Custom message"lightCardclassName="custom-wrapper"- locale="en-US"/>,)@@ -695,12 +664,6 @@ describe('Empty', () => {expect(container.querySelector('.only-class')).toBeInTheDocument()})- it('should render with only locale prop', () => {- render(<Empty locale="zh-CN" />)-- expect(screen.getByText('No plugin found')).toBeInTheDocument()- })-it('should handle text with unicode characters', () => {render(<Empty text="没有找到插件 🔍" />)@@ -813,7 +776,7 @@ describe('Empty and Line Integration', () => {})it('should render complete Empty component structure', () => {- const { container } = render(<Empty text="Test" lightCard className="test" locale="en-US" />)+ const { container } = render(<Empty text="Test" lightCard className="test" />)// Containerexpect(container.querySelector('.test')).toBeInTheDocument()diff --git a/web/app/components/plugins/marketplace/empty/index.tsx b/web/app/components/plugins/marketplace/empty/index.tsxindex 3c33d9b92aa..6e5adff1b44 100644--- a/web/app/components/plugins/marketplace/empty/index.tsx+++ b/web/app/components/plugins/marketplace/empty/index.tsx@@ -1,6 +1,6 @@'use client'+import { useTranslation } from '#i18n'import { Group } from '@/app/components/base/icons/src/vender/other'-import { useMixedTranslation } from '@/app/components/plugins/marketplace/hooks'import { cn } from '@/utils/classnames'import Line from './line'@@ -8,16 +8,14 @@ type Props = {text?: stringlightCard?: booleanclassName?: string- locale?: string}const Empty = ({text,lightCard,className,- locale,}: Props) => {- const { t } = useMixedTranslation(locale)+ const { t } = useTranslation()return (<divdiff --git a/web/app/components/plugins/marketplace/hooks.ts b/web/app/components/plugins/marketplace/hooks.tsindex 5dc03be2b77..11558e8c96f 100644--- a/web/app/components/plugins/marketplace/hooks.ts+++ b/web/app/components/plugins/marketplace/hooks.ts@@ -18,8 +18,6 @@ import {useEffect,useState,} from 'react'-import { useTranslation } from 'react-i18next'-import i18n from '@/i18n-config/i18next-config'import { postMarketplace } from '@/service/base'import { SCROLL_BOTTOM_THRESHOLD } from './constants'import {@@ -218,21 +216,6 @@ export const useMarketplacePlugins = () => {}}-/**- * ! Support zh-Hans, pt-BR, ja-JP and en-US for Marketplace page- * ! For other languages, use en-US as fallback- */-export const useMixedTranslation = (localeFromOuter?: string) => {- let t = useTranslation().t-- if (localeFromOuter)- t = i18n.getFixedT(localeFromOuter)-- return {- t,- }-}-export const useMarketplaceContainerScroll = (callback: () => void,scrollContainerId = 'marketplace-container',diff --git a/web/app/components/plugins/marketplace/index.spec.tsx b/web/app/components/plugins/marketplace/index.spec.tsxindex 3073897ba1e..b3b1d58dd48 100644--- a/web/app/components/plugins/marketplace/index.spec.tsx+++ b/web/app/components/plugins/marketplace/index.spec.tsx@@ -11,7 +11,6 @@ import { PluginCategoryEnum } from '@/app/components/plugins/types'// Note: Import after mocks are set upimport { DEFAULT_SORT, SCROLL_BOTTOM_THRESHOLD } from './constants'import { MarketplaceContext, MarketplaceContextProvider, useMarketplaceContext } from './context'-import { useMixedTranslation } from './hooks'import PluginTypeSwitch, { PLUGIN_TYPE_SEARCH_MAP } from './plugin-type-switch'import StickySearchAndSwitchWrapper from './sticky-search-and-switch-wrapper'import {@@ -602,48 +601,6 @@ describe('utils', () => {})})-// ================================-// Hooks Tests-// ================================-describe('hooks', () => {- describe('useMixedTranslation', () => {- it('should return translation function', () => {- const { result } = renderHook(() => useMixedTranslation())-- expect(result.current.t).toBeDefined()- expect(typeof result.current.t).toBe('function')- })-- it('should return translation key when no translation found', () => {- const { result } = renderHook(() => useMixedTranslation())-- // The global mock returns key with namespace prefix- expect(result.current.t('category.all', { ns: 'plugin' })).toBe('plugin.category.all')- })-- it('should use locale from outer when provided', () => {- const { result } = renderHook(() => useMixedTranslation('zh-Hans'))-- expect(result.current.t).toBeDefined()- })-- it('should handle different locale values', () => {- const locales = ['en-US', 'zh-Hans', 'ja-JP', 'pt-BR']- locales.forEach((locale) => {- const { result } = renderHook(() => useMixedTranslation(locale))- expect(result.current.t).toBeDefined()- expect(typeof result.current.t).toBe('function')- })- })-- it('should use getFixedT when localeFromOuter is provided', () => {- const { result } = renderHook(() => useMixedTranslation('fr-FR'))- // The global mock returns key with namespace prefix- expect(result.current.t('search', { ns: 'plugin' })).toBe('plugin.search')- })- })-})-// ================================// useMarketplaceCollectionsAndPlugins Tests// ================================@@ -2088,17 +2045,6 @@ describe('StickySearchAndSwitchWrapper', () => {})describe('Props', () => {- it('should accept locale prop', () => {- render(- <MarketplaceContextProvider>- <StickySearchAndSwitchWrapper locale="zh-Hans" />- </MarketplaceContextProvider>,- )-- // Component should render without errors- expect(screen.getByTestId('portal-elem')).toBeInTheDocument()- })-it('should accept showSearchParams prop', () => {render(<MarketplaceContextProvider>diff --git a/web/app/components/plugins/marketplace/index.tsx b/web/app/components/plugins/marketplace/index.tsxindex f9f7e86b9a9..08d1bc833fa 100644--- a/web/app/components/plugins/marketplace/index.tsx+++ b/web/app/components/plugins/marketplace/index.tsx@@ -1,6 +1,5 @@import type { MarketplaceCollection, SearchParams } from './types'import type { Plugin } from '@/app/components/plugins/types'-import type { Locale } from '@/i18n-config'import { TanstackQueryInitializer } from '@/context/query-client'import { MarketplaceContextProvider } from './context'import Description from './description'@@ -9,7 +8,6 @@ import StickySearchAndSwitchWrapper from './sticky-search-and-switch-wrapper'import { getMarketplaceCollectionsAndPlugins } from './utils'type MarketplaceProps = {- locale: LocaleshowInstallButton?: booleanshouldExclude?: booleansearchParams?: SearchParams@@ -18,7 +16,6 @@ type MarketplaceProps = {showSearchParams?: boolean}const Marketplace = async ({- locale,showInstallButton = true,shouldExclude,searchParams,@@ -44,12 +41,10 @@ const Marketplace = async ({><Description /><StickySearchAndSwitchWrapper- locale={locale}pluginTypeSwitchClassName={pluginTypeSwitchClassName}showSearchParams={showSearchParams}/><ListWrapper- locale={locale}marketplaceCollections={marketplaceCollections}marketplaceCollectionPluginsMap={marketplaceCollectionPluginsMap}showInstallButton={showInstallButton}diff --git a/web/app/components/plugins/marketplace/list/card-wrapper.tsx b/web/app/components/plugins/marketplace/list/card-wrapper.tsxindex 6c1d2e16562..42a5fec5c57 100644--- a/web/app/components/plugins/marketplace/list/card-wrapper.tsx+++ b/web/app/components/plugins/marketplace/list/card-wrapper.tsx@@ -1,6 +1,6 @@'use client'import type { Plugin } from '@/app/components/plugins/types'-import type { Locale } from '@/i18n-config'+import { useLocale, useTranslation } from '#i18n'import { RiArrowRightUpLine } from '@remixicon/react'import { useBoolean } from 'ahooks'import { useTheme } from 'next-themes'@@ -11,34 +11,30 @@ import Card from '@/app/components/plugins/card'import CardMoreInfo from '@/app/components/plugins/card/card-more-info'import { useTags } from '@/app/components/plugins/hooks'import InstallFromMarketplace from '@/app/components/plugins/install-plugin/install-from-marketplace'-import { useMixedTranslation } from '@/app/components/plugins/marketplace/hooks'-import { useLocale } from '@/context/i18n'import { getPluginDetailLinkInMarketplace, getPluginLinkInMarketplace } from '../utils'type CardWrapperProps = {plugin: PluginshowInstallButton?: boolean- locale?: Locale}const CardWrapperComponent = ({plugin,showInstallButton,- locale,}: CardWrapperProps) => {- const { t } = useMixedTranslation(locale)+ const { t } = useTranslation()const { theme } = useTheme()const [isShowInstallFromMarketplace, {setTrue: showInstallFromMarketplace,setFalse: hideInstallFromMarketplace,}] = useBoolean(false)- const localeFromLocale = useLocale()- const { getTagLabel } = useTags(t)+ const locale = useLocale()+ const { getTagLabel } = useTags()// Memoize marketplace link params to prevent unnecessary re-rendersconst marketplaceLinkParams = useMemo(() => ({- language: localeFromLocale,+ language: locale,theme,- }), [localeFromLocale, theme])+ }), [locale, theme])// Memoize tag labels to prevent recreating array on every renderconst tagLabels = useMemo(() =>@@ -52,7 +48,6 @@ const CardWrapperComponent = ({<Cardkey={plugin.name}payload={plugin}- locale={locale}footer={(<CardMoreInfodownloadCount={plugin.install_count}@@ -99,7 +94,6 @@ const CardWrapperComponent = ({<Cardkey={plugin.name}payload={plugin}- locale={locale}footer={(<CardMoreInfodownloadCount={plugin.install_count}diff --git a/web/app/components/plugins/marketplace/list/index.spec.tsx b/web/app/components/plugins/marketplace/list/index.spec.tsxindex 029cc7ecbc8..c8fc6309a4b 100644--- a/web/app/components/plugins/marketplace/list/index.spec.tsx+++ b/web/app/components/plugins/marketplace/list/index.spec.tsx@@ -1,6 +1,5 @@import type { MarketplaceCollection, SearchParamsFromCollection } from '../types'import type { Plugin } from '@/app/components/plugins/types'-import type { Locale } from '@/i18n-config'import { fireEvent, render, screen, waitFor } from '@testing-library/react'import { beforeEach, describe, expect, it, vi } from 'vitest'import { PluginCategoryEnum } from '@/app/components/plugins/types'@@ -12,9 +11,9 @@ import ListWrapper from './list-wrapper'// Mock External Dependencies Only// ================================-// Mock useMixedTranslation hook-vi.mock('../hooks', () => ({- useMixedTranslation: (_locale?: string) => ({+// Mock i18n translation hook+vi.mock('#i18n', () => ({+ useTranslation: () => ({t: (key: string, options?: { ns?: string, num?: number }) => {// Build full key with namespace prefix if providedconst fullKey = options?.ns ? `${options.ns}.${key}` : key@@ -28,6 +27,7 @@ vi.mock('../hooks', () => ({return translations[fullKey] || key},}),+ useLocale: () => 'en-US',}))// Mock useMarketplaceContext with controllable values@@ -148,15 +148,15 @@ vi.mock('@/app/components/plugins/install-plugin/install-from-marketplace', () =// Mock SortDropdown componentvi.mock('../sort-dropdown', () => ({- default: ({ locale }: { locale: Locale }) => (- <div data-testid="sort-dropdown" data-locale={locale}>Sort</div>+ default: () => (+ <div data-testid="sort-dropdown">Sort</div>),}))// Mock Empty componentvi.mock('../empty', () => ({- default: ({ className, locale }: { className?: string, locale?: string }) => (- <div data-testid="empty-component" className={className} data-locale={locale}>+ default: ({ className }: { className?: string }) => (+ <div data-testid="empty-component" className={className}>No plugins found</div>),@@ -233,7 +233,6 @@ describe('List', () => {marketplaceCollectionPluginsMap: {} as Record<string, Plugin[]>,plugins: undefined,showInstallButton: false,- locale: 'en-US' as Locale,cardContainerClassName: '',cardRender: undefined,onMoreClick: undefined,@@ -351,18 +350,6 @@ describe('List', () => {expect(screen.getByTestId('empty-component')).toHaveClass('custom-empty-class')})- it('should pass locale to Empty component', () => {- render(- <List- {...defaultProps}- plugins={[]}- locale={'zh-CN' as Locale}- />,- )-- expect(screen.getByTestId('empty-component')).toHaveAttribute('data-locale', 'zh-CN')- })-it('should pass showInstallButton to CardWrapper', () => {const plugins = createMockPluginList(1)@@ -508,7 +495,6 @@ describe('ListWithCollection', () => {marketplaceCollections: [] as MarketplaceCollection[],marketplaceCollectionPluginsMap: {} as Record<string, Plugin[]>,showInstallButton: false,- locale: 'en-US' as Locale,cardContainerClassName: '',cardRender: undefined,onMoreClick: undefined,@@ -820,7 +806,6 @@ describe('ListWrapper', () => {marketplaceCollections: [] as MarketplaceCollection[],marketplaceCollectionPluginsMap: {} as Record<string, Plugin[]>,showInstallButton: false,- locale: 'en-US' as Locale,}beforeEach(() => {@@ -901,14 +886,6 @@ describe('ListWrapper', () => {expect(screen.queryByTestId('sort-dropdown')).not.toBeInTheDocument()})-- it('should pass locale to SortDropdown', () => {- mockContextValues.plugins = createMockPluginList(1)-- render(<ListWrapper {...defaultProps} locale={'zh-CN' as Locale} />)-- expect(screen.getByTestId('sort-dropdown')).toHaveAttribute('data-locale', 'zh-CN')- })})// ================================@@ -1169,7 +1146,6 @@ describe('CardWrapper (via List integration)', () => {marketplaceCollections={[]}marketplaceCollectionPluginsMap={{}}plugins={[plugin]}- locale="en-US"/>,)@@ -1188,7 +1164,6 @@ describe('CardWrapper (via List integration)', () => {marketplaceCollections={[]}marketplaceCollectionPluginsMap={{}}plugins={[plugin]}- locale="en-US"/>,)@@ -1209,7 +1184,6 @@ describe('CardWrapper (via List integration)', () => {marketplaceCollections={[]}marketplaceCollectionPluginsMap={{}}plugins={plugins}- locale="en-US"/>,)@@ -1231,7 +1205,6 @@ describe('CardWrapper (via List integration)', () => {marketplaceCollectionPluginsMap={{}}plugins={[plugin]}showInstallButton={true}- locale="en-US"/>,)@@ -1252,7 +1225,6 @@ describe('CardWrapper (via List integration)', () => {marketplaceCollectionPluginsMap={{}}plugins={[plugin]}showInstallButton={true}- locale="en-US"/>,)@@ -1274,7 +1246,6 @@ describe('CardWrapper (via List integration)', () => {marketplaceCollectionPluginsMap={{}}plugins={[plugin]}showInstallButton={true}- locale="en-US"/>,)@@ -1293,7 +1264,6 @@ describe('CardWrapper (via List integration)', () => {marketplaceCollectionPluginsMap={{}}plugins={[plugin]}showInstallButton={true}- locale="en-US"/>,)@@ -1310,7 +1280,6 @@ describe('CardWrapper (via List integration)', () => {marketplaceCollectionPluginsMap={{}}plugins={[plugin]}showInstallButton={true}- locale="en-US"/>,)@@ -1327,7 +1296,6 @@ describe('CardWrapper (via List integration)', () => {marketplaceCollectionPluginsMap={{}}plugins={[plugin]}showInstallButton={true}- locale="en-US"/>,)@@ -1354,7 +1322,6 @@ describe('CardWrapper (via List integration)', () => {marketplaceCollectionPluginsMap={{}}plugins={[plugin]}showInstallButton={false}- locale="en-US"/>,)@@ -1375,7 +1342,6 @@ describe('CardWrapper (via List integration)', () => {marketplaceCollectionPluginsMap={{}}plugins={[plugin]}showInstallButton={false}- locale="en-US"/>,)@@ -1390,7 +1356,6 @@ describe('CardWrapper (via List integration)', () => {marketplaceCollections={[]}marketplaceCollectionPluginsMap={{}}plugins={[plugin]}- locale="en-US"/>,)@@ -1414,7 +1379,6 @@ describe('CardWrapper (via List integration)', () => {marketplaceCollections={[]}marketplaceCollectionPluginsMap={{}}plugins={[plugin]}- locale="en-US"/>,)@@ -1432,7 +1396,6 @@ describe('CardWrapper (via List integration)', () => {marketplaceCollections={[]}marketplaceCollectionPluginsMap={{}}plugins={[plugin]}- locale="en-US"/>,)@@ -1450,7 +1413,6 @@ describe('CardWrapper (via List integration)', () => {marketplaceCollections={[]}marketplaceCollectionPluginsMap={{}}plugins={[plugin]}- locale="en-US"/>,)@@ -1482,7 +1444,6 @@ describe('Combined Workflows', () => {<ListWrappermarketplaceCollections={[]}marketplaceCollectionPluginsMap={{}}- locale="en-US"/>,)@@ -1501,7 +1462,6 @@ describe('Combined Workflows', () => {<ListWrappermarketplaceCollections={[]}marketplaceCollectionPluginsMap={{}}- locale="en-US"/>,)@@ -1521,7 +1481,6 @@ describe('Combined Workflows', () => {<ListWrappermarketplaceCollections={[]}marketplaceCollectionPluginsMap={{}}- locale="en-US"/>,)@@ -1535,7 +1494,6 @@ describe('Combined Workflows', () => {<ListWrappermarketplaceCollections={[]}marketplaceCollectionPluginsMap={{}}- locale="en-US"/>,)@@ -1551,7 +1509,6 @@ describe('Combined Workflows', () => {<ListWrappermarketplaceCollections={[]}marketplaceCollectionPluginsMap={{}}- locale="en-US"/>,)@@ -1569,7 +1526,6 @@ describe('Combined Workflows', () => {<ListWrappermarketplaceCollections={[]}marketplaceCollectionPluginsMap={{}}- locale="en-US"/>,)@@ -1601,7 +1557,6 @@ describe('Accessibility', () => {<ListWithCollectionmarketplaceCollections={collections}marketplaceCollectionPluginsMap={pluginsMap}- locale="en-US"/>,)@@ -1625,7 +1580,6 @@ describe('Accessibility', () => {marketplaceCollections={collections}marketplaceCollectionPluginsMap={pluginsMap}onMoreClick={onMoreClick}- locale="en-US"/>,)@@ -1642,7 +1596,6 @@ describe('Accessibility', () => {marketplaceCollections={[]}marketplaceCollectionPluginsMap={{}}plugins={plugins}- locale="en-US"/>,)@@ -1668,7 +1621,6 @@ describe('Performance', () => {marketplaceCollections={[]}marketplaceCollectionPluginsMap={{}}plugins={plugins}- locale="en-US"/>,)const endTime = performance.now()@@ -1689,7 +1641,6 @@ describe('Performance', () => {<ListWithCollectionmarketplaceCollections={collections}marketplaceCollectionPluginsMap={pluginsMap}- locale="en-US"/>,)const endTime = performance.now()diff --git a/web/app/components/plugins/marketplace/list/index.tsx b/web/app/components/plugins/marketplace/list/index.tsxindex 54889b232ff..80b33d0ffd0 100644--- a/web/app/components/plugins/marketplace/list/index.tsx+++ b/web/app/components/plugins/marketplace/list/index.tsx@@ -1,7 +1,6 @@'use client'import type { Plugin } from '../../types'import type { MarketplaceCollection } from '../types'-import type { Locale } from '@/i18n-config'import { cn } from '@/utils/classnames'import Empty from '../empty'import CardWrapper from './card-wrapper'@@ -12,7 +11,6 @@ type ListProps = {marketplaceCollectionPluginsMap: Record<string, Plugin[]>plugins?: Plugin[]showInstallButton?: boolean- locale: LocalecardContainerClassName?: stringcardRender?: (plugin: Plugin) => React.JSX.Element | nullonMoreClick?: () => void@@ -23,7 +21,6 @@ const List = ({marketplaceCollectionPluginsMap,plugins,showInstallButton,- locale,cardContainerClassName,cardRender,onMoreClick,@@ -37,7 +34,6 @@ const List = ({marketplaceCollections={marketplaceCollections}marketplaceCollectionPluginsMap={marketplaceCollectionPluginsMap}showInstallButton={showInstallButton}- locale={locale}cardContainerClassName={cardContainerClassName}cardRender={cardRender}onMoreClick={onMoreClick}@@ -61,7 +57,6 @@ const List = ({key={`${plugin.org}/${plugin.name}`}plugin={plugin}showInstallButton={showInstallButton}- locale={locale}/>)})@@ -71,7 +66,7 @@ const List = ({}{plugins && !plugins.length && (- <Empty className={emptyClassName} locale={locale} />+ <Empty className={emptyClassName} />)}</>diff --git a/web/app/components/plugins/marketplace/list/list-with-collection.tsx b/web/app/components/plugins/marketplace/list/list-with-collection.tsxindex 8830cc5ddf9..c17715e71e1 100644--- a/web/app/components/plugins/marketplace/list/list-with-collection.tsx+++ b/web/app/components/plugins/marketplace/list/list-with-collection.tsx@@ -3,9 +3,8 @@import type { MarketplaceCollection } from '../types'import type { SearchParamsFromCollection } from '@/app/components/plugins/marketplace/types'import type { Plugin } from '@/app/components/plugins/types'-import type { Locale } from '@/i18n-config'+import { useLocale, useTranslation } from '#i18n'import { RiArrowRightSLine } from '@remixicon/react'-import { useMixedTranslation } from '@/app/components/plugins/marketplace/hooks'import { getLanguage } from '@/i18n-config/language'import { cn } from '@/utils/classnames'import CardWrapper from './card-wrapper'@@ -14,7 +13,6 @@ type ListWithCollectionProps = {marketplaceCollections: MarketplaceCollection[]marketplaceCollectionPluginsMap: Record<string, Plugin[]>showInstallButton?: boolean- locale: LocalecardContainerClassName?: stringcardRender?: (plugin: Plugin) => React.JSX.Element | nullonMoreClick?: (searchParams?: SearchParamsFromCollection) => void@@ -23,12 +21,12 @@ const ListWithCollection = ({marketplaceCollections,marketplaceCollectionPluginsMap,showInstallButton,- locale,cardContainerClassName,cardRender,onMoreClick,}: ListWithCollectionProps) => {- const { t } = useMixedTranslation(locale)+ const { t } = useTranslation()+ const locale = useLocale()return (<>@@ -72,7 +70,6 @@ const ListWithCollection = ({key={plugin.plugin_id}plugin={plugin}showInstallButton={showInstallButton}- locale={locale}/>)})diff --git a/web/app/components/plugins/marketplace/list/list-wrapper.tsx b/web/app/components/plugins/marketplace/list/list-wrapper.tsxindex f8126eb34b0..84fcf92dafb 100644--- a/web/app/components/plugins/marketplace/list/list-wrapper.tsx+++ b/web/app/components/plugins/marketplace/list/list-wrapper.tsx@@ -1,10 +1,9 @@'use client'import type { Plugin } from '../../types'import type { MarketplaceCollection } from '../types'-import type { Locale } from '@/i18n-config'+import { useTranslation } from '#i18n'import { useEffect } from 'react'import Loading from '@/app/components/base/loading'-import { useMixedTranslation } from '@/app/components/plugins/marketplace/hooks'import { useMarketplaceContext } from '../context'import SortDropdown from '../sort-dropdown'import List from './index'@@ -13,15 +12,13 @@ type ListWrapperProps = {marketplaceCollections: MarketplaceCollection[]marketplaceCollectionPluginsMap: Record<string, Plugin[]>showInstallButton?: boolean- locale: Locale}const ListWrapper = ({marketplaceCollections,marketplaceCollectionPluginsMap,showInstallButton,- locale,}: ListWrapperProps) => {- const { t } = useMixedTranslation(locale)+ const { t } = useTranslation()const plugins = useMarketplaceContext(v => v.plugins)const pluginsTotal = useMarketplaceContext(v => v.pluginsTotal)const marketplaceCollectionsFromClient = useMarketplaceContext(v => v.marketplaceCollectionsFromClient)@@ -55,7 +52,7 @@ const ListWrapper = ({<div className="mb-4 flex items-center pt-3"><div className="title-xl-semi-bold text-text-primary">{t('marketplace.pluginsResult', { ns: 'plugin', num: pluginsTotal })}</div><div className="mx-3 h-3.5 w-[1px] bg-divider-regular"></div>- <SortDropdown locale={locale} />+ <SortDropdown /></div>)}@@ -73,7 +70,6 @@ const ListWrapper = ({marketplaceCollectionPluginsMap={marketplaceCollectionPluginsMapFromClient || marketplaceCollectionPluginsMap}plugins={plugins}showInstallButton={showInstallButton}- locale={locale}onMoreClick={handleMoreClick}/>)diff --git a/web/app/components/plugins/marketplace/plugin-type-switch.tsx b/web/app/components/plugins/marketplace/plugin-type-switch.tsxindex 2a89e6847e8..b9572413ed8 100644--- a/web/app/components/plugins/marketplace/plugin-type-switch.tsx+++ b/web/app/components/plugins/marketplace/plugin-type-switch.tsx@@ -1,4 +1,5 @@'use client'+import { useTranslation } from '#i18n'import {RiArchive2Line,RiBrain2Line,@@ -12,7 +13,6 @@ import { Trigger as TriggerIcon } from '@/app/components/base/icons/src/vender/pimport { cn } from '@/utils/classnames'import { PluginCategoryEnum } from '../types'import { useMarketplaceContext } from './context'-import { useMixedTranslation } from './hooks'export const PLUGIN_TYPE_SEARCH_MAP = {all: 'all',@@ -25,16 +25,14 @@ export const PLUGIN_TYPE_SEARCH_MAP = {bundle: 'bundle',}type PluginTypeSwitchProps = {- locale?: stringclassName?: stringshowSearchParams?: boolean}const PluginTypeSwitch = ({- locale,className,showSearchParams,}: PluginTypeSwitchProps) => {- const { t } = useMixedTranslation(locale)+ const { t } = useTranslation()const activePluginType = useMarketplaceContext(s => s.activePluginType)const handleActivePluginTypeChange = useMarketplaceContext(s => s.handleActivePluginTypeChange)diff --git a/web/app/components/plugins/marketplace/search-box/index.spec.tsx b/web/app/components/plugins/marketplace/search-box/index.spec.tsxindex 8c3131f6d1b..3e9cc40be05 100644--- a/web/app/components/plugins/marketplace/search-box/index.spec.tsx+++ b/web/app/components/plugins/marketplace/search-box/index.spec.tsx@@ -10,9 +10,9 @@ import ToolSelectorTrigger from './trigger/tool-selector'// Mock external dependencies only// ================================-// Mock useMixedTranslation hook-vi.mock('../hooks', () => ({- useMixedTranslation: (_locale?: string) => ({+// Mock i18n translation hook+vi.mock('#i18n', () => ({+ useTranslation: () => ({t: (key: string, options?: { ns?: string }) => {// Build full key with namespace prefix if providedconst fullKey = options?.ns ? `${options.ns}.${key}` : key@@ -364,13 +364,6 @@ describe('SearchBox', () => {expect(container.querySelector('.custom-input-class')).toBeInTheDocument()})- it('should pass locale to TagsFilter', () => {- render(<SearchBox {...defaultProps} locale="zh-CN" />)-- // TagsFilter should be rendered with locale- expect(screen.getByTestId('portal-elem')).toBeInTheDocument()- })-it('should handle empty placeholder', () => {render(<SearchBox {...defaultProps} placeholder="" />)@@ -449,12 +442,6 @@ describe('SearchBoxWrapper', () => {expect(screen.getByRole('textbox')).toBeInTheDocument()})- it('should render with locale prop', () => {- render(<SearchBoxWrapper locale="en-US" />)-- expect(screen.getByRole('textbox')).toBeInTheDocument()- })-it('should render in marketplace mode', () => {const { container } = render(<SearchBoxWrapper />)@@ -500,13 +487,6 @@ describe('SearchBoxWrapper', () => {expect(screen.getByPlaceholderText('Search plugins')).toBeInTheDocument()})-- it('should pass locale to useMixedTranslation', () => {- render(<SearchBoxWrapper locale="zh-CN" />)-- // Translation should still work- expect(screen.getByPlaceholderText('Search plugins')).toBeInTheDocument()- })})})@@ -665,12 +645,6 @@ describe('MarketplaceTrigger', () => {})describe('Props Variations', () => {- it('should handle locale prop', () => {- render(<MarketplaceTrigger {...defaultProps} locale="zh-CN" />)-- expect(screen.getByText('All Tags')).toBeInTheDocument()- })-it('should handle empty tagsMap', () => {const { container } = render(<MarketplaceTrigger {...defaultProps} tagsMap={{}} tags={[]} />,@@ -1251,7 +1225,6 @@ describe('Combined Workflows', () => {supportAddCustomToolonShowAddCustomCollectionModal={vi.fn()}placeholder="Search plugins"- locale="en-US"wrapperClassName="custom-wrapper"inputClassName="custom-input"autoFocus={false}diff --git a/web/app/components/plugins/marketplace/search-box/index.tsx b/web/app/components/plugins/marketplace/search-box/index.tsxindex 05f98782b92..b6e1f8ee702 100644--- a/web/app/components/plugins/marketplace/search-box/index.tsx+++ b/web/app/components/plugins/marketplace/search-box/index.tsx@@ -13,7 +13,6 @@ type SearchBoxProps = {tags: string[]onTagsChange: (tags: string[]) => voidplaceholder?: string- locale?: stringsupportAddCustomTool?: booleanusedInMarketplace?: booleanonShowAddCustomCollectionModal?: () => void@@ -28,7 +27,6 @@ const SearchBox = ({tags,onTagsChange,placeholder = '',- locale,usedInMarketplace = false,supportAddCustomTool,onShowAddCustomCollectionModal,@@ -49,7 +47,6 @@ const SearchBox = ({tags={tags}onTagsChange={onTagsChange}usedInMarketplace- locale={locale}/><Divider type="vertical" className="mx-1 h-3.5" /><div className="flex grow items-center gap-x-2 p-1">@@ -109,7 +106,6 @@ const SearchBox = ({<TagsFiltertags={tags}onTagsChange={onTagsChange}- locale={locale}/></>)diff --git a/web/app/components/plugins/marketplace/search-box/search-box-wrapper.tsx b/web/app/components/plugins/marketplace/search-box/search-box-wrapper.tsxindex 1290c26210b..d7fc004236e 100644--- a/web/app/components/plugins/marketplace/search-box/search-box-wrapper.tsx+++ b/web/app/components/plugins/marketplace/search-box/search-box-wrapper.tsx@@ -1,16 +1,11 @@'use client'+import { useTranslation } from '#i18n'import { useMarketplaceContext } from '../context'-import { useMixedTranslation } from '../hooks'import SearchBox from './index'-type SearchBoxWrapperProps = {- locale?: string-}-const SearchBoxWrapper = ({- locale,-}: SearchBoxWrapperProps) => {- const { t } = useMixedTranslation(locale)+const SearchBoxWrapper = () => {+ const { t } = useTranslation()const searchPluginText = useMarketplaceContext(v => v.searchPluginText)const handleSearchPluginTextChange = useMarketplaceContext(v => v.handleSearchPluginTextChange)const filterPluginTags = useMarketplaceContext(v => v.filterPluginTags)@@ -24,7 +19,6 @@ const SearchBoxWrapper = ({onSearchChange={handleSearchPluginTextChange}tags={filterPluginTags}onTagsChange={handleFilterPluginTagsChange}- locale={locale}placeholder={t('searchPlugins', { ns: 'plugin' })}usedInMarketplace/>diff --git a/web/app/components/plugins/marketplace/search-box/tags-filter.tsx b/web/app/components/plugins/marketplace/search-box/tags-filter.tsxindex df4d3eebab7..9a8035e2e30 100644--- a/web/app/components/plugins/marketplace/search-box/tags-filter.tsx+++ b/web/app/components/plugins/marketplace/search-box/tags-filter.tsx@@ -1,5 +1,6 @@'use client'+import { useTranslation } from '#i18n'import { useState } from 'react'import Checkbox from '@/app/components/base/checkbox'import Input from '@/app/components/base/input'@@ -9,7 +10,6 @@ import {PortalToFollowElemTrigger,} from '@/app/components/base/portal-to-follow-elem'import { useTags } from '@/app/components/plugins/hooks'-import { useMixedTranslation } from '@/app/components/plugins/marketplace/hooks'import MarketplaceTrigger from './trigger/marketplace'import ToolSelectorTrigger from './trigger/tool-selector'@@ -17,18 +17,16 @@ type TagsFilterProps = {tags: string[]onTagsChange: (tags: string[]) => voidusedInMarketplace?: boolean- locale?: string}const TagsFilter = ({tags,onTagsChange,usedInMarketplace = false,- locale,}: TagsFilterProps) => {- const { t } = useMixedTranslation(locale)+ const { t } = useTranslation()const [open, setOpen] = useState(false)const [searchText, setSearchText] = useState('')- const { tags: options, tagsMap } = useTags(t)+ const { tags: options, tagsMap } = useTags()const filteredOptions = options.filter(option => option.label.toLowerCase().includes(searchText.toLowerCase()))const handleCheck = (id: string) => {if (tags.includes(id))@@ -59,7 +57,6 @@ const TagsFilter = ({open={open}tags={tags}tagsMap={tagsMap}- locale={locale}onTagsChange={onTagsChange}/>)diff --git a/web/app/components/plugins/marketplace/search-box/trigger/marketplace.tsx b/web/app/components/plugins/marketplace/search-box/trigger/marketplace.tsxindex 2ba03bd2f23..e387d52d0ee 100644--- a/web/app/components/plugins/marketplace/search-box/trigger/marketplace.tsx+++ b/web/app/components/plugins/marketplace/search-box/trigger/marketplace.tsx@@ -1,15 +1,14 @@import type { Tag } from '../../../hooks'+import { useTranslation } from '#i18n'import { RiArrowDownSLine, RiCloseCircleFill, RiFilter3Line } from '@remixicon/react'import * as React from 'react'import { cn } from '@/utils/classnames'-import { useMixedTranslation } from '../../hooks'type MarketplaceTriggerProps = {selectedTagsLength: numberopen: booleantags: string[]tagsMap: Record<string, Tag>- locale?: stringonTagsChange: (tags: string[]) => void}@@ -18,10 +17,9 @@ const MarketplaceTrigger = ({open,tags,tagsMap,- locale,onTagsChange,}: MarketplaceTriggerProps) => {- const { t } = useMixedTranslation(locale)+ const { t } = useTranslation()return (<divdiff --git a/web/app/components/plugins/marketplace/sort-dropdown/index.spec.tsx b/web/app/components/plugins/marketplace/sort-dropdown/index.spec.tsxindex d42d4fbbf34..3ed7d78b07c 100644--- a/web/app/components/plugins/marketplace/sort-dropdown/index.spec.tsx+++ b/web/app/components/plugins/marketplace/sort-dropdown/index.spec.tsx@@ -8,7 +8,7 @@ import SortDropdown from './index'// Mock external dependencies only// ================================-// Mock useMixedTranslation hook+// Mock i18n translation hookconst mockTranslation = vi.fn((key: string, options?: { ns?: string }) => {// Build full key with namespace prefix if providedconst fullKey = options?.ns ? `${options.ns}.${key}` : key@@ -22,8 +22,8 @@ const mockTranslation = vi.fn((key: string, options?: { ns?: string }) => {return translations[fullKey] || key})-vi.mock('../hooks', () => ({- useMixedTranslation: (_locale?: string) => ({+vi.mock('#i18n', () => ({+ useTranslation: () => ({t: mockTranslation,}),}))@@ -145,36 +145,6 @@ describe('SortDropdown', () => {})})- // ================================- // Props Testing- // ================================- describe('Props', () => {- it('should accept locale prop', () => {- render(<SortDropdown locale="zh-CN" />)-- expect(screen.getByTestId('portal-wrapper')).toBeInTheDocument()- })-- it('should call useMixedTranslation with provided locale', () => {- render(<SortDropdown locale="ja-JP" />)-- // Translation function should be called for labels- expect(mockTranslation).toHaveBeenCalledWith('marketplace.sortBy', { ns: 'plugin' })- })-- it('should render without locale prop (undefined)', () => {- render(<SortDropdown />)-- expect(screen.getByText('Sort by')).toBeInTheDocument()- })-- it('should render with empty string locale', () => {- render(<SortDropdown locale="" />)-- expect(screen.getByText('Sort by')).toBeInTheDocument()- })- })-// ================================// State Management Tests// ================================@@ -618,13 +588,6 @@ describe('SortDropdown', () => {expect(mockTranslation).toHaveBeenCalledWith('marketplace.sortOption.newlyReleased', { ns: 'plugin' })expect(mockTranslation).toHaveBeenCalledWith('marketplace.sortOption.firstReleased', { ns: 'plugin' })})-- it('should pass locale to useMixedTranslation', () => {- render(<SortDropdown locale="pt-BR" />)-- // Verify component renders with locale- expect(screen.getByTestId('portal-wrapper')).toBeInTheDocument()- })})// ================================diff --git a/web/app/components/plugins/marketplace/sort-dropdown/index.tsx b/web/app/components/plugins/marketplace/sort-dropdown/index.tsxindex a1f66317355..984b114d03b 100644--- a/web/app/components/plugins/marketplace/sort-dropdown/index.tsx+++ b/web/app/components/plugins/marketplace/sort-dropdown/index.tsx@@ -1,4 +1,5 @@'use client'+import { useTranslation } from '#i18n'import {RiArrowDownSLine,RiCheckLine,@@ -9,16 +10,10 @@ import {PortalToFollowElemContent,PortalToFollowElemTrigger,} from '@/app/components/base/portal-to-follow-elem'-import { useMixedTranslation } from '@/app/components/plugins/marketplace/hooks'import { useMarketplaceContext } from '../context'-type SortDropdownProps = {- locale?: string-}-const SortDropdown = ({- locale,-}: SortDropdownProps) => {- const { t } = useMixedTranslation(locale)+const SortDropdown = () => {+ const { t } = useTranslation()const options = [{value: 'install_count',diff --git a/web/app/components/plugins/marketplace/sticky-search-and-switch-wrapper.tsx b/web/app/components/plugins/marketplace/sticky-search-and-switch-wrapper.tsxindex 602a1e9af2b..3d3530c83ed 100644--- a/web/app/components/plugins/marketplace/sticky-search-and-switch-wrapper.tsx+++ b/web/app/components/plugins/marketplace/sticky-search-and-switch-wrapper.tsx@@ -5,13 +5,11 @@ import PluginTypeSwitch from './plugin-type-switch'import SearchBoxWrapper from './search-box/search-box-wrapper'type StickySearchAndSwitchWrapperProps = {- locale?: stringpluginTypeSwitchClassName?: stringshowSearchParams?: boolean}const StickySearchAndSwitchWrapper = ({- locale,pluginTypeSwitchClassName,showSearchParams,}: StickySearchAndSwitchWrapperProps) => {@@ -25,9 +23,8 @@ const StickySearchAndSwitchWrapper = ({pluginTypeSwitchClassName,)}>- <SearchBoxWrapper locale={locale} />+ <SearchBoxWrapper /><PluginTypeSwitch- locale={locale}showSearchParams={showSearchParams}/></div>diff --git a/web/app/components/plugins/plugin-item/index.tsx b/web/app/components/plugins/plugin-item/index.tsxindex d287bd9e9a0..3f658c63a80 100644--- a/web/app/components/plugins/plugin-item/index.tsx+++ b/web/app/components/plugins/plugin-item/index.tsx@@ -44,7 +44,7 @@ const PluginItem: FC<Props> = ({}) => {const { t } = useTranslation()const { theme } = useTheme()- const { categoriesMap } = useCategories(t, true)+ const { categoriesMap } = useCategories(true)const currentPluginID = usePluginPageContext(v => v.currentPluginID)const setCurrentPluginID = usePluginPageContext(v => v.setCurrentPluginID)const { refreshPluginList } = useRefreshPluginList()diff --git a/web/app/components/provider/i18n-server.tsx b/web/app/components/provider/i18n-server.tsxnew file mode 100644index 00000000000..23391cf4287--- /dev/null+++ b/web/app/components/provider/i18n-server.tsx@@ -0,0 +1,21 @@+import { getLocaleOnServer, getResources } from '@/i18n-config/server'++import { I18nClientProvider } from './i18n'++export async function I18nServerProvider({+ children,+}: {+ children: React.ReactNode+}) {+ const locale = await getLocaleOnServer()+ const resource = await getResources(locale)++ return (+ <I18nClientProvider+ locale={locale}+ resource={resource}+ >+ {children}+ </I18nClientProvider>+ )+}diff --git a/web/app/components/provider/i18n.tsx b/web/app/components/provider/i18n.tsxnew file mode 100644index 00000000000..6441a09dd37--- /dev/null+++ b/web/app/components/provider/i18n.tsx@@ -0,0 +1,24 @@+'use client'++import type { Resource } from 'i18next'+import type { Locale } from '@/i18n-config'+import { I18nextProvider } from 'react-i18next'+import { createI18nextInstance } from '@/i18n-config/client'++export function I18nClientProvider({+ locale,+ resource,+ children,+}: {+ locale: Locale+ resource: Resource+ children: React.ReactNode+}) {+ const i18n = createI18nextInstance(locale, resource)++ return (+ <I18nextProvider i18n={i18n}>+ {children}+ </I18nextProvider>+ )+}diff --git a/web/app/components/share/text-generation/index.tsx b/web/app/components/share/text-generation/index.tsxindex b9bb59664a0..b793a03ce7e 100644--- a/web/app/components/share/text-generation/index.tsx+++ b/web/app/components/share/text-generation/index.tsx@@ -32,7 +32,7 @@ import { useWebAppStore } from '@/context/web-app-context'import { useAppFavicon } from '@/hooks/use-app-favicon'import useBreakpoints, { MediaType } from '@/hooks/use-breakpoints'import useDocumentTitle from '@/hooks/use-document-title'-import { changeLanguage } from '@/i18n-config/i18next-config'+import { changeLanguage } from '@/i18n-config/client'import { AccessMode } from '@/models/access-control'import { fetchSavedMessage as doFetchSavedMessage, removeMessage, saveMessage } from '@/service/share'import { Resolution, TransferMethod } from '@/types/app'diff --git a/web/app/components/tools/marketplace/index.spec.tsx b/web/app/components/tools/marketplace/index.spec.tsxindex 354c717f2d1..493d960e2a0 100644--- a/web/app/components/tools/marketplace/index.spec.tsx+++ b/web/app/components/tools/marketplace/index.spec.tsx@@ -19,7 +19,6 @@ vi.mock('@/app/components/plugins/marketplace/list', () => ({marketplaceCollectionPluginsMap: Record<string, unknown[]>plugins?: unknown[]showInstallButton?: boolean- locale: string}) => {listRenderSpy(props)return <div data-testid="marketplace-list" />@@ -42,10 +41,6 @@ vi.mock('@/utils/var', () => ({getMarketplaceUrl: vi.fn(() => 'https://marketplace.test/market'),}))-vi.mock('@/i18n-config', () => ({- getLocaleOnClient: () => 'en',-}))-vi.mock('next-themes', () => ({useTheme: () => ({ theme: 'light' }),}))@@ -148,7 +143,6 @@ describe('Marketplace', () => {expect(screen.getByTestId('marketplace-list')).toBeInTheDocument()expect(listRenderSpy).toHaveBeenCalledWith(expect.objectContaining({showInstallButton: true,- locale: 'en',}))})})diff --git a/web/app/components/tools/marketplace/index.tsx b/web/app/components/tools/marketplace/index.tsxindex 476a47d8f61..3900a9e5053 100644--- a/web/app/components/tools/marketplace/index.tsx+++ b/web/app/components/tools/marketplace/index.tsx@@ -1,4 +1,5 @@import type { useMarketplace } from './hooks'+import { useLocale } from '#i18n'import {RiArrowRightUpLine,RiArrowUpDoubleLine,@@ -7,7 +8,6 @@ import { useTheme } from 'next-themes'import { useTranslation } from 'react-i18next'import Loading from '@/app/components/base/loading'import List from '@/app/components/plugins/marketplace/list'-import { getLocaleOnClient } from '@/i18n-config'import { getMarketplaceUrl } from '@/utils/var'type MarketplaceProps = {@@ -24,7 +24,7 @@ const Marketplace = ({showMarketplacePanel,marketplaceContext,}: MarketplaceProps) => {- const locale = getLocaleOnClient()+ const locale = useLocale()const { t } = useTranslation()const { theme } = useTheme()const {@@ -104,7 +104,6 @@ const Marketplace = ({marketplaceCollectionPluginsMap={marketplaceCollectionPluginsMap || {}}plugins={plugins}showInstallButton- locale={locale}/>)}diff --git a/web/app/layout.tsx b/web/app/layout.tsxindex 8fc5f8abcca..acd56e1da64 100644--- a/web/app/layout.tsx+++ b/web/app/layout.tsx@@ -8,9 +8,10 @@ import { TanstackQueryInitializer } from '@/context/query-client'import { getLocaleOnServer } from '@/i18n-config/server'import { DatasetAttr } from '@/types/feature'import { cn } from '@/utils/classnames'+import { ToastProvider } from './components/base/toast'import BrowserInitializer from './components/browser-initializer'import { ReactScanLoader } from './components/devtools/react-scan/loader'-import I18nServer from './components/i18n-server'+import { I18nServerProvider } from './components/provider/i18n-server'import SentryInitializer from './components/sentry-initializer'import RoutePrefixHandle from './routePrefixHandle'import './styles/globals.css'@@ -104,11 +105,13 @@ const LocaleLayout = async ({<BrowserInitializer><SentryInitializer><TanstackQueryInitializer>- <I18nServer>- <GlobalPublicStoreProvider>- {children}- </GlobalPublicStoreProvider>- </I18nServer>+ <I18nServerProvider>+ <ToastProvider>+ <GlobalPublicStoreProvider>+ {children}+ </GlobalPublicStoreProvider>+ </ToastProvider>+ </I18nServerProvider></TanstackQueryInitializer></SentryInitializer></BrowserInitializer>diff --git a/web/context/i18n.ts b/web/context/i18n.tsindex e65049b5064..d57fc5b9843 100644--- a/web/context/i18n.ts+++ b/web/context/i18n.ts@@ -1,10 +1,10 @@import type { Locale } from '@/i18n-config/language'-import { atom, useAtomValue } from 'jotai'+import { useTranslation } from '#i18n'import { getDocLanguage, getLanguage, getPricingPageLanguage } from '@/i18n-config/language'-export const localeAtom = atom<Locale>('en-US')export const useLocale = () => {- return useAtomValue(localeAtom)+ const { i18n } = useTranslation()+ return i18n.language as Locale}export const useGetLanguage = () => {diff --git a/web/i18n-config/client.ts b/web/i18n-config/client.tsnew file mode 100644index 00000000000..17d3dceae13--- /dev/null+++ b/web/i18n-config/client.ts@@ -0,0 +1,35 @@+'use client'+import type { Resource } from 'i18next'+import type { Locale } from '.'+import type { NamespaceCamelCase, NamespaceKebabCase } from './resources'+import { kebabCase } from 'es-toolkit/string'+import { createInstance } from 'i18next'+import resourcesToBackend from 'i18next-resources-to-backend'+import { getI18n, initReactI18next } from 'react-i18next'+import { getInitOptions } from './settings'++export function createI18nextInstance(lng: Locale, resources: Resource) {+ const instance = createInstance()+ instance+ .use(initReactI18next)+ .use(resourcesToBackend((+ language: Locale,+ namespace: NamespaceKebabCase | NamespaceCamelCase,+ ) => {+ const namespaceKebab = kebabCase(namespace)+ return import(`../i18n/${language}/${namespaceKebab}.json`)+ }))+ .init({+ ...getInitOptions(),+ lng,+ resources,+ })+ return instance+}++export const changeLanguage = async (lng?: Locale) => {+ if (!lng)+ return+ const i18n = getI18n()+ await i18n.changeLanguage(lng)+}diff --git a/web/i18n-config/index.ts b/web/i18n-config/index.tsindex bb73ef4b71b..e24fd8533d0 100644--- a/web/i18n-config/index.ts+++ b/web/i18n-config/index.ts@@ -2,7 +2,7 @@ import type { Locale } from '@/i18n-config/language'import Cookies from 'js-cookie'import { LOCALE_COOKIE_NAME } from '@/config'-import { changeLanguage } from '@/i18n-config/i18next-config'+import { changeLanguage } from '@/i18n-config/client'import { LanguagesSupported } from '@/i18n-config/language'export const i18n = {@@ -19,10 +19,6 @@ export const setLocaleOnClient = async (locale: Locale, reloadPage = true) => {location.reload()}-export const getLocaleOnClient = (): Locale => {- return Cookies.get(LOCALE_COOKIE_NAME) as Locale || i18n.defaultLocale-}-export const renderI18nObject = (obj: Record<string, string>, language: string) => {if (!obj)return ''diff --git a/web/i18n-config/lib.client.ts b/web/i18n-config/lib.client.tsindex fc403844585..fffb4d95ae2 100644--- a/web/i18n-config/lib.client.ts+++ b/web/i18n-config/lib.client.ts@@ -1,6 +1,6 @@'use client'-import type { NamespaceCamelCase } from './i18next-config'+import type { NamespaceCamelCase } from './resources'import { useTranslation as useTranslationOriginal } from 'react-i18next'export function useTranslation(ns?: NamespaceCamelCase) {diff --git a/web/i18n-config/lib.server.ts b/web/i18n-config/lib.server.tsindex 4969492cd48..4727ed482f8 100644--- a/web/i18n-config/lib.server.ts+++ b/web/i18n-config/lib.server.ts@@ -1,4 +1,4 @@-import type { NamespaceCamelCase } from './i18next-config'+import type { NamespaceCamelCase } from './resources'import { use } from 'react'import { getLocaleOnServer, getTranslation } from './server'diff --git a/web/i18n-config/i18next-config.ts b/web/i18n-config/resources.tssimilarity index 59%rename from web/i18n-config/i18next-config.tsrename to web/i18n-config/resources.tsindex 09974859675..4bcfb98e14a 100644--- a/web/i18n-config/i18next-config.ts+++ b/web/i18n-config/resources.ts@@ -1,8 +1,4 @@-'use client'-import type { Locale } from '.'-import { camelCase, kebabCase } from 'es-toolkit/string'-import i18n from 'i18next'-import { initReactI18next } from 'react-i18next'+import { kebabCase } from 'es-toolkit/string'import appAnnotation from '../i18n/en-US/app-annotation.json'import appApi from '../i18n/en-US/app-api.json'import appDebug from '../i18n/en-US/app-debug.json'@@ -35,7 +31,7 @@ import tools from '../i18n/en-US/tools.json'import workflow from '../i18n/en-US/workflow.json'// @keep-sorted-export const resources = {+const resources = {app,appAnnotation,appApi,@@ -82,60 +78,5 @@ export type Resources = typeof resourcesexport type NamespaceCamelCase = keyof Resourcesexport type NamespaceKebabCase = KebabCase<NamespaceCamelCase>-const requireSilent = async (lang: Locale, namespace: NamespaceKebabCase) => {- let res- try {- res = (await import(`../i18n/${lang}/${namespace}.json`)).default- }- catch {- res = (await import(`../i18n/en-US/${namespace}.json`)).default- }-- return res-}--const NAMESPACES = Object.keys(resources).map(kebabCase) as NamespaceKebabCase[]--// Load a single namespace for a language-export const loadNamespace = async (lang: Locale, ns: NamespaceKebabCase) => {- const camelNs = camelCase(ns) as NamespaceCamelCase- if (i18n.hasResourceBundle(lang, camelNs))- return-- const resource = await requireSilent(lang, ns)- i18n.addResourceBundle(lang, camelNs, resource, true, true)-}--// Load all namespaces for a language (used when switching language)-export const loadLangResources = async (lang: Locale) => {- await Promise.all(- NAMESPACES.map(ns => loadNamespace(lang, ns)),- )-}--// Initial resources: load en-US namespaces for fallback/default locale-const getInitialTranslations = () => {- return {- 'en-US': resources,- }-}--if (!i18n.isInitialized) {- i18n.use(initReactI18next).init({- lng: undefined,- fallbackLng: 'en-US',- resources: getInitialTranslations(),- defaultNS: 'common',- ns: Object.keys(resources),- keySeparator: false,- })-}--export const changeLanguage = async (lng?: Locale) => {- if (!lng)- return- await loadLangResources(lng)- await i18n.changeLanguage(lng)-}--export default i18n+export const namespacesCamelCase = Object.keys(resources) as NamespaceCamelCase[]+export const namespacesKebabCase = namespacesCamelCase.map(ns => kebabCase(ns)) as NamespaceKebabCase[]diff --git a/web/i18n-config/server.ts b/web/i18n-config/server.tsindex f5966149fd7..403040c1341 100644--- a/web/i18n-config/server.ts+++ b/web/i18n-config/server.ts@@ -1,15 +1,19 @@-import type { i18n as I18nInstance } from 'i18next'+import type { i18n as I18nInstance, Resource, ResourceLanguage } from 'i18next'import type { Locale } from '.'-import type { NamespaceCamelCase, NamespaceKebabCase } from './i18next-config'+import type { NamespaceCamelCase, NamespaceKebabCase } from './resources'import { match } from '@formatjs/intl-localematcher'import { kebabCase } from 'es-toolkit/compat'+import { camelCase } from 'es-toolkit/string'import { createInstance } from 'i18next'import resourcesToBackend from 'i18next-resources-to-backend'import Negotiator from 'negotiator'import { cookies, headers } from 'next/headers'+import { cache } from 'react'import { initReactI18next } from 'react-i18next/initReactI18next'import { serverOnlyContext } from '@/utils/server-only-context'import { i18n } from '.'+import { namespacesKebabCase } from './resources'+import { getInitOptions } from './settings'const [getLocaleCache, setLocaleCache] = serverOnlyContext<Locale | null>(null)const [getI18nInstance, setI18nInstance] = serverOnlyContext<I18nInstance | null>(null)@@ -27,9 +31,8 @@ const getOrCreateI18next = async (lng: Locale) => {return import(`../i18n/${language}/${fileNamespace}.json`)})).init({+ ...getInitOptions(),lng,- fallbackLng: 'en-US',- keySeparator: false,})setI18nInstance(instance)return instance@@ -76,3 +79,16 @@ export const getLocaleOnServer = async (): Promise<Locale> => {setLocaleCache(matchedLocale)return matchedLocale}++export const getResources = cache(async (lng: Locale): Promise<Resource> => {+ const messages = {} as ResourceLanguage++ await Promise.all(+ (namespacesKebabCase).map(async (ns) => {+ const mod = await import(`../i18n/${lng}/${ns}.json`)+ messages[camelCase(ns)] = mod.default+ }),+ )++ return { [lng]: messages }+})diff --git a/web/i18n-config/settings.ts b/web/i18n-config/settings.tsnew file mode 100644index 00000000000..1bf37ab21d5--- /dev/null+++ b/web/i18n-config/settings.ts@@ -0,0 +1,13 @@+import type { InitOptions } from 'i18next'+import { namespacesCamelCase } from './resources'++export function getInitOptions(): InitOptions {+ return {+ // We do not have en for fallback+ load: 'currentOnly',+ fallbackLng: 'en-US',+ partialBundledLanguages: true,+ keySeparator: false,+ ns: namespacesCamelCase,+ }+}diff --git a/web/types/i18n.d.ts b/web/types/i18n.d.tsindex 160d385730d..9e20d5a55a7 100644--- a/web/types/i18n.d.ts+++ b/web/types/i18n.d.ts@@ -1,4 +1,4 @@-import type { NamespaceCamelCase, Resources } from '../i18n-config/i18next-config'+import type { NamespaceCamelCase, Resources } from '../i18n-config/resources'import 'i18next'declare module 'i18next' {