-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow configuring available languages from helm chart (#2230)
Closes #2223 - [x] Adds `localesAvailable` to `/api/settings` endpoint, and uses that list if available, rather than the full list of translated locales, to determine which options to display to users - [x] ~~Uses the user's browser locales, filtered to the current language setting, for formatting numbers, dates, and durations~~ - [x] Adds & persists checkbox for "use same language for formatting dates and numbers" in user settings - [x] Replaces uses of `sl-format-bytes` with `localize.bytes(...)`, and `sl-format-date` with replacement `btrix-format-date` that properly handles fallback locales - [x] Caches all number/duration/datetime formatters by a combined key consisting of app language, browser language, browser setting, and formatter options so that all formatters can be reused if needed (previously any formatter with non-default options would be recreated every render) - [x] Splits out ordinal formatting from number formatter, as it didn't make much sense in some non-English locales - [x] Adds a little demo of date/time/duration/number formatting so you can see what effect your language settings have https://github.com/user-attachments/assets/724858cb-b140-4d72-a38d-83f602c71bc7 --------- Signed-off-by: emma <[email protected]> Co-authored-by: Ilya Kreymer <[email protected]> Co-authored-by: Ilya Kreymer <[email protected]>
- Loading branch information
1 parent
46aab91
commit b650762
Showing
46 changed files
with
704 additions
and
403 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import { localized } from "@lit/localize"; | ||
import { html, LitElement } from "lit"; | ||
import { customElement } from "lit/decorators/custom-element.js"; | ||
import { property } from "lit/decorators/property.js"; | ||
|
||
import { LocalizeController } from "@/controllers/localize"; | ||
|
||
/** | ||
* Re-implementation of Shoelace's `<sl-format-date>` element using | ||
* Browsertrix's localization implementation. | ||
* | ||
* This allows for multiple locales to be passed into the date formatter, in | ||
* order of the user's preferences. | ||
*/ | ||
@customElement("btrix-format-date") | ||
@localized() | ||
export class FormatDate extends LitElement { | ||
private readonly localize = new LocalizeController(this); | ||
|
||
/** | ||
* The date/time to format. If not set, the current date and time will be used. When passing a string, it's strongly | ||
* recommended to use the ISO 8601 format to ensure timezones are handled correctly. To convert a date to this format | ||
* in JavaScript, use [`date.toISOString()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString). | ||
*/ | ||
@property() date?: Date | string | null = new Date(); | ||
|
||
/** The format for displaying the weekday. */ | ||
@property() weekday?: "narrow" | "short" | "long"; | ||
|
||
/** The format for displaying the era. */ | ||
@property() era?: "narrow" | "short" | "long"; | ||
|
||
/** The format for displaying the year. */ | ||
@property() year?: "numeric" | "2-digit"; | ||
|
||
/** The format for displaying the month. */ | ||
@property() month?: "numeric" | "2-digit" | "narrow" | "short" | "long"; | ||
|
||
/** The format for displaying the day. */ | ||
@property() day?: "numeric" | "2-digit"; | ||
|
||
/** The format for displaying the hour. */ | ||
@property() hour?: "numeric" | "2-digit"; | ||
|
||
/** The format for displaying the minute. */ | ||
@property() minute?: "numeric" | "2-digit"; | ||
|
||
/** The format for displaying the second. */ | ||
@property() second?: "numeric" | "2-digit"; | ||
|
||
/** The format for displaying the time. */ | ||
@property({ attribute: "time-zone-name" }) timeZoneName?: "short" | "long"; | ||
|
||
/** The time zone to express the time in. */ | ||
@property({ attribute: "time-zone" }) timeZone?: string; | ||
|
||
/** The format for displaying the hour. */ | ||
@property({ attribute: "hour-format" }) hourFormat: "auto" | "12" | "24" = | ||
"auto"; | ||
|
||
render() { | ||
if (!this.date) return undefined; | ||
const date = new Date(this.date); | ||
const hour12 = | ||
this.hourFormat === "auto" ? undefined : this.hourFormat === "12"; | ||
|
||
// Check for an invalid date | ||
if (isNaN(date.getMilliseconds())) { | ||
return undefined; | ||
} | ||
|
||
return html` | ||
<time datetime=${date.toISOString()}> | ||
${this.localize.date(date, { | ||
weekday: this.weekday, | ||
era: this.era, | ||
year: this.year, | ||
month: this.month, | ||
day: this.day, | ||
hour: this.hour, | ||
minute: this.minute, | ||
second: this.second, | ||
timeZoneName: this.timeZoneName, | ||
timeZone: this.timeZone, | ||
hour12: hour12, | ||
})} | ||
</time> | ||
`; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.