From b64273957a74cd7ca54bd163831a65f8398e101c Mon Sep 17 00:00:00 2001 From: Abner Chou Date: Sat, 22 Jul 2023 15:09:45 -0400 Subject: [PATCH] Add localization support for endpoint pages components (#667) * init localization * Update defaul to en * Fix merge issue and import path. * Set default to en * Change jsx to tsx * Update the password max length string. * Remove languageContext as using the recoil instead. * Add localization to component endpoints pages * Revert default to en after testing. * Update LoginForm.tsx * Fix translation. * Make lint happy --- .../components/Endpoints/BingAI/Settings.jsx | 22 +++--- .../components/Endpoints/EditPresetDialog.jsx | 24 +++++-- .../Endpoints/EndpointOptionsDialog.jsx | 6 +- .../Endpoints/EndpointOptionsPopover.jsx | 7 +- .../components/Endpoints/Google/Examples.jsx | 10 ++- .../Endpoints/Google/OptionHover.jsx | 15 ++-- .../components/Endpoints/Google/Settings.jsx | 19 ++--- .../Endpoints/OpenAI/OptionHover.jsx | 17 +++-- .../components/Endpoints/OpenAI/Settings.jsx | 23 +++--- .../Endpoints/Plugins/AgentSettings.jsx | 9 ++- .../components/Endpoints/Plugins/Settings.jsx | 25 ++++--- .../Endpoints/SaveAsPresetDialog.jsx | 4 +- client/src/localization/Translation.tsx | 24 ++++++- client/src/localization/languages/Eng.tsx | 70 +++++++++++++++++++ client/src/localization/languages/Zh.tsx | 4 +- 15 files changed, 212 insertions(+), 67 deletions(-) diff --git a/client/src/components/Endpoints/BingAI/Settings.jsx b/client/src/components/Endpoints/BingAI/Settings.jsx index 19c5b7e75f..3a9671cc4a 100644 --- a/client/src/components/Endpoints/BingAI/Settings.jsx +++ b/client/src/components/Endpoints/BingAI/Settings.jsx @@ -6,6 +6,9 @@ import SelectDropDown from '../../ui/SelectDropDown'; import { cn } from '~/utils/'; import useDebounce from '~/hooks/useDebounce'; import { useUpdateTokenCountMutation } from '@librechat/data-provider'; +import { useRecoilValue } from 'recoil'; +import store from '~/store'; +import { localize } from '~/localization/Translation'; const defaultTextProps = 'rounded-md border border-gray-200 focus:border-slate-400 focus:bg-gray-50 bg-transparent text-sm shadow-[0_0_10px_rgba(0,0,0,0.05)] outline-none placeholder:text-gray-400 focus:outline-none focus:ring-gray-400 focus:ring-opacity-20 focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 dark:border-gray-500 dark:bg-gray-700 focus:dark:bg-gray-600 dark:text-gray-50 dark:shadow-[0_0_15px_rgba(0,0,0,0.10)] dark:focus:border-gray-400 dark:focus:outline-none dark:focus:ring-0 dark:focus:ring-gray-400 dark:focus:ring-offset-0'; @@ -20,6 +23,7 @@ function Settings(props) { const setToneStyle = (value) => setOption('toneStyle')(value.toLowerCase()); const debouncedContext = useDebounce(context, 250); const updateTokenCountMutation = useUpdateTokenCountMutation(); + const lang = useRecoilValue(store.lang); useEffect(() => { if (!debouncedContext || debouncedContext.trim() === '') { @@ -48,7 +52,7 @@ function Settings(props) {
setContext(e.target.value || null)} - placeholder="Bing can use up to 7k tokens for 'context', which it can reference for the conversation. The specific limit is not known but may run into errors exceeding 7k tokens" + placeholder={localize(lang, 'com_endpoint_bing_context_placeholder')} className={cn( defaultTextProps, 'flex max-h-[300px] min-h-[100px] w-full resize-none px-3 py-2', )} /> - {`Token count: ${tokenCount}`} + {`${localize(lang, 'com_endpoint_token_count')}: ${tokenCount}`}
- Jailbreak To enable Sydney + {localize(lang, 'com_endpoint_bing_jailbreak')} {localize(lang, 'com_endpoint_bing_to_enable_sydney')}
@@ -116,9 +120,9 @@ function Settings(props) { className="text-blue-500 transition-colors duration-200 hover:text-blue-800 dark:text-blue-400 dark:hover:text-blue-500" rel="noreferrer" > - System Message + {localize(lang, 'com_endpoint_system_message')} {' '} - (default: blank) + ( {localize(lang, 'com_endpoint_default_blank')}) setSystemMessage(e.target.value || null)} - placeholder="WARNING: Misuse of this feature can get you BANNED from using Bing! Click on 'System Message' for full instructions and the default message if omitted, which is the 'Sydney' preset that is considered safe." + placeholder={localize(lang, 'com_endpoint_bing_system_message_placeholder')} className={cn( defaultTextProps, 'flex max-h-[300px] min-h-[100px] w-full resize-none px-3 py-2 placeholder:text-red-400', diff --git a/client/src/components/Endpoints/EditPresetDialog.jsx b/client/src/components/Endpoints/EditPresetDialog.jsx index 5ac77de5f9..4ee399bc8f 100644 --- a/client/src/components/Endpoints/EditPresetDialog.jsx +++ b/client/src/components/Endpoints/EditPresetDialog.jsx @@ -20,10 +20,12 @@ import { } from '~/components/'; import { cn } from '~/utils/'; import cleanupPreset from '~/utils/cleanupPreset'; +import { localize } from '~/localization/Translation'; import store from '~/store'; const EditPresetDialog = ({ open, onOpenChange, preset: _preset, title }) => { + const lang = useRecoilValue(store.lang); const [preset, setPreset] = useState(_preset); const setPresets = useSetRecoilState(store.presets); const [showExamples, setShowExamples] = useState(false); @@ -174,13 +176,13 @@ const EditPresetDialog = ({ open, onOpenChange, preset: _preset, title }) => {
setOption('title')(e.target.value || '')} - placeholder="Set a custom name, in case you can find this preset" + placeholder={localize(lang, 'com_endpoint_set_custom_name')} className={cn( defaultTextProps, 'flex h-10 max-h-10 w-full resize-none px-3 py-2 focus:outline-none focus:ring-0 focus:ring-opacity-0 focus:ring-offset-0', @@ -189,7 +191,7 @@ const EditPresetDialog = ({ open, onOpenChange, preset: _preset, title }) => {
{ onClick={triggerExamples} > - {(showExamples ? 'Hide' : 'Show') + ' Examples'} + {(showExamples + ? localize(lang, 'com_endpoint_hide') + : localize(lang, 'com_endpoint_show')) + + localize(lang, 'com_endpoint_examples')} )} {preset?.endpoint === 'gptPlugins' && ( @@ -220,6 +225,13 @@ const EditPresetDialog = ({ open, onOpenChange, preset: _preset, title }) => { > {`Show ${showAgentSettings ? 'Completion' : 'Agent'} Settings`} + {localize( + lang, + 'com_endpoint_show_what_settings', + showAgentSettings + ? localize(lang, 'com_endpoint_completion') + : localize(lang, 'com_endpoint_agent'), + )} )}
@@ -261,14 +273,14 @@ const EditPresetDialog = ({ open, onOpenChange, preset: _preset, title }) => { onClick={submitPreset} className="dark:hover:gray-400 border-gray-700 bg-green-600 text-white hover:bg-green-700 dark:hover:bg-green-800" > - Save + {localize(lang, 'com_endpoint_save')} } leftButtons={ <> - Export + {localize(lang, 'com_endpoint_export')} } diff --git a/client/src/components/Endpoints/EndpointOptionsDialog.jsx b/client/src/components/Endpoints/EndpointOptionsDialog.jsx index 85e4e47030..ffd2660ce8 100644 --- a/client/src/components/Endpoints/EndpointOptionsDialog.jsx +++ b/client/src/components/Endpoints/EndpointOptionsDialog.jsx @@ -8,6 +8,7 @@ import { alternateName } from '~/utils'; import Settings from './Settings'; import store from '~/store'; +import { localize } from '~/localization/Translation'; // A preset dialog to show readonly preset values. const EndpointOptionsDialog = ({ open, onOpenChange, preset: _preset, title }) => { @@ -15,6 +16,7 @@ const EndpointOptionsDialog = ({ open, onOpenChange, preset: _preset, title }) = const [saveAsDialogShow, setSaveAsDialogShow] = useState(false); const endpointsConfig = useRecoilValue(store.endpointsConfig); const endpointName = alternateName[preset?.endpoint] ?? 'Endpoint'; + const lang = useRecoilValue(store.lang); const setOption = (param) => (newValue) => { let update = {}; @@ -61,14 +63,14 @@ const EndpointOptionsDialog = ({ open, onOpenChange, preset: _preset, title }) = onClick={saveAsPreset} className="dark:hover:gray-400 border-gray-700 bg-green-600 text-white hover:bg-green-700 dark:hover:bg-green-800" > - Save As Preset + {localize(lang, 'com_endpoint_save_as_preset')} } leftButtons={ <> - Export + {localize(lang, 'com_endpoint_export')} } diff --git a/client/src/components/Endpoints/EndpointOptionsPopover.jsx b/client/src/components/Endpoints/EndpointOptionsPopover.jsx index c96be79680..3962355c0c 100644 --- a/client/src/components/Endpoints/EndpointOptionsPopover.jsx +++ b/client/src/components/Endpoints/EndpointOptionsPopover.jsx @@ -5,6 +5,10 @@ import CrossIcon from '../svg/CrossIcon'; import { Save } from 'lucide-react'; import { cn } from '~/utils/'; +import store from '~/store'; +import { useRecoilValue } from 'recoil'; +import { localize } from '~/localization/Translation'; + function EndpointOptionsPopover({ content, visible, @@ -12,6 +16,7 @@ function EndpointOptionsPopover({ switchToSimpleMode, additionalButton = null, }) { + const lang = useRecoilValue(store.lang); const cardStyle = 'shadow-md rounded-md min-w-[75px] font-normal bg-white border-black/10 border dark:bg-gray-700 text-black dark:text-white'; @@ -37,7 +42,7 @@ function EndpointOptionsPopover({ onClick={saveAsPreset} > - Save as preset + {localize(lang, 'com_endpoint_save_as_preset')} {additionalButton && (