mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-04-05 15:27:20 +02:00
🗣️ fix: Prevent @librechat/client useLocalize from Overwriting Host App Language State (#12515)
* directly returns the translation function without managing language state in client package * chore: remove unused langAtom from packages/client store * fix: add useCallback to match canonical useLocalize, add guard comment --------- Co-authored-by: Danny Avila <danny@librechat.ai>
This commit is contained in:
parent
162ac9c253
commit
2140729a54
2 changed files with 7 additions and 13 deletions
|
|
@ -1,21 +1,16 @@
|
|||
import { useEffect } from 'react';
|
||||
import { useCallback } from 'react';
|
||||
import { TOptions } from 'i18next';
|
||||
import { useAtomValue } from 'jotai';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { resources } from '~/locales/i18n';
|
||||
import { langAtom } from '~/store';
|
||||
|
||||
export type TranslationKeys = keyof typeof resources.en.translation;
|
||||
|
||||
/** Language lifecycle is managed by the host app — do not add i18n.changeLanguage() calls here. */
|
||||
export default function useLocalize() {
|
||||
const lang = useAtomValue(langAtom);
|
||||
const { t, i18n } = useTranslation();
|
||||
const { t } = useTranslation();
|
||||
|
||||
useEffect(() => {
|
||||
if (i18n.language !== lang) {
|
||||
i18n.changeLanguage(lang);
|
||||
}
|
||||
}, [lang, i18n]);
|
||||
|
||||
return (phraseKey: TranslationKeys, options?: TOptions) => t(phraseKey, options);
|
||||
return useCallback(
|
||||
(phraseKey: TranslationKeys, options?: TOptions) => t(phraseKey, options),
|
||||
[t],
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
import { atom } from 'jotai';
|
||||
import { NotificationSeverity } from '~/common';
|
||||
|
||||
export const langAtom = atom<string>('en');
|
||||
export const chatDirectionAtom = atom<string>('ltr');
|
||||
export const fontSizeAtom = atom<string>('text-base');
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue