Pass full locale from Accept-Language to ClientDate
Add detectLocale() that extracts the full locale tag (e.g. "de-DE") from the request, not just the language. The journal root loader passes it via LocaleContext so ClientDate renders with the correct locale on both server and client — no more hardcoded "en-US" fallback. Also fixes settings page hydration mismatch by using ClientDate for passkey creation dates instead of inline toLocaleDateString(). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
79f000fcc5
commit
38ada3bd4f
5 changed files with 54 additions and 9 deletions
|
|
@ -70,4 +70,23 @@ export function detectLanguage(request: Request): SupportedLng {
|
|||
return "en";
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract the full locale (e.g. "de-DE") from a request's Accept-Language header.
|
||||
* Falls back to the supported language (e.g. "en") if no region tag is present.
|
||||
*/
|
||||
export function detectLocale(request: Request): string {
|
||||
const header = request.headers.get("Accept-Language") ?? "";
|
||||
for (const part of header.split(",")) {
|
||||
const tag = part.split(";")[0]?.trim();
|
||||
if (!tag) continue;
|
||||
const lang = tag.toLowerCase();
|
||||
for (const supported of supportedLngs) {
|
||||
if (lang === supported || lang.startsWith(supported + "-")) {
|
||||
return tag; // preserve original casing (e.g. "de-DE")
|
||||
}
|
||||
}
|
||||
}
|
||||
return "en";
|
||||
}
|
||||
|
||||
export { i18n };
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue