Normalize i18n() calls to prepare for ICU migration

This commit is contained in:
Jamie Kyle 2023-03-28 11:26:46 -07:00 committed by GitHub
parent 7c8e7c1013
commit c02c8d9640
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 377 additions and 273 deletions

View file

@ -21,9 +21,11 @@ export type PropsType = Readonly<{
onClose: () => void;
}>;
const UNITS = ['seconds', 'minutes', 'hours', 'days', 'weeks'];
const UNITS = ['seconds', 'minutes', 'hours', 'days', 'weeks'] as const;
const UNIT_TO_SEC = new Map<string, number>([
export type Unit = typeof UNITS[number];
const UNIT_TO_SEC = new Map<Unit, number>([
['seconds', 1],
['minutes', 60],
['hours', 60 * 60],
@ -31,7 +33,7 @@ const UNIT_TO_SEC = new Map<string, number>([
['weeks', 7 * 24 * 60 * 60],
]);
const RANGES = new Map<string, [number, number]>([
const RANGES = new Map<Unit, [number, number]>([
['seconds', [1, 60]],
['minutes', [1, 60]],
['hours', [1, 24]],
@ -48,7 +50,7 @@ export function DisappearingTimeDialog(props: PropsType): JSX.Element {
onClose,
} = props;
let initialUnit = 'seconds';
let initialUnit: Unit = 'seconds';
let initialUnitValue = 1;
for (const unit of UNITS) {
const sec = UNIT_TO_SEC.get(unit) || 1;
@ -62,7 +64,7 @@ export function DisappearingTimeDialog(props: PropsType): JSX.Element {
}
const [unitValue, setUnitValue] = useState(initialUnitValue);
const [unit, setUnit] = useState(initialUnit);
const [unit, setUnit] = useState<Unit>(initialUnit);
const range = RANGES.get(unit) || [1, 1];
@ -108,9 +110,9 @@ export function DisappearingTimeDialog(props: PropsType): JSX.Element {
moduleClassName={`${CSS_MODULE}__time-boxes__units`}
value={unit}
onChange={newUnit => {
setUnit(newUnit);
setUnit(newUnit as Unit);
const ranges = RANGES.get(newUnit);
const ranges = RANGES.get(newUnit as Unit);
if (!ranges) {
return;
}
@ -121,7 +123,13 @@ export function DisappearingTimeDialog(props: PropsType): JSX.Element {
options={UNITS.map(unitName => {
return {
value: unitName,
text: i18n(`DisappearingTimeDialog__${unitName}`),
text: {
seconds: i18n('DisappearingTimeDialog__seconds'),
minutes: i18n('DisappearingTimeDialog__minutes'),
hours: i18n('DisappearingTimeDialog__hours'),
days: i18n('DisappearingTimeDialog__days'),
weeks: i18n('DisappearingTimeDialog__weeks'),
}[unitName],
};
})}
/>