🗣️ fix: Prevent @librechat/client useLocalize from Overwriting Host App Language State (#12515)
Some checks are pending
Docker Dev Branch Images Build / build (Dockerfile, lc-dev, node) (push) Waiting to run
Docker Dev Branch Images Build / build (Dockerfile.multi, lc-dev-api, api-build) (push) Waiting to run

* 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:
Shahryar Tayeb 2026-04-04 04:01:39 +09:00 committed by GitHub
parent 162ac9c253
commit 2140729a54
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 13 deletions

View file

@ -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],
);
}

View file

@ -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');