fix(i18n): numbers, units, dates and order in the UI language, and after a switch (E30 S3)
Every locale formatter takes the language as an argument. Under the React
Compiler a formatter that read the i18n singleton was memoized on its other
arguments, so a card kept "2 hr 4 min" after a switch to Hungarian; plexLang()
had the same flaw and left Plex queries in the old language. Components now
take the language from useTranslation, and the signature makes forgetting it
a type error.
- ratings, file sizes, stream stats: the language's decimal mark ("8,3")
- view and subscriber counts compact in the language ("1,2 E")
- seconds as the language's unit ("6 mp") in the sliders and the stats
- a person's birth and death dates as dates, not ISO strings
- A-Z lists by the shown name in the language's alphabet (compareText),
the tag catalog re-sorted by its translated names
- lint local/locale-format (was date-format) also refuses Intl.NumberFormat
outside lib/format.ts, localeCompare, and a component reading the language
off the i18n singleton
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
// chips can label a sort without re-deriving the mapping.
|
||||
import type { Video } from "./api";
|
||||
import type { SortOption } from "./columnSort";
|
||||
import { compareText } from "./collate";
|
||||
|
||||
export type SortKey =
|
||||
| "date"
|
||||
@@ -100,7 +101,12 @@ const YT_SORT_VALUE: Partial<Record<SortKey, (v: Video) => number | string | nul
|
||||
* Results missing the value sink to the END in both directions (a video whose duration YouTube did
|
||||
* not report is not "the shortest"), and ties keep the provider's ranking, in both directions —
|
||||
* hence a signed comparator rather than sorting and reversing, which would flip the ties too. */
|
||||
export function sortYtResults(items: Video[], key: SortKey, dir: "asc" | "desc"): Video[] {
|
||||
export function sortYtResults(
|
||||
items: Video[],
|
||||
key: SortKey,
|
||||
dir: "asc" | "desc",
|
||||
lang: string,
|
||||
): Video[] {
|
||||
const value = YT_SORT_VALUE[key];
|
||||
if (!value) return items; // relevance, and anything a stale pref names that we no longer offer
|
||||
const sign = dir === "asc" ? 1 : -1;
|
||||
@@ -109,7 +115,7 @@ export function sortYtResults(items: Video[], key: SortKey, dir: "asc" | "desc")
|
||||
have.sort((a, b) => {
|
||||
const x = value(a)!;
|
||||
const y = value(b)!;
|
||||
return sign * (typeof x === "string" ? x.localeCompare(String(y)) : x - Number(y));
|
||||
return sign * (typeof x === "string" ? compareText(x, String(y), lang) : x - Number(y));
|
||||
});
|
||||
return [...have, ...missing];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user