From 8a4ad4ff6238b218fd86595db43eb022353c2101 Mon Sep 17 00:00:00 2001 From: Oliver Date: Tue, 24 Feb 2026 16:08:26 +1100 Subject: [PATCH] [UI] Default locale (#11412) * [UI] Support default server language * Handle faulty theme * Add option for default language * Improve language selection * Brief docs entry * Fix typo * Fix yarn build * Remove debug msg * Fix calendar locale --- docs/docs/concepts/user_interface.md | 8 +++ .../src/components/calendar/Calendar.tsx | 18 ++++++- .../src/components/items/LanguageSelect.tsx | 16 +++++- .../src/components/plugins/PluginContext.tsx | 5 +- src/frontend/src/contexts/LanguageContext.tsx | 54 ++++++++++++++++--- src/frontend/src/contexts/ThemeContext.tsx | 42 +++++++++------ src/frontend/src/states/LocalState.tsx | 6 +-- 7 files changed, 119 insertions(+), 30 deletions(-) diff --git a/docs/docs/concepts/user_interface.md b/docs/docs/concepts/user_interface.md index a7a20f99f0..665b9fcf02 100644 --- a/docs/docs/concepts/user_interface.md +++ b/docs/docs/concepts/user_interface.md @@ -291,3 +291,11 @@ Users may opt to disable the spotlight search functionality if they do not find Many aspects of the user interface are controlled by user permissions, which determine what actions and features are available to each user based on their assigned roles and permissions within the system. This allows for a highly customizable user experience, where different users can have access to different features and functionality based on their specific needs and responsibilities within the organization. If a user does not have permission to access a particular feature or section of the system, that feature will be hidden from their view in the user interface. This helps to ensure that users only see the features and information that are relevant to their role, reducing clutter and improving usability. + +## Language Support + +The InvenTree user interface supports multiple languages, allowing users to interact with the system in their preferred language. + +The default system language can be configured by the system administrator in the [server configuration options](../start/config.md#basic-options). + +Additionally, users can select their preferred language in their [user settings](../settings/user.md), allowing them to override the system default language with their own choice. This provides a personalized experience for each user, ensuring that they can interact with the system in the language they are most comfortable with. diff --git a/src/frontend/src/components/calendar/Calendar.tsx b/src/frontend/src/components/calendar/Calendar.tsx index d93195d725..50f416a175 100644 --- a/src/frontend/src/components/calendar/Calendar.tsx +++ b/src/frontend/src/components/calendar/Calendar.tsx @@ -29,6 +29,10 @@ import { } from '@tabler/icons-react'; import { useCallback, useEffect, useMemo, useState } from 'react'; import { useShallow } from 'zustand/react/shallow'; +import { + defaultLocale, + getPriorityLocale +} from '../../contexts/LanguageContext'; import type { CalendarState } from '../../hooks/UseCalendar'; import { useLocalState } from '../../states/LocalState'; import { FilterSelectDrawer } from '../../tables/FilterSelectDrawer'; @@ -60,7 +64,19 @@ export default function Calendar({ const [locale] = useLocalState(useShallow((s) => [s.language])); // Ensure underscore is replaced with dash - const calendarLocale = useMemo(() => locale.replace('_', '-'), [locale]); + const calendarLocale = useMemo(() => { + let _locale: string | null = locale; + + if (!_locale) { + _locale = getPriorityLocale(); + } + + _locale = _locale || defaultLocale; + + _locale = _locale.replace('_', '-'); + + return _locale; + }, [locale]); const selectMonth = useCallback( (date: DateValue) => { diff --git a/src/frontend/src/components/items/LanguageSelect.tsx b/src/frontend/src/components/items/LanguageSelect.tsx index 6ef3cdfc0a..3650603670 100644 --- a/src/frontend/src/components/items/LanguageSelect.tsx +++ b/src/frontend/src/components/items/LanguageSelect.tsx @@ -1,8 +1,12 @@ import { Select } from '@mantine/core'; import { useEffect, useState } from 'react'; +import { t } from '@lingui/core/macro'; import { useShallow } from 'zustand/react/shallow'; -import { getSupportedLanguages } from '../../contexts/LanguageContext'; +import { + activateLocale, + getSupportedLanguages +} from '../../contexts/LanguageContext'; import { useLocalState } from '../../states/LocalState'; export function LanguageSelect({ width = 80 }: Readonly<{ width?: number }>) { @@ -28,13 +32,21 @@ export function LanguageSelect({ width = 80 }: Readonly<{ width?: number }>) { })); setLangOptions(newLangOptions); setValue(locale); + activateLocale(locale); // Ensure the locale is activated on component load }, [locale]); return (