Merge pull request #411 from danditomaso/issue-399-wrong-measurement-unit-in-map
feat: adding pluralizer util. fix: measurement unit in marker popup
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import { Separator } from "@app/components/UI/Seperator";
|
import { Separator } from "@app/components/UI/Seperator";
|
||||||
import { H5 } from "@app/components/UI/Typography/H5.tsx";
|
import { H5 } from "@app/components/UI/Typography/H5.tsx";
|
||||||
import { Subtle } from "@app/components/UI/Typography/Subtle.tsx";
|
import { Subtle } from "@app/components/UI/Typography/Subtle.tsx";
|
||||||
|
import { formatQuantity } from "@app/core/utils/string";
|
||||||
import { Avatar } from "@components/UI/Avatar";
|
import { Avatar } from "@components/UI/Avatar";
|
||||||
import { Mono } from "@components/generic/Mono.tsx";
|
import { Mono } from "@components/generic/Mono.tsx";
|
||||||
import { TimeAgo } from "@components/generic/Table/tmp/TimeAgo.tsx";
|
import { TimeAgo } from "@components/generic/Table/tmp/TimeAgo.tsx";
|
||||||
@@ -132,7 +133,12 @@ export const NodeDetail = ({ node }: NodeDetailProps) => {
|
|||||||
className="ml-2 mr-1"
|
className="ml-2 mr-1"
|
||||||
aria-label="Elevation"
|
aria-label="Elevation"
|
||||||
/>
|
/>
|
||||||
<div>{node.position?.altitude} ft</div>
|
<div>
|
||||||
|
{formatQuantity(node.position?.altitude, {
|
||||||
|
one: "meter",
|
||||||
|
other: "meters",
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
interface PluralForms {
|
||||||
|
one: string;
|
||||||
|
other: string;
|
||||||
|
[key: string]: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface FormatOptions {
|
||||||
|
locale?: string;
|
||||||
|
pluralRules?: Intl.PluralRulesOptions;
|
||||||
|
numberFormat?: Intl.NumberFormatOptions;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function formatQuantity(
|
||||||
|
value: number,
|
||||||
|
forms: PluralForms,
|
||||||
|
options: FormatOptions = {},
|
||||||
|
) {
|
||||||
|
const {
|
||||||
|
locale = "en-US",
|
||||||
|
pluralRules: pluralOptions = { type: "cardinal" },
|
||||||
|
numberFormat: numberOptions = {},
|
||||||
|
} = options;
|
||||||
|
|
||||||
|
const pluralRules = new Intl.PluralRules(locale, pluralOptions);
|
||||||
|
const numberFormat = new Intl.NumberFormat(locale, numberOptions);
|
||||||
|
|
||||||
|
const pluralCategory = pluralRules.select(value);
|
||||||
|
const word = forms[pluralCategory];
|
||||||
|
|
||||||
|
return `${numberFormat.format(value)} ${word}`;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user