Add support for locale_behavior: "respect_accept_language"
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 187
- Forks
- 80
- PR merge metrics
- No merged PRs in 30d
Description
Preflight checklist
- I could not find a solution in the existing issues, docs, nor discussions.
- I agree to follow this project's Code of Conduct.
- I have read and am following this repository's Contribution Guidelines.
- I have joined the Ory Community Slack.
- I am signed up to the Ory Security Patch Newsletter.
Ory Network Project
No response
Describe your problem
Currently, it seems like this mode is not supported, since there are no references to the "accept-language" header in the library.
In fact, it is not the key: project.default_locale which is used (as the name would perhaps suggest), but the intl.locale config key https://github.com/ory/elements/blob/795b1bda1f7236874fb7686f5fbf51237ff290a1/packages/elements-react/src/context/provider.tsx#L83.
Describe your ideal solution
I would expect the behaviour of the default OryProvider to interpret the "accept-language" header in "respect_accept_language" mode, and use that as the default application language, unless otherwise overridden in the config object.
I imagine that this would entail adding another function to "utils" which parses the header and possibly cross-references it with the project.enabled_locales array from config. Once this approach is approved, I'd be happy to open a PR.
Workarounds or alternatives
I was looking at using window.navigator.language as an alternative but this would mean that the config object would need to be rendered client-side.
Version
main 795b1bda1f7236874fb7686f5fbf51237ff290a1
Additional Context
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in packages/elements-react/src/context/provider.tsx around the intl.locale configuration and inspect the existing utils area for locale handling. Trace how the default OryProvider receives configuration, then define how accept-language should be parsed and matched against project.enabled_locales. Done means respect_accept_language selects that locale by default while an explicit config value still overrides it.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- react, typescript
- Domain
- frontend, internationalization
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100