[UI] Default locale#11412
Conversation
✅ Deploy Preview for inventree-web-pui-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
Pull request overview
This PR aims to ensure the frontend language defaults to the server’s configured default_locale when the user has not explicitly chosen a language, and adds a “Default Language” option in the user profile language selector.
Changes:
- Allow
languageto benullin local state to represent “use default language”. - Add locale-priority logic and more defensive locale activation/loading.
- Add “Default Language” option to the language dropdown and document language support.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| src/frontend/src/states/LocalState.tsx | Changes language state to string | null with null as the default. |
| src/frontend/src/contexts/ThemeContext.tsx | Wraps Mantine theme creation in a try/catch and falls back to default theme on errors. |
| src/frontend/src/contexts/LanguageContext.tsx | Introduces locale prioritization and updates locale activation logic. |
| src/frontend/src/components/items/LanguageSelect.tsx | Adds a “Default Language” option to the language selector UI. |
| docs/docs/concepts/user_interface.md | Adds language support documentation section. |
Comments suppressed due to low confidence (1)
src/frontend/src/contexts/LanguageContext.tsx:106
- This effect computes
langaslanguage || defaultLocaleand only re-runs whenlanguagechanges. As a result, when server info loads later, the serverdefault_localeis not used as the initial UI locale (and the Accept-Language header logic below will not re-run to include the server locale). Computelangusing the documented priority (user language -> server.default_locale -> defaultLocale) and includeserver.default_localein the dependency list so changes are honored.
let lang: string = language || defaultLocale;
// Ensure that the selected language is supported
if (!Object.keys(getSupportedLanguages()).includes(lang)) {
lang = defaultLocale;
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| return ( | ||
| <Select | ||
| w={width} | ||
| data={langOptions} | ||
| data={[ | ||
| { | ||
| value: '', | ||
| label: t`Default Language` | ||
| }, | ||
| ...langOptions | ||
| ]} | ||
| value={value} | ||
| defaultValue={''} | ||
| onChange={setValue} |
There was a problem hiding this comment.
The select is controlled via value={value}, but when the stored locale is null you call setValue(locale) which leaves the control with null (no option selected). That means the new "Default Language" option (value '') is never shown as selected, and defaultValue has no effect in controlled mode. Consider controlling the select with value={locale ?? ''} and converting '' -> null in onChange so the UI reflects the default-language state.
| } | ||
|
|
||
| if (locale != activeLocale) { | ||
| console.info('Changing locale from', activeLocale, 'to', locale); |
There was a problem hiding this comment.
This adds a new console.info log on every locale change. There are no other console.info calls in the frontend, so this will create noisy production logs. Consider removing it or gating it behind a debug flag.
| console.info('Changing locale from', activeLocale, 'to', locale); |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #11412 +/- ##
==========================================
- Coverage 87.99% 87.99% -0.01%
==========================================
Files 1295 1295
Lines 58806 58801 -5
Branches 1939 1939
==========================================
- Hits 51745 51740 -5
Misses 6579 6579
Partials 482 482
🚀 New features to boost your workflow:
|
* [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

As part of the investigation for #11408 I discovered that the server default locale is not honored in the user interface.
This PR adds the following: