System wide default language detection via browser language header #1124

Closed
opened 2026-04-05 18:19:27 +02:00 by MrUnknownDE · 0 comments
Owner

Originally created by @Pallavikumarimdb on 8/3/2025

Community Contribution License Agreement

By creating this pull request, I grant the project maintainers an unlimited,
perpetual license to use, modify, and redistribute these contributions under any terms they
choose, including both the AGPLv3 and the Fossorial Commercial license terms. I
represent that I have the right to grant this license for all contributed content.

Description

This PR adds support for detecting a user's preferred language from their browser settings (Accept-Language header) and falling back to a predefined default (en-US) when not available. The flow works as follows:

  1. If a cookie exists and its value matches one of the app-supported locales (/i18n/config.ts), it is used.

  2. If not, the Accept-Language header from the browser is parsed.
    We extract the base language (e.g., fr from fr-FR).
    We try to match it against available locales by comparing prefixes.

  3. If no match is found, the app falls back to the default locale: 'en-US'.

Fixes #1131

How to test?

  1. Open your browser settings and change the preferred language to something like French.
  2. Make sure the NEXT_LOCALE cookie is not set by clearing cookies or using an incognito/private window.
  3. Visit the app in a new tab or incognito window.
  4. Set your browser to a language not included in the app’s locales. The application should fallback to en-US.
  5. Cookie Override Test: If NEXT_LOCALE cookie is set (e.g., via language switcher), it should take priority over browser settings on the next visit.
*Originally created by @Pallavikumarimdb on 8/3/2025* ## Community Contribution License Agreement By creating this pull request, I grant the project maintainers an unlimited, perpetual license to use, modify, and redistribute these contributions under any terms they choose, including both the AGPLv3 and the Fossorial Commercial license terms. I represent that I have the right to grant this license for all contributed content. ## Description This PR adds support for detecting a user's preferred language from their browser settings (Accept-Language header) and falling back to a predefined default (en-US) when not available. The flow works as follows: 1. If a cookie exists and its value matches one of the app-supported locales (/i18n/config.ts), it is used. 2. If not, the Accept-Language header from the browser is parsed. We extract the base language (e.g., fr from fr-FR). We try to match it against available locales by comparing prefixes. 3. If no match is found, the app falls back to the default locale: 'en-US'. Fixes #1131 ## How to test? 1. Open your browser settings and change the preferred language to something like French. 2. Make sure the NEXT_LOCALE cookie is not set by clearing cookies or using an incognito/private window. 3. Visit the app in a new tab or incognito window. 5. Set your browser to a language not included in the app’s locales. The application should fallback to en-US. 6. Cookie Override Test: If NEXT_LOCALE cookie is set (e.g., via language switcher), it should take priority over browser settings on the next visit.
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github/pangolin#1124