fix(share): The language of the shared page will cause the language of the original website to change. (#18043)

This commit is contained in:
chanx
2026-08-10 17:26:18 +08:00
committed by GitHub
parent d6292da508
commit 5a2cd36b45
8 changed files with 44 additions and 47 deletions

View File

@@ -1,6 +1,5 @@
import { Toaster as Sonner } from '@/components/ui/sonner'; import { Toaster as Sonner } from '@/components/ui/sonner';
import { Toaster } from '@/components/ui/toaster'; import { Toaster } from '@/components/ui/toaster';
import { changeLanguageAsync } from '@/locales/config';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { configResponsive } from 'ahooks'; import { configResponsive } from 'ahooks';
import dayjs from 'dayjs'; import dayjs from 'dayjs';
@@ -13,13 +12,12 @@ import localeData from 'dayjs/plugin/localeData';
import weekOfYear from 'dayjs/plugin/weekOfYear'; import weekOfYear from 'dayjs/plugin/weekOfYear';
import weekYear from 'dayjs/plugin/weekYear'; import weekYear from 'dayjs/plugin/weekYear';
import weekday from 'dayjs/plugin/weekday'; import weekday from 'dayjs/plugin/weekday';
import React, { useEffect } from 'react'; import React from 'react';
import { RouterProvider } from 'react-router'; import { RouterProvider } from 'react-router';
import { ThemeProvider } from './components/theme-provider'; import { ThemeProvider } from './components/theme-provider';
import { TooltipProvider } from './components/ui/tooltip'; import { TooltipProvider } from './components/ui/tooltip';
import { ThemeEnum } from './constants/common'; import { ThemeEnum } from './constants/common';
import { routers } from './routes'; import { routers } from './routes';
import storage from './utils/authorization-util';
import 'react-photo-view/dist/react-photo-view.css'; import 'react-photo-view/dist/react-photo-view.css';
@@ -76,13 +74,6 @@ function Root({ children }: React.PropsWithChildren) {
} }
const RootProvider = ({ children }: React.PropsWithChildren) => { const RootProvider = ({ children }: React.PropsWithChildren) => {
useEffect(() => {
const lng = storage.getLanguage();
if (lng) {
void changeLanguageAsync(lng);
}
}, []);
return ( return (
<TooltipProvider> <TooltipProvider>
<QueryClientProvider client={queryClient}> <QueryClientProvider client={queryClient}>

View File

@@ -294,7 +294,7 @@ const FloatingChatWidget = () => {
}, 50); }, 50);
if (locale && i18n.language !== locale) { if (locale && i18n.language !== locale) {
changeLanguageAsync(locale); changeLanguageAsync(locale, { persist: false });
} }
return () => clearTimeout(timer); return () => clearTimeout(timer);

View File

@@ -131,32 +131,29 @@ export function NextMessageInput({
}; };
}, [isResizing]); }, [isResizing]);
const thinkingOptions = useMemo( const thinkingOptions = [
() => [ {
{ label: t('chat.thinkingLevelUltra'),
label: t('chat.thinkingLevelUltra'), value: '4',
value: '4', description: t('chat.thinkingLevelUltraDescription'),
description: t('chat.thinkingLevelUltraDescription'), },
}, {
{ label: t('chat.thinkingLevelHigh'),
label: t('chat.thinkingLevelHigh'), value: '3',
value: '3', description: t('chat.thinkingLevelHighDescription'),
description: t('chat.thinkingLevelHighDescription'), },
}, {
{ label: t('chat.thinkingLevelMedium'),
label: t('chat.thinkingLevelMedium'), value: '2',
value: '2', description: t('chat.thinkingLevelMediumDescription'),
description: t('chat.thinkingLevelMediumDescription'), },
}, {
{ label: t('chat.thinkingLevelLow'),
label: t('chat.thinkingLevelLow'), value: '1',
value: '1', description: t('chat.thinkingLevelLowDescription'),
description: t('chat.thinkingLevelLowDescription'), },
}, { label: t('chat.thinkingLevelNone'), value: '0' },
{ label: t('chat.thinkingLevelNone'), value: '0' }, ];
],
[t],
);
const handleThinkingChange = useCallback((value: string) => { const handleThinkingChange = useCallback((value: string) => {
setEnableThinking(value); setEnableThinking(value);

View File

@@ -28,9 +28,9 @@ import {
PopoverTrigger, PopoverTrigger,
} from '@/components/ui/popover'; } from '@/components/ui/popover';
import { cn } from '@/lib/utils'; import { cn } from '@/lib/utils';
import { t } from 'i18next';
import { RAGFlowSelectOptionType } from '../ui/select'; import { RAGFlowSelectOptionType } from '../ui/select';
import { Separator } from '../ui/separator'; import { Separator } from '../ui/separator';
import { useTranslation } from 'react-i18next';
export type SelectWithSearchOptionType = RAGFlowSelectOptionType & { export type SelectWithSearchOptionType = RAGFlowSelectOptionType & {
description?: ReactNode; description?: ReactNode;
@@ -127,8 +127,8 @@ export const SelectWithSearch = forwardRef<
triggerClassName, triggerClassName,
allowClear = false, allowClear = false,
disabled = false, disabled = false,
placeholder = t('common.selectPlaceholder'), placeholder,
emptyData = t('common.noDataFound'), emptyData,
allowCustomValue = false, allowCustomValue = false,
onNoMatchEnter, onNoMatchEnter,
disableAutoSelectOnEnter = false, disableAutoSelectOnEnter = false,
@@ -137,6 +137,9 @@ export const SelectWithSearch = forwardRef<
}, },
ref, ref,
) => { ) => {
const { t } = useTranslation();
const resolvedPlaceholder = placeholder ?? t('common.selectPlaceholder');
const resolvedEmptyData = emptyData ?? t('common.noDataFound');
const id = useId(); const id = useId();
const [open, setOpen] = useState<boolean>(false); const [open, setOpen] = useState<boolean>(false);
const [value, setValue] = useState<string>(''); const [value, setValue] = useState<string>('');
@@ -257,7 +260,7 @@ export const SelectWithSearch = forwardRef<
{selectLabel || value} {selectLabel || value}
</span> </span>
) : ( ) : (
<span className="text-text-disabled">{placeholder}</span> <span className="text-text-disabled">{resolvedPlaceholder}</span>
)} )}
<div className="flex items-center justify-between"> <div className="flex items-center justify-between">
{value && allowClear && ( {value && allowClear && (
@@ -296,7 +299,7 @@ export const SelectWithSearch = forwardRef<
)} )}
<CommandList className="mt-2 outline-none"> <CommandList className="mt-2 outline-none">
<CommandEmpty> <CommandEmpty>
<div dangerouslySetInnerHTML={{ __html: emptyData }}></div> <div dangerouslySetInnerHTML={{ __html: resolvedEmptyData }}></div>
</CommandEmpty> </CommandEmpty>
{hasCustomSearchValue && ( {hasCustomSearchValue && (
<CommandItem <CommandItem

View File

@@ -97,7 +97,11 @@ export const loadLanguageAsync = async (lng: string): Promise<void> => {
} }
}; };
export const changeLanguageAsync = async (lng: string): Promise<void> => { export const changeLanguageAsync = async (
lng: string,
options: { persist?: boolean } = {},
): Promise<void> => {
const { persist = true } = options;
const normalizedLng = lng; const normalizedLng = lng;
if ( if (
@@ -107,7 +111,9 @@ export const changeLanguageAsync = async (lng: string): Promise<void> => {
await loadLanguageAsync(normalizedLng); await loadLanguageAsync(normalizedLng);
} }
storage.setLanguage(lng); if (persist) {
storage.setLanguage(lng);
}
updateDocumentLocale(lng); updateDocumentLocale(lng);

View File

@@ -87,7 +87,7 @@ const ChatContainer = () => {
React.useEffect(() => { React.useEffect(() => {
if (locale && i18n.language !== locale) { if (locale && i18n.language !== locale) {
changeLanguageAsync(locale); changeLanguageAsync(locale, { persist: false });
} }
}, [locale, visibleAvatar]); }, [locale, visibleAvatar]);

View File

@@ -44,7 +44,7 @@ const ChatContainer = () => {
React.useEffect(() => { React.useEffect(() => {
if (locale && i18n.language !== locale) { if (locale && i18n.language !== locale) {
changeLanguageAsync(locale); changeLanguageAsync(locale, { persist: false });
} }
}, [locale, visibleAvatar]); }, [locale, visibleAvatar]);

View File

@@ -24,7 +24,7 @@ export default function ShareSearchPage() {
useEffect(() => { useEffect(() => {
if (locale && i18n.language !== locale) { if (locale && i18n.language !== locale) {
changeLanguageAsync(locale); changeLanguageAsync(locale, { persist: false });
} }
}, [locale]); }, [locale]);
return ( return (