ory / ory/elements

Add support for locale_behavior: "respect_accept_language"

Open
#591 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Needs Triage
Dominant language
TypeScript
Stars
187
Forks
80
PR merge metrics
No merged PRs in 30d

Description

Preflight checklist
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.