mirror of
https://github.com/getpaseo/paseo.git
synced 2026-10-25 02:32:47 +00:00
fix: localize compact context percentage
This commit is contained in:
@@ -3,7 +3,7 @@ import Svg, { Circle } from "react-native-svg";
|
||||
import { StyleSheet, useUnistyles } from "react-native-unistyles";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
|
||||
import { formatTokenCount } from "./context-window-meter.utils";
|
||||
import { formatContextPercentage, formatTokenCount } from "./context-window-meter.utils";
|
||||
|
||||
interface ContextWindowMeterProps {
|
||||
maxTokens: number | null;
|
||||
@@ -99,7 +99,7 @@ export function ContextWindowMeter({
|
||||
glyphSize,
|
||||
}: ContextWindowMeterProps) {
|
||||
const { theme } = useUnistyles();
|
||||
const { t } = useTranslation();
|
||||
const { t, i18n } = useTranslation();
|
||||
const percentage =
|
||||
maxTokens !== null && usedTokens !== null ? getUsagePercentage(maxTokens, usedTokens) : null;
|
||||
const geometry = getMeterGeometry(showPercentage, glyphSize);
|
||||
@@ -183,7 +183,9 @@ export function ContextWindowMeter({
|
||||
/>
|
||||
</Svg>
|
||||
{showPercentage ? (
|
||||
<Text style={styles.percentageLabel}>{`${roundedPercentage}%`}</Text>
|
||||
<Text style={styles.percentageLabel}>
|
||||
{formatContextPercentage(roundedPercentage, i18n.resolvedLanguage)}
|
||||
</Text>
|
||||
) : null}
|
||||
</Pressable>
|
||||
</TooltipTrigger>
|
||||
|
||||
@@ -7,3 +7,10 @@ export function formatTokenCount(value: number): string {
|
||||
}
|
||||
return Math.round(value).toString();
|
||||
}
|
||||
|
||||
export function formatContextPercentage(value: number, locale?: string): string {
|
||||
return new Intl.NumberFormat(locale, {
|
||||
style: "percent",
|
||||
maximumFractionDigits: 0,
|
||||
}).format(Math.max(0, Math.min(100, value)) / 100);
|
||||
}
|
||||
|
||||
@@ -36,4 +36,8 @@ describe("formatAmount", () => {
|
||||
expect(formatRunsOutLabel(twoHoursFromNow, NOW)).toBe("2時間後に上限に到達");
|
||||
expect(formatAgo(threeDaysAgo, NOW)).toBe("3日前");
|
||||
});
|
||||
|
||||
it("formats percentages with locale-specific spacing", () => {
|
||||
expect(formatPct(42, "fr")).toBe("42\u00a0%");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user