11import { FilePasswordPrompt } from "./FilePasswordPrompt" ;
22import { errorDisplayMessage , Marked } from "@t3tools/client-runtime/errors" ;
33import { formatAttachmentSize } from "@t3tools/client-runtime/state/attachments" ;
4+ import { useFormattingLocale } from "../../i18n/formattingLocale" ;
45import {
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.
7678const ZipFailure = Schema . Struct ( {
7779 title : Schema . String ,
78- detail : Marked ,
80+ detail : Schema . optionalKey ( Marked ) ,
7981 retry : Schema . Boolean ,
8082} ) ;
8183type ZipFailure = typeof ZipFailure . Type ;
8284
8385const 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} ;
8889const 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 = {
0 commit comments