mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-01-16 23:45:33 +01:00
⚙️ feat: Add configurable trust checkbox labels for MCP Server Dialog (#10820)
Co-authored-by: Atef Bellaaj <slalom.bellaaj@external.daimlertruck.com>
This commit is contained in:
parent
394bb6242b
commit
9400148175
5 changed files with 91 additions and 4 deletions
|
|
@ -34,3 +34,4 @@ export { default as useSpeechToText } from './Input/useSpeechToText';
|
|||
export { default as useTextToSpeech } from './Input/useTextToSpeech';
|
||||
export { default as useGenerationsByLatest } from './useGenerationsByLatest';
|
||||
export { useResourcePermissions } from './useResourcePermissions';
|
||||
export { default as useLocalizedConfig } from './useLocalizedConfig';
|
||||
|
|
|
|||
36
client/src/hooks/useLocalizedConfig.ts
Normal file
36
client/src/hooks/useLocalizedConfig.ts
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
import { useRecoilValue } from 'recoil';
|
||||
import store from '~/store';
|
||||
|
||||
type LocalizedValue = string | Record<string, string> | undefined;
|
||||
|
||||
/**
|
||||
* Hook to resolve localized config values based on current user language.
|
||||
* Automatically retrieves the current language from Recoil state.
|
||||
*
|
||||
* @returns A function to resolve localized values
|
||||
*/
|
||||
export default function useLocalizedConfig() {
|
||||
const lang = useRecoilValue(store.lang);
|
||||
|
||||
/**
|
||||
* Resolves a localized config value.
|
||||
* @param value - Either a string or object with language codes as keys
|
||||
* @param fallback - Fallback value if config is undefined or language not found
|
||||
* @returns The resolved string value
|
||||
*/
|
||||
return (value: LocalizedValue, fallback: string): string => {
|
||||
if (value === undefined) {
|
||||
return fallback;
|
||||
}
|
||||
if (typeof value === 'string') {
|
||||
return value;
|
||||
}
|
||||
// Extract base language code (e.g., 'de' from 'de-DE')
|
||||
const baseLang = lang?.split('-')[0] ?? 'en';
|
||||
|
||||
// Try exact locale (de-DE), then base language (de), then 'en', then first available
|
||||
return (
|
||||
(lang && value[lang]) || value[baseLang] || value['en'] || Object.values(value)[0] || fallback
|
||||
);
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue