inventree / InvenTree

Open Source Inventory Management System
https://docs.inventree.org
MIT License
4.32k stars 781 forks source link

Default language is overwriten by browser language settings #7528

Open NightSkySK opened 4 months ago

NightSkySK commented 4 months ago

Please verify that this bug has NOT been raised before.

Describe the bug*

in Inventree config file /etc/inventree/config.yaml I've applied language setting:

# Select default system language (default is 'en-us')
# Use the environment variable INVENTREE_LANGUAGE
language: en-us

How ever once I launch Inventree it's set up language to Polish by default: image

Even if I save the setting for my account to English it return back to Polish after some time. Also language setting seems to not be stored in account setting as in new browser it display all in Polish as well.

Steps to Reproduce

  1. Use browser with primary language different than english
  2. Set up config.yaml language: en-us
  3. Open inventree app and check UI language displayed

Expected behaviour

  1. config.yaml should have higher priority than browser language settings
  2. If user decide to use different language the setting should be stored within account settings and all browsers and app (including mobile app ) should launch with the same language version

Deployment Method

Version Information

Version Information:

InvenTree-Version: 0.15.4 Django Version: 4.2.12

Database: postgresql Debug-Mode: False Deployed using Docker: False Platform: Linux-5.4.0-186-generic-x86_64-with-glibc2.31 Installer: None

Active plugins: [{'name': 'InvenTreeBarcode', 'slug': 'inventreebarcode', 'version': '2.0.0'}, {'name': 'InvenTreeCoreNotificationsPlugin', 'slug': 'inventreecorenotificationsplugin', 'version': '1.0.0'}, {'name': 'InvenTreeCurrencyExchange', 'slug': 'inventreecurrencyexchange', 'version': '1.0.0'}, {'name': 'InvenTreeLabel', 'slug': 'inventreelabel', 'version': '1.0.0'}, {'name': 'InvenTreeLabelMachine', 'slug': 'inventreelabelmachine', 'version': '1.0.0'}, {'name': 'InvenTreeLabelSheet', 'slug': 'inventreelabelsheet', 'version': '1.0.0'}, {'name': 'DigiKeyPlugin', 'slug': 'digikeyplugin', 'version': '1.0.0'}, {'name': 'LCSCPlugin', 'slug': 'lcscplugin', 'version': '1.0.0'}, {'name': 'MouserPlugin', 'slug': 'mouserplugin', 'version': '1.0.0'}, {'name': 'TMEPlugin', 'slug': 'tmeplugin', 'version': '1.0.0'}, {'name': 'Zebra', 'slug': 'zebra', 'version': '0.6.0'}, {'name': 'KiCadLibraryPlugin', 'slug': 'kicad-library-plugin', 'version': '1.4.2'}]

Please verify if you can reproduce this bug on the demo site.

Relevant log output

No response

SchrodingersGat commented 4 months ago

If your browser is requesting the page in polish, this is what the server will return. The "default" language selection is intended as a back-stop after other language selection priorities are exhausted.

From the django documentation:

LocaleMiddleware tries to determine the user’s language preference by following this algorithm:

- First, it looks for the language prefix in the requested URL. This is only performed when you are using the i18n_patterns function in your root URLconf. See [Internationalization: in URL patterns](https://docs.djangoproject.com/en/4.2/topics/i18n/translation/#url-internationalization) for more information about the language prefix and how to internationalize URL patterns.
- Failing that, it looks for a cookie. The name of the cookie used is set by the [LANGUAGE_COOKIE_NAME](https://docs.djangoproject.com/en/4.2/ref/settings/#std-setting-LANGUAGE_COOKIE_NAME) setting. (The default name is django_language.)
- Failing that, it looks at the Accept-Language HTTP header. This header is sent by your browser and tells the server which language(s) you prefer, in order by priority. Django tries each language in the header until it finds one with available translations.
- Failing that, it uses the global [LANGUAGE_CODE](https://docs.djangoproject.com/en/4.2/ref/settings/#std-setting-LANGUAGE_CODE) setting.
NightSkySK commented 4 months ago

OK, I understand it's not a bug in this case. Can it be "feature-request" to store user preferred language in user settings? in this case login page would be still based on "language selection priorities" mentioned above, but once user successfully login it would switch to the preferred language/language which he was using during last session, etc.

SchrodingersGat commented 4 months ago

@NightSkySK this is possible with the new user interface, but likely not with the current "legacy" interface.

github-actions[bot] commented 2 months ago

This issue seems stale. Please react to show this is still important.