Skip to content

Commit 443e4c4

Browse files
fix(web): ZIP member sizes use the app language's decimal separator (#48167)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
1 parent e1b810e commit 443e4c4

28 files changed

Lines changed: 182 additions & 55 deletions

‎apps/mobile/src/components/ComposerContextSheet.tsx‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import type {
1313
ScopedThreadRef,
1414
} from "@t3tools/contracts";
1515
import { formatAttachmentSize } from "@t3tools/client-runtime/state/attachments";
16+
import { useFormattingLocale } from "../i18n/formattingLocale";
1617
import { sourceControlClients } from "@t3tools/client-runtime/source-control-clients";
1718
import { changeRequestTermKind } from "../lib/changeRequestTerm";
1819
import { videoMimeType } from "@t3tools/shared/video";
@@ -117,6 +118,7 @@ export function ComposerContextSheet(props: {
117118
});
118119
const gt = useGT();
119120
const messages = useMessages();
121+
const locale = useFormattingLocale();
120122
const reviewColors = useReviewCommentColors();
121123
const insets = useSafeAreaInsets();
122124
const { themeId, themeAppearance } = useAppearancePreferences();
@@ -376,7 +378,7 @@ export function ComposerContextSheet(props: {
376378
{record.kind === "image" ? (
377379
<ContextField
378380
label={gt({ context: "noun" })`File`}
379-
value={`${record.mimeType} · ${formatAttachmentSize(record.sizeBytes, messages)}`}
381+
value={`${record.mimeType} · ${formatAttachmentSize(record.sizeBytes, messages, locale)}`}
380382
/>
381383
) : null}
382384
{record.kind === "mention" ? (

‎apps/mobile/src/features/files/AttachmentFileScreen.tsx‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
clampFileAttachmentUploadBytes,
66
formatAttachmentSize,
77
} from "@t3tools/client-runtime/state/attachments";
8+
import { useFormattingLocale } from "../../i18n/formattingLocale";
89
import { msg, useGT, useMessages } from "gt-react-native";
910
import { useRef, useState } from "react";
1011
import { View } from "react-native";
@@ -41,6 +42,7 @@ export function AttachmentFileScreen(props: AttachmentFileScreenProps) {
4142
const navigation = useNavigation();
4243
const gt = useGT();
4344
const messages = useMessages();
45+
const locale = useFormattingLocale();
4446
const { appearance, setCodeWordBreak } = useAppearancePreferences();
4547
const params = props.route.params;
4648
const environmentId = params.environmentId?.trim()
@@ -219,8 +221,8 @@ export function AttachmentFileScreen(props: AttachmentFileScreenProps) {
219221
const subtitle =
220222
sizeBytes > 0
221223
? draftKey
222-
? gt`Draft attachment · ${{ size: formatAttachmentSize(sizeBytes, messages) }}`
223-
: gt`Attachment · ${{ size: formatAttachmentSize(sizeBytes, messages) }}`
224+
? gt`Draft attachment · ${{ size: formatAttachmentSize(sizeBytes, messages, locale) }}`
225+
: gt`Attachment · ${{ size: formatAttachmentSize(sizeBytes, messages, locale) }}`
224226
: draftKey
225227
? gt`Draft attachment`
226228
: gt`Attachment`;

‎apps/mobile/src/features/files/ZipArchiveView.test.tsx‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ import { ZipArchiveView } from "./ZipArchiveView";
156156
import { AttachmentFileScreen } from "./AttachmentFileScreen";
157157
import { appAtomRegistry } from "../../state/atom-registry";
158158
import { composerDraftsAtom } from "../../state/use-composer-drafts";
159+
import { FormattingLocaleContext } from "../../i18n/formattingLocale";
159160

160161
function setup() {
161162
vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
@@ -300,6 +301,20 @@ it("asks for a password before browsing encrypted entries", async () => {
300301
expect(screen.container.querySelector('[aria-label="first.txt"]')).toBeNull();
301302
});
302303

304+
it("shows the browse limit in the app's formatting locale", async () => {
305+
const screen = setup();
306+
await act(async () =>
307+
screen.root.render(
308+
<FormattingLocaleContext value="de">
309+
<ZipArchiveView {...screen.props} sizeBytes={51 * 1024 * 1024} />
310+
</FormattingLocaleContext>,
311+
),
312+
);
313+
await screen.settle(() =>
314+
expect(screen.container.textContent).toContain("Browsing works up to 50,0 MB."),
315+
);
316+
});
317+
303318
it("keeps the archive and selected entry when the parent re-renders with a new refresh", async () => {
304319
const screen = setup();
305320
await screen.render();

‎apps/mobile/src/features/files/ZipArchiveView.tsx‎

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { FilePasswordPrompt } from "./FilePasswordPrompt";
22
import { errorDisplayMessage, Marked } from "@t3tools/client-runtime/errors";
33
import { formatAttachmentSize } from "@t3tools/client-runtime/state/attachments";
4+
import { useFormattingLocale } from "../../i18n/formattingLocale";
45
import {
56
ARCHIVE_ENTRY_MAX_BYTES,
67
ARCHIVE_MAX_BYTES,
@@ -72,17 +73,17 @@ interface ZipArchive {
7273
readonly fileCount: number;
7374
}
7475

75-
// title and detail hold msg() strings; they resolve where they render.
76+
// title and detail hold msg() strings; they resolve where they render. TOO_LARGE has no
77+
// detail because its size must be formatted in the app's locale, which only render knows.
7678
const ZipFailure = Schema.Struct({
7779
title: Schema.String,
78-
detail: Marked,
80+
detail: Schema.optionalKey(Marked),
7981
retry: Schema.Boolean,
8082
});
8183
type ZipFailure = typeof ZipFailure.Type;
8284

8385
const TOO_LARGE: ZipFailure = {
8486
title: msg("Too large to browse here"),
85-
detail: msg`Browsing works up to ${{ size: formatAttachmentSize(ARCHIVE_MAX_BYTES) }}. Save the ZIP to open it in another app.`,
8687
retry: false,
8788
};
8889
const CANCELLED: ZipFailure = {
@@ -283,6 +284,7 @@ function ZipTreeRowView(props: {
283284
const entry = node.entry;
284285
const gt = useGT();
285286
const messages = useMessages();
287+
const locale = useFormattingLocale();
286288
const folder = entry ? null : zipFolderLabel(node.label);
287289
return (
288290
<Pressable
@@ -318,7 +320,7 @@ function ZipTreeRowView(props: {
318320
</Text>
319321
<Text className="text-xs text-foreground-muted">
320322
{entry
321-
? formatAttachmentSize(entry.sizeBytes, messages)
323+
? formatAttachmentSize(entry.sizeBytes, messages, locale)
322324
: props.collapsed
323325
? gt`${plural(
324326
{ count: node.fileCount },
@@ -375,19 +377,20 @@ function ZipArchiveProgress(props: {
375377
const { timeLeft } = props;
376378
const gt = useGT();
377379
const messages = useMessages();
380+
const locale = useFormattingLocale();
378381
return (
379382
<View className="flex-1 justify-center gap-3 bg-sheet px-8">
380383
<Text className="text-xl font-t3-semibold text-foreground">
381384
{props.totalBytes > 0 ? (
382385
<T>
383-
<Var>{formatAttachmentSize(props.receivedBytes, messages)}</Var>
386+
<Var>{formatAttachmentSize(props.receivedBytes, messages, locale)}</Var>
384387
<Text className="text-xl text-foreground-muted">
385388
{" "}
386-
of <Var>{formatAttachmentSize(props.totalBytes, messages)}</Var>
389+
of <Var>{formatAttachmentSize(props.totalBytes, messages, locale)}</Var>
387390
</Text>
388391
</T>
389392
) : (
390-
formatAttachmentSize(props.receivedBytes, messages)
393+
formatAttachmentSize(props.receivedBytes, messages, locale)
391394
)}
392395
</Text>
393396
<Progress
@@ -411,12 +414,17 @@ function ZipArchiveFailure(props: {
411414
}) {
412415
const gt = useGT();
413416
const resolveMessage = useMessages();
417+
const locale = useFormattingLocale();
414418
return (
415419
<View className="flex-1 items-center justify-center bg-sheet px-6">
416420
<EmptyState
417421
variant="plain"
418422
title={resolveMessage(props.failure.title)}
419-
detail={resolveMessage(props.failure.detail)}
423+
detail={
424+
props.failure.detail === undefined
425+
? gt`Browsing works up to ${{ size: formatAttachmentSize(ARCHIVE_MAX_BYTES, resolveMessage, locale) }}. Save the ZIP to open it in another app.`
426+
: resolveMessage(props.failure.detail)
427+
}
420428
action={
421429
<View className="flex-row gap-3">
422430
{props.failure.retry ? (
@@ -551,6 +559,7 @@ export function ZipArchiveView(props: {
551559
const { state, unlock, retry, cancel } = useZipArchive(props);
552560
const gt = useGT();
553561
const messages = useMessages();
562+
const locale = useFormattingLocale();
554563
const [selection, setSelection] = useState<{
555564
readonly archive: ZipArchive;
556565
readonly entry: ZipEntry;
@@ -571,8 +580,8 @@ export function ZipArchiveView(props: {
571580
? gt`${plural(
572581
{ count: archive.fileCount },
573582
{
574-
one: part`${{ count: archive.fileCount }} file · ${{ size: formatAttachmentSize(props.sizeBytes, messages) }}`,
575-
other: part`${{ count: archive.fileCount }} files · ${{ size: formatAttachmentSize(props.sizeBytes, messages) }}`,
583+
one: part`${{ count: archive.fileCount }} file · ${{ size: formatAttachmentSize(props.sizeBytes, messages, locale) }}`,
584+
other: part`${{ count: archive.fileCount }} files · ${{ size: formatAttachmentSize(props.sizeBytes, messages, locale) }}`,
576585
},
577586
)}`
578587
: gt`${plural(
@@ -687,6 +696,7 @@ function ZipEntryView(props: {
687696
const { entry, draftKey, maxAttachmentBytes } = props;
688697
const gt = useGT();
689698
const messages = useMessages();
699+
const locale = useFormattingLocale();
690700
const { mimeType } = entry;
691701
const previewKind = filePreviewKind({ name: entry.name, mimeType });
692702
const isText = previewKind === "text" || previewKind === "markdown" || previewKind === "html";
@@ -797,7 +807,7 @@ function ZipEntryView(props: {
797807
rendered,
798808
});
799809
const folders = entry.path.split("/").slice(0, -1);
800-
const subtitle = `${[props.archiveName, ...folders].join(" / ")} · ${formatAttachmentSize(entry.sizeBytes, messages)}`;
810+
const subtitle = `${[props.archiveName, ...folders].join(" / ")} · ${formatAttachmentSize(entry.sizeBytes, messages, locale)}`;
801811
return (
802812
<View className="flex-1 bg-sheet">
803813
<AppBar
@@ -850,7 +860,7 @@ function ZipEntryView(props: {
850860
}
851861
detail={
852862
content.reason === "tooBig"
853-
? gt`Previews stop at ${{ size: formatAttachmentSize(ARCHIVE_ENTRY_MAX_BYTES, messages) }}. Save the file to open it in another app.`
863+
? gt`Previews stop at ${{ size: formatAttachmentSize(ARCHIVE_ENTRY_MAX_BYTES, messages, locale) }}. Save the file to open it in another app.`
854864
: (content.detail ?? gt`Could not read this file.`)
855865
}
856866
action={

‎apps/mobile/src/features/threads/ThreadFeed.tsx‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ import type { CodexArtifactTemplate } from "@t3tools/shared/codexArtifactTemplat
108108
import { codexArtifactTemplatePresentationLabel } from "@t3tools/shared/codexArtifactTemplatesCopy";
109109
import { resolveAssetUrl } from "@t3tools/client-runtime/state/assets";
110110
import { formatAttachmentSize } from "@t3tools/client-runtime/state/attachments";
111+
import { useFormattingLocale } from "../../i18n/formattingLocale";
111112
import {
112113
executeAtomQuery,
113114
isAtomCommandInterrupted,
@@ -771,6 +772,7 @@ function MessageAttachmentFile(props: {
771772
}) {
772773
const gt = useGT();
773774
const messages = useMessages();
775+
const locale = useFormattingLocale();
774776
const sourceIdentifier = useId();
775777
const navigation = useNavigation();
776778
const { selectedThread } = useThreadSelection();
@@ -786,7 +788,7 @@ function MessageAttachmentFile(props: {
786788
? "PDF"
787789
: (attachment.name.match(/\.([a-z0-9]{1,8})$/i)?.[1]?.toUpperCase() ??
788790
gt({ context: "generic file type label" })`File`);
789-
const sizeLabel = formatAttachmentSize(attachment.sizeBytes, messages);
791+
const sizeLabel = formatAttachmentSize(attachment.sizeBytes, messages, locale);
790792
const httpBaseUrl = Option.isSome(preparedConnection)
791793
? preparedConnection.value.httpBaseUrl
792794
: null;
@@ -2842,6 +2844,7 @@ type UserMessageContentProps = {
28422844
function UserMessageContent(props: UserMessageContentProps) {
28432845
const gt = useGT();
28442846
const messages = useMessages();
2847+
const locale = useFormattingLocale();
28452848
const [selected, setSelected] = useState<{ contextId: string; label: string } | null>(null);
28462849
const navigation = useNavigation();
28472850
const openThreadLink = useOpenThreadLink(props.environmentId);
@@ -2948,8 +2951,12 @@ function UserMessageContent(props: UserMessageContentProps) {
29482951
},
29492952
linkCustomization: (href) =>
29502953
withChipIcon(
2951-
enrichedContextLinkCustomization(href, props.context?.records ?? [], messages) ??
2952-
props.linkHandlers.linkCustomization?.(href),
2954+
enrichedContextLinkCustomization(
2955+
href,
2956+
props.context?.records ?? [],
2957+
messages,
2958+
locale,
2959+
) ?? props.linkHandlers.linkCustomization?.(href),
29532960
threadIcons.get(href),
29542961
),
29552962
}}

‎apps/mobile/src/features/threads/ThreadInlineFilePreview.tsx‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { useIsFocused } from "@react-navigation/native";
22
import { formatAttachmentSize } from "@t3tools/client-runtime/state/attachments";
3+
import { useFormattingLocale } from "../../i18n/formattingLocale";
34
import { useAudioPlayerStatus } from "expo-audio";
45
import { useGT, useMessages } from "gt-react-native";
56
import { useContext, useEffect, useRef, useState } from "react";
@@ -32,6 +33,7 @@ type PreviewProps = {
3233
function FileCardHeader(props: PreviewProps) {
3334
const gt = useGT();
3435
const messages = useMessages();
36+
const locale = useFormattingLocale();
3537
return (
3638
<Pressable
3739
accessibilityRole="button"
@@ -49,7 +51,7 @@ function FileCardHeader(props: PreviewProps) {
4951
</Text>
5052
<Text className="text-xs text-foreground-muted" numberOfLines={1}>
5153
{props.sizeBytes !== undefined
52-
? gt`Audio · ${{ size: formatAttachmentSize(props.sizeBytes, messages) }}`
54+
? gt`Audio · ${{ size: formatAttachmentSize(props.sizeBytes, messages, locale) }}`
5355
: gt`Audio`}
5456
</Text>
5557
</View>

‎apps/mobile/src/lib/composerChipPresentation.test.ts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,12 @@ describe("composerChipSizeSuffix", () => {
2828
? mFallback(message)
2929
: `${String(message.values.size)}${unit}`;
3030
}) as MessageResolver;
31-
expect(composerChipSizeSuffix({ kind: "file", sizeBytes: 12 * 1024 }, french)).toBe("12 Ko");
32-
expect(composerChipSizeSuffix({ kind: "image", sizeBytes: 3 * 1024 * 1024 }, french)).toBe(
33-
"3.0 Mo",
31+
expect(composerChipSizeSuffix({ kind: "file", sizeBytes: 12 * 1024 }, french, "fr")).toBe(
32+
"12 Ko",
3433
);
34+
expect(
35+
composerChipSizeSuffix({ kind: "image", sizeBytes: 3 * 1024 * 1024 }, french, "fr"),
36+
).toBe("3,0 Mo");
3537
});
3638
});
3739

‎apps/mobile/src/lib/composerChipPresentation.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,11 @@ export function contextChipLabel(
110110
export function composerChipSizeSuffix(
111111
record?: { readonly kind?: string; readonly sizeBytes?: number },
112112
resolve: MessageResolver = m,
113+
locale?: string,
113114
): string {
114115
if (record?.kind !== "file" && record?.kind !== "image") return "";
115116
return typeof record.sizeBytes === "number"
116-
? formatAttachmentSize(record.sizeBytes, resolve)
117+
? formatAttachmentSize(record.sizeBytes, resolve, locale)
117118
: "";
118119
}
119120

‎apps/mobile/src/lib/enrichedLinkPresentation.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export function enrichedContextLinkPresentation(
2424
href: string,
2525
records?: ReadonlyArray<ComposerContextRecord>,
2626
resolve?: MessageResolver,
27+
locale?: string,
2728
): { accent?: string; icon: ContextChipIconRef; label?: string } | undefined {
2829
const reference = parseComposerContextHref(href);
2930
if (!reference) return undefined;
@@ -32,7 +33,7 @@ export function enrichedContextLinkPresentation(
3233
records && !record
3334
? UNAVAILABLE_CONTEXT_CHIP_PRESENTATION
3435
: contextChipPresentation(reference.kind, record);
35-
const size = composerChipSizeSuffix(record, resolve);
36+
const size = composerChipSizeSuffix(record, resolve, locale);
3637
return {
3738
...(presentation.accent ? { accent: presentation.accent } : {}),
3839
icon: contextChipIcon(presentation, contextRecordFileName(record)),

‎apps/mobile/src/native/T3ComposerEditor.ios.tsx‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {
2727
contextChipPresentation,
2828
contextRecordFileName,
2929
} from "../lib/composerChipPresentation";
30+
import { useFormattingLocale } from "../i18n/formattingLocale";
3031
import { contextChipIconUri, modelChipIcon, modelChipIconUri } from "../lib/contextChipIconSource";
3132
import { useUniwindTheme } from "../lib/useUniwindTheme";
3233
import { createNativeComposerTheme } from "../lib/nativeComposerTheme";
@@ -160,6 +161,7 @@ export function ComposerEditor({
160161
}: ComposerEditorProps) {
161162
const gt = useGT();
162163
const messages = useMessages();
164+
const locale = useFormattingLocale();
163165
const nativeRef = useRef<NativeComposerEditorRef>(null);
164166
const mostRecentEventCountRef = useRef(0);
165167
const [mostRecentEventCount, setMostRecentEventCount] = useState(0);
@@ -225,7 +227,7 @@ export function ComposerEditor({
225227
: token.type === "citation"
226228
? token.value
227229
: fileDisplayName(token.value),
228-
detail: token.type === "context" ? composerChipSizeSuffix(record, messages) : "",
230+
detail: token.type === "context" ? composerChipSizeSuffix(record, messages, locale) : "",
229231
iconUri: model ? modelChipIconUri(model) : contextChipIconUri(icon),
230232
tintsIcon: model ? modelChipIcon(model).tintsIcon : icon.kind === "chip",
231233
};
@@ -241,6 +243,7 @@ export function ComposerEditor({
241243
theme,
242244
chipTextColor,
243245
messages,
246+
locale,
244247
]);
245248
// Every render resolves against the snapshot history, so a render whose
246249
// (value, selection) lags the acknowledged native state is stamped behind

0 commit comments

Comments
 (0)