-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
web: 2025.12 RC2 UI feedback #19229
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
web: 2025.12 RC2 UI feedback #19229
Changes from 13 commits
9966cfe
0bdd975
fb2355b
bbdf9df
464b4d2
efca157
b6c559c
617eaf1
400c0f5
c6d94e9
a7ebd6d
429da72
024def4
ade5661
e759d0d
61f42de
8a64762
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,8 +9,6 @@ import { | |
| import { safeParseLocale } from "#common/ui/locale/utils"; | ||
|
|
||
| import { msg, str } from "@lit/localize"; | ||
| import { html } from "lit"; | ||
| import { repeat } from "lit/directives/repeat.js"; | ||
|
|
||
| /** | ||
| * Safely get a minimized locale ID, with fallback for older browsers. | ||
|
|
@@ -198,34 +196,41 @@ export function formatLocaleDisplayNames( | |
| return entries.sort(createIntlCollator(activeLocaleTag, collatorOptions)); | ||
| } | ||
|
|
||
| export function renderLocaleDisplayNames( | ||
| entries: LocaleDisplay[], | ||
| activeLocaleTag: TargetLanguageTag | null, | ||
| export function formatRelativeLocaleDisplayName( | ||
| languageTag: TargetLanguageTag, | ||
| localizedDisplayName: string, | ||
| relativeDisplayName: string, | ||
| ) { | ||
|
Comment on lines
-201
to
203
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Split the render function from the formatter logic to re-use in the locale stage prompt component. |
||
| return repeat( | ||
| entries, | ||
| ([languageTag]) => languageTag, | ||
| ([languageTag, localizedDisplayName, relativeDisplayName]) => { | ||
| const pseudo = languageTag === PseudoLanguageTag; | ||
|
|
||
| const same = | ||
| relativeDisplayName && | ||
| normalizeDisplayName(relativeDisplayName) === | ||
| normalizeDisplayName(localizedDisplayName); | ||
|
|
||
| let localizedMessage = localizedDisplayName; | ||
|
|
||
| if (!same && !pseudo) { | ||
| localizedMessage = msg(str`${relativeDisplayName} (${localizedDisplayName})`, { | ||
| id: "locale-option-localized-label", | ||
| desc: "Locale option label showing the localized language name along with the native language name in parentheses.", | ||
| }); | ||
| } | ||
| const pseudo = languageTag === PseudoLanguageTag; | ||
|
|
||
| const same = | ||
| relativeDisplayName && | ||
| normalizeDisplayName(relativeDisplayName) === normalizeDisplayName(localizedDisplayName); | ||
|
|
||
| if (same || pseudo) { | ||
| return localizedDisplayName; | ||
| } | ||
|
|
||
| return msg(str`${relativeDisplayName} (${localizedDisplayName})`, { | ||
| id: "locale-option-localized-label", | ||
| desc: "Locale option label showing the localized language name along with the native language name in parentheses.", | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Format the display name for the auto-detect locale option. | ||
| * | ||
| * @param detectedLocale The detected locale display, if any. | ||
| */ | ||
| export function formatAutoDetectLocaleDisplayName(detectedLocale?: LocaleDisplay | null) { | ||
| const prefix = msg("Auto-detect", { | ||
| id: "locale-auto-detect-option", | ||
| desc: "Label for the auto-detect locale option in language selection dropdown", | ||
| }); | ||
|
|
||
| if (!detectedLocale) { | ||
| return prefix; | ||
| } | ||
|
|
||
| return html`${pseudo ? html`<hr />` : null} | ||
| <option value=${languageTag} ?selected=${languageTag === activeLocaleTag}> | ||
| ${localizedMessage} | ||
| </option>`; | ||
| }, | ||
| ); | ||
| return `${prefix} (${formatRelativeLocaleDisplayName(...detectedLocale)})`; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -157,8 +157,8 @@ export function getSessionLocale(): string | null { | |
| /** | ||
| * Auto-detect the best locale to use from several sources. | ||
| * | ||
| * @param localeHint An optional locale code hint. | ||
| * @param fallbackLocaleCode An optional fallback locale code. | ||
| * @param languageTagHint An optional locale code hint. | ||
| * @param fallbackLanguageTag An optional fallback locale code. | ||
|
Comment on lines
-160
to
+161
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consistent usage of "language tag" (a string) vs locale (a JavaScript |
||
| * @returns The best-matching supported locale code. | ||
| * | ||
| * @remarks | ||
|
|
@@ -172,8 +172,8 @@ export function getSessionLocale(): string | null { | |
| * 6. The source locale (English) | ||
| */ | ||
| export function autoDetectLanguage( | ||
| localeHint?: string, | ||
| fallbackLocaleCode?: string, | ||
| languageTagHint?: Intl.UnicodeBCP47LocaleIdentifier, | ||
| fallbackLanguageTag?: Intl.UnicodeBCP47LocaleIdentifier, | ||
| ): TargetLanguageTag { | ||
| let localeParam: string | null = null; | ||
|
|
||
|
|
@@ -188,18 +188,18 @@ export function autoDetectLanguage( | |
| const candidates = [ | ||
| localeParam, | ||
| sessionLocale, | ||
| localeHint, | ||
| self.navigator?.language, | ||
| fallbackLocaleCode, | ||
| languageTagHint, | ||
| ...(self.navigator?.languages || []), | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| fallbackLanguageTag, | ||
| ].filter((item): item is string => !!item); | ||
|
|
||
| const firstSupportedLocale = findSupportedLocale(candidates); | ||
|
|
||
| if (!firstSupportedLocale) { | ||
| console.debug(`authentik/locale: Falling back to source locale`, { | ||
| SourceLanguageTag, | ||
| localeHint, | ||
| fallbackLocaleCode, | ||
| languageTagHint, | ||
| fallbackLanguageTag, | ||
| candidates, | ||
| }); | ||
|
|
||
|
|
@@ -208,3 +208,28 @@ export function autoDetectLanguage( | |
|
|
||
| return firstSupportedLocale; | ||
| } | ||
|
|
||
| /** | ||
| * Given a locale code, format it for use in an `Accept-Language` header. | ||
| */ | ||
| export function formatAcceptLanguageHeader(languageTag: Intl.UnicodeBCP47LocaleIdentifier): string { | ||
| const [preferredLanguageTag, ...languageTags] = new Set([ | ||
| languageTag, | ||
| ...(self.navigator?.languages || []), | ||
| SourceLanguageTag, | ||
| "*", | ||
| ]); | ||
|
|
||
| const fallbackCount = languageTags.length; | ||
|
|
||
| return [ | ||
| preferredLanguageTag, | ||
| ...languageTags.map((tag, idx) => { | ||
| const weight = ((fallbackCount - idx) / (fallbackCount + 1)).toFixed( | ||
| fallbackCount > 9 ? 2 : 1, | ||
| ); | ||
|
|
||
| return `${tag};q=${weight}`; | ||
| }), | ||
| ].join(", "); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
e.g.