Skip to content

[UI] Default locale#11412

Merged
SchrodingersGat merged 9 commits intoinventree:masterfrom
SchrodingersGat:default-locale
Feb 24, 2026
Merged

[UI] Default locale#11412
SchrodingersGat merged 9 commits intoinventree:masterfrom
SchrodingersGat:default-locale

Conversation

@SchrodingersGat
Copy link
Member

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:

  • Ensure that the UI language initially defaults to the server "default locale" setting
  • Add a user profile option to select "default language"

@netlify
Copy link

netlify bot commented Feb 23, 2026

Deploy Preview for inventree-web-pui-preview ready!

Name Link
🔨 Latest commit e9a3563
🔍 Latest deploy log https://app.netlify.com/projects/inventree-web-pui-preview/deploys/699d146fbc897e0008ea9822
😎 Deploy Preview https://deploy-preview-11412--inventree-web-pui-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 93 (🟢 up 1 from production)
Accessibility: 81 (no change from production)
Best Practices: 100 (no change from production)
SEO: 78 (no change from production)
PWA: -
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify project configuration.

@SchrodingersGat SchrodingersGat added bug Identifies a bug which needs to be addressed translation User Interface Related to the frontend / User Interface labels Feb 23, 2026
@SchrodingersGat SchrodingersGat added this to the 1.3.0 milestone Feb 23, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 language to be null in 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 lang as language || defaultLocale and only re-runs when language changes. As a result, when server info loads later, the server default_locale is not used as the initial UI locale (and the Accept-Language header logic below will not re-run to include the server locale). Compute lang using the documented priority (user language -> server.default_locale -> defaultLocale) and include server.default_locale in 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.

Comment on lines 38 to 50
return (
<Select
w={width}
data={langOptions}
data={[
{
value: '',
label: t`Default Language`
},
...langOptions
]}
value={value}
defaultValue={''}
onChange={setValue}
Copy link

Copilot AI Feb 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
}

if (locale != activeLocale) {
console.info('Changing locale from', activeLocale, 'to', locale);
Copy link

Copilot AI Feb 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
console.info('Changing locale from', activeLocale, 'to', locale);

Copilot uses AI. Check for mistakes.
Copy link
Member

@matmair matmair left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@SchrodingersGat SchrodingersGat merged commit 8a4ad4f into inventree:master Feb 24, 2026
42 of 43 checks passed
@SchrodingersGat SchrodingersGat deleted the default-locale branch February 24, 2026 05:08
@codecov
Copy link

codecov bot commented Feb 24, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.99%. Comparing base (edc639d) to head (e9a3563).
⚠️ Report is 5 commits behind head on master.

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              
Components Coverage Δ
Backend Apps 91.69% <ø> (ø)
Backend General 93.37% <ø> (ø)
Frontend 70.83% <ø> (-0.02%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

jmerro-c3d pushed a commit to jmerro-c3d/InvenTree that referenced this pull request Feb 25, 2026
* [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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Identifies a bug which needs to be addressed translation User Interface Related to the frontend / User Interface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants