Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve locale browser detection by following RFC 2616 #5272

merged 4 commits into from Jul 25, 2019


Copy link

commented Jul 17, 2019

馃帺 What? Why?

The default language detected by Decidim does not always work as expected and does not respect organization defaults.

This PR does:

  1. Solves a bug detecting the browser's language from the Accept-Language header. Previously only worked when it had only 2 chars and nothing else. Now follows RFC 2616 taking quality values into account. This means that values like es,en-US;q=0.8,ca;q=0.5,en;q=0.3 are correctly handled.
  2. Uses the organization default_locale and available_locales methods instead of the ones in the Decidim core class. This allows a consistent behavior according the configured value in the admin. This is specially useful for tenants with very different languages and defaults.
  3. Respond in a more useful way the default locale if the browser asks for a language variant (this is not RFC 2116 compliant). For instance, if ca-ES is requested it should return ca if available. Also the other way around, if the user requests pt should return pt-BR before the default if available.
  4. Introduces tests to check the expected behaviors.

馃搶 Related Issues

馃搵 Subtasks

  • Add CHANGELOG entry
  • Add documentation regarding the feature
  • Add/modify seeds
  • Add tests
  • Another subtask
@microstudi microstudi requested a review from decidim/lot-core as a code owner Jul 17, 2019
microstudi added 2 commits Jul 17, 2019
@oriolgual oriolgual merged commit 6635a15 into decidim:master Jul 25, 2019
0 of 3 checks passed
0 of 3 checks passed
ci/circleci: build_test_app CircleCI is running your tests
ci/circleci: main CircleCI is running your tests
codeclimate Code Climate is analyzing this code.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
2 participants
You can鈥檛 perform that action at this time.