🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
feat: show selected language label in language switcher (#16231)
Bittu kumard8e288de60a2
diff --git a/src/features/AuthShell/AuthContainer.tsx b/src/features/AuthShell/AuthContainer.tsxindex 49d17493c64..49a16e588eb 100644--- a/src/features/AuthShell/AuthContainer.tsx+++ b/src/features/AuthShell/AuthContainer.tsx@@ -32,7 +32,7 @@ const AuthContainer: FC<PropsWithChildren> = ({ children }) => {</Center><Flexbox horizontal align={'center'} justify={'space-between'} padding={16} width={'100%'}><Flexbox horizontal align={'center'}>- <AuthLangButton size={18} />+ <AuthLangButton /><Divider className={styles.divider} orientation={'vertical'} /><AuthThemeButton size={18} /></Flexbox>diff --git a/src/features/AuthShell/AuthLangButton.tsx b/src/features/AuthShell/AuthLangButton.tsxindex cdff955446e..2e834a86cbe 100644--- a/src/features/AuthShell/AuthLangButton.tsx+++ b/src/features/AuthShell/AuthLangButton.tsx@@ -1,13 +1,13 @@'use client';import {- ActionIcon,DropdownMenu,type DropdownMenuCheckboxItem,Flexbox,Text,} from '@lobehub/ui';-import { Languages } from 'lucide-react';+import { Button } from '@lobehub/ui/base-ui';+import { GlobeIcon } from 'lucide-react';import { memo, useMemo } from 'react';import { useTranslation } from 'react-i18next';@@ -19,10 +19,11 @@ const setCookieSimple = (key: string, value: string, days: number) => {document.cookie = `${key}=${value};expires=${expires};path=/;`;};-const AuthLangButton = memo<{ size?: number }>((props) => {+const AuthLangButton = memo(() => {const { i18n } = useTranslation();const browserLanguage = typeof navigator !== 'undefined' ? navigator.language : 'en-US';const current = normalizeLocale(i18n.resolvedLanguage || i18n.language || browserLanguage);+ const currentLabel = localeOptions.find((item) => item.value === current)?.label || 'English';const items = useMemo<DropdownMenuCheckboxItem[]>(() =>@@ -57,7 +58,18 @@ const AuthLangButton = memo<{ size?: number }>((props) => {},}}>- <ActionIcon icon={Languages} size={props.size || { blockSize: 32, size: 16 }} />+ <Button+ icon={GlobeIcon}+ iconPosition="end"+ size="small"+ type="text"+ style={{+ height: 32,+ paddingInline: 8,+ }}+ >+ <Text fontSize={12}>{currentLabel}</Text>+ </Button></DropdownMenu>);});diff --git a/src/features/DesktopOnboarding/Layout/index.tsx b/src/features/DesktopOnboarding/Layout/index.tsxindex 3670d0d91fd..58fd9e220f0 100644--- a/src/features/DesktopOnboarding/Layout/index.tsx+++ b/src/features/DesktopOnboarding/Layout/index.tsx@@ -42,7 +42,7 @@ const OnboardingContainer: FC<PropsWithChildren> = ({ children }) => {><div /><Flexbox horizontal align={'center'}>- <LangButton placement={'bottomRight'} size={18} />+ <LangButton compact placement={'bottomRight'} /><Divider className={styles.divider} orientation={'vertical'} /><ThemeButton placement={'bottomRight'} size={18} /></Flexbox>diff --git a/src/features/Onboarding/Layout/index.tsx b/src/features/Onboarding/Layout/index.tsxindex 702ed7582fd..48afb523d09 100644--- a/src/features/Onboarding/Layout/index.tsx+++ b/src/features/Onboarding/Layout/index.tsx@@ -56,7 +56,7 @@ const OnBoardingContainer: FC<PropsWithChildren> = ({ children }) => {<ProductLogo color={theme.colorText} size={28} type={'text'} /><Flexbox horizontal align={'center'} gap={16}><Flexbox horizontal align={'center'}>- <LangButton placement={'bottomRight'} size={18} />+ <LangButton compact placement={'bottomRight'} /><Divider className={styles.divider} orientation={'vertical'} /><ThemeButton placement={'bottomRight'} size={18} /></Flexbox>diff --git a/src/features/User/UserPanel/LangButton.tsx b/src/features/User/UserPanel/LangButton.tsxindex a855f795078..362f8ba0f6a 100644--- a/src/features/User/UserPanel/LangButton.tsx+++ b/src/features/User/UserPanel/LangButton.tsx@@ -1,7 +1,8 @@import { type DropdownMenuCheckboxItem, type DropdownMenuProps } from '@lobehub/ui';-import { ActionIcon, DropdownMenu, Flexbox, Icon, Text } from '@lobehub/ui';+import { DropdownMenu, Flexbox, Icon, Text } from '@lobehub/ui';+import { Button } from '@lobehub/ui/base-ui';import { cssVar } from 'antd-style';-import { ChevronRight, Languages } from 'lucide-react';+import { ChevronRight, GlobeIcon } from 'lucide-react';import { memo, type ReactNode, useMemo } from 'react';import { useTranslation } from 'react-i18next';@@ -11,14 +12,22 @@ import { globalGeneralSelectors } from '@/store/global/selectors';import { electronStylish } from '@/styles/electron';import { preloadLang } from '@/utils/client/preloadLang';-const LangButton = memo<{ placement?: DropdownMenuProps['placement']; size?: number }>(- ({ placement, size }) => {- const [language, switchLocale] = useGlobalStore((s) => [+import { getLanguageDisplayLabel } from './getLanguageDisplayLabel';++const LangButton = memo<{ compact?: boolean; placement?: DropdownMenuProps['placement'] }>(+ ({ compact, placement }) => {+ const [language, currentLanguage, switchLocale] = useGlobalStore((s) => [globalGeneralSelectors.language(s),+ globalGeneralSelectors.currentLanguage(s),s.switchLocale,]);const { t } = useTranslation(['setting', 'common']);+ const currentLabel = getLanguageDisplayLabel(+ language,+ currentLanguage,+ t('settingCommon.lang.autoMode'),+ );const items = useMemo<DropdownMenuCheckboxItem[]>(() => {const autoItem: DropdownMenuCheckboxItem = {@@ -66,8 +75,21 @@ const LangButton = memo<{ placement?: DropdownMenuProps['placement']; size?: numlet trigger: ReactNode;- if (size) {- trigger = <ActionIcon icon={Languages} size={size} />;+ if (compact) {+ trigger = (+ <Button+ icon={GlobeIcon}+ iconPosition="end"+ size="small"+ type="text"+ style={{+ height: 32,+ paddingInline: 8,+ }}+ >+ <Text fontSize={12}>{currentLabel}</Text>+ </Button>+ );} else {trigger = (<Flexbox@@ -90,8 +112,8 @@ const LangButton = memo<{ placement?: DropdownMenuProps['placement']; size?: nume.currentTarget.style.background = 'transparent';}}>- <Icon icon={Languages} size={'small'} style={{ color: cssVar.colorTextSecondary }} />- <Flexbox flex={1}>{t('settingCommon.lang.title')}</Flexbox>+ <Flexbox flex={1}>{currentLabel}</Flexbox>+ <Icon icon={GlobeIcon} size={'small'} style={{ color: cssVar.colorTextSecondary }} /><Icon icon={ChevronRight} size={'small'} style={{ color: cssVar.colorTextSecondary }} /></Flexbox>);diff --git a/src/features/User/UserPanel/getLanguageDisplayLabel.test.ts b/src/features/User/UserPanel/getLanguageDisplayLabel.test.tsnew file mode 100644index 00000000000..0d22c17837f--- /dev/null+++ b/src/features/User/UserPanel/getLanguageDisplayLabel.test.ts@@ -0,0 +1,15 @@+import { describe, expect, it } from 'vitest';++import { getLanguageDisplayLabel } from './getLanguageDisplayLabel';++describe('getLanguageDisplayLabel', () => {+ it('shows the resolved locale alongside Follow System in auto mode', () => {+ expect(getLanguageDisplayLabel('auto', 'en-US', 'Follow System')).toBe(+ 'Follow System · English',+ );+ });++ it('shows the manually selected locale without the auto-mode label', () => {+ expect(getLanguageDisplayLabel('fr-FR', 'en-US', 'Follow System')).toBe('Français');+ });+});diff --git a/src/features/User/UserPanel/getLanguageDisplayLabel.ts b/src/features/User/UserPanel/getLanguageDisplayLabel.tsnew file mode 100644index 00000000000..9d7f5c21dfd--- /dev/null+++ b/src/features/User/UserPanel/getLanguageDisplayLabel.ts@@ -0,0 +1,15 @@+import type { Locales } from '@/locales/resources';+import { localeOptions } from '@/locales/resources';+import type { LocaleMode } from '@/types/locale';++export const getLanguageDisplayLabel = (+ languageMode: LocaleMode,+ currentLanguage: Locales,+ autoLabel: string,+) => {+ const activeLanguage = languageMode === 'auto' ? currentLanguage : languageMode;+ const activeLabel =+ localeOptions.find((item) => item.value === activeLanguage)?.label || 'English';++ return languageMode === 'auto' ? `${autoLabel} · ${activeLabel}` : activeLabel;+};