Skip to content

Commit 49df1b4

Browse files
committed
compose: Add translations in _uploadFiles
1 parent e29b7b8 commit 49df1b4

File tree

2 files changed

+44
-10
lines changed

2 files changed

+44
-10
lines changed

assets/l10n/app_en.arb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,29 @@
5959
"@errorCopyingFailed": {
6060
"description": "Error message when copying the text of a message to the users system clipboard failed."
6161
},
62+
"errorFailedToUploadFileTitle": "Failed to upload file: {filename}",
63+
"@errorFailedToUploadFileTitle": {
64+
"description": "Error title when the specified file failed to upload.",
65+
"placeholders": {
66+
"filename": {"type": "String", "example": "file.txt"}
67+
}
68+
},
69+
"errorFilesTooLarge": "{num, plural, =1{File is} other{{num} files are}} larger than the server's limit of {maxFileUploadSizeMib} MiB and will not be uploaded:\n\n{listMessage}",
70+
"@errorFilesTooLarge": {
71+
"description": "Error message when attached files are too large in size.",
72+
"placeholders": {
73+
"num": {"type": "int", "example": "2"},
74+
"maxFileUploadSizeMib": {"type": "int", "example": "15"},
75+
"listMessage": {"type": "String", "example": "foo.txt\nbar.txt"}
76+
}
77+
},
78+
"errorFilesTooLargeTitle": "{num, plural, =1{File} other{Files}} too large",
79+
"@errorFilesTooLargeTitle": {
80+
"description": "Error title when attached files are too large in size.",
81+
"placeholders": {
82+
"num": {"type": "int", "example": "4"}
83+
}
84+
},
6285
"errorLoginInvalidInputTitle": "Invalid input",
6386
"@errorLoginInvalidInputTitle": {
6487
"description": "Error title for login when input is invalid."
@@ -101,6 +124,13 @@
101124
"@successMessageCopied": {
102125
"description": "Message when content of a message was copied to the users system clipboard."
103126
},
127+
"composeBoxUploadingFilename": "Uploading {filename}...",
128+
"@composeBoxUploadingFilename": {
129+
"description": "Label in compose box showing the specified file is currently uploading.",
130+
"placeholders": {
131+
"filename": {"type": "String", "example": "file.txt"}
132+
}
133+
},
104134
"contentValidationErrorTooLong": "Message length shouldn't be greater than 10000 characters.",
105135
"@contentValidationErrorTooLong": {
106136
"description": "Content validation error message when the message is too long."

lib/widgets/compose_box.dart

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,11 @@ class ComposeContentController extends ComposeController<ContentValidationError>
208208
///
209209
/// Returns an int "tag" that should be passed to registerUploadEnd on the
210210
/// upload's success or failure.
211-
int registerUploadStart(String filename) {
211+
int registerUploadStart(String filename, ZulipLocalizations zulipLocalizations) {
212212
final tag = _nextUploadTag;
213213
_nextUploadTag += 1;
214-
final placeholder = inlineLink('Uploading $filename...', null); // TODO(i18n)
214+
final linkText = zulipLocalizations.composeBoxUploadingFilename(filename);
215+
final placeholder = inlineLink(linkText, null);
215216
_uploads[tag] = (filename: filename, placeholder: placeholder);
216217
notifyListeners(); // _uploads change could affect validationErrors
217218
value = value.replaced(insertionIndex(), '$placeholder\n\n');
@@ -430,6 +431,7 @@ Future<void> _uploadFiles({
430431
}) async {
431432
assert(context.mounted);
432433
final store = PerAccountStoreWidget.of(context);
434+
final zulipLocalizations = ZulipLocalizations.of(context);
433435

434436
final List<_File> tooLargeFiles = [];
435437
final List<_File> rightSizeFiles = [];
@@ -445,18 +447,19 @@ Future<void> _uploadFiles({
445447
final listMessage = tooLargeFiles
446448
.map((file) => '${file.filename}: ${(file.length / (1 << 20)).toStringAsFixed(1)} MiB')
447449
.join('\n');
448-
showErrorDialog( // TODO(i18n)
450+
showErrorDialog(
449451
context: context,
450-
title: 'File(s) too large',
451-
message:
452-
'${tooLargeFiles.length} file(s) are larger than the server\'s limit'
453-
' of ${store.maxFileUploadSizeMib} MiB and will not be uploaded:'
454-
'\n\n$listMessage');
452+
title: zulipLocalizations.errorFilesTooLargeTitle(tooLargeFiles.length),
453+
message: zulipLocalizations.errorFilesTooLarge(
454+
tooLargeFiles.length,
455+
store.maxFileUploadSizeMib,
456+
listMessage));
455457
}
456458

457459
final List<(int, _File)> uploadsInProgress = [];
458460
for (final file in rightSizeFiles) {
459-
final tag = contentController.registerUploadStart(file.filename);
461+
final tag = contentController.registerUploadStart(file.filename,
462+
zulipLocalizations);
460463
uploadsInProgress.add((tag, file));
461464
}
462465
if (!contentFocusNode.hasFocus) {
@@ -475,7 +478,8 @@ Future<void> _uploadFiles({
475478
// TODO(#37): Specifically handle `413 Payload Too Large`
476479
// TODO(#37): On API errors, quote `msg` from server, with "The server said:"
477480
showErrorDialog(context: context,
478-
title: 'Failed to upload file: $filename', message: e.toString());
481+
title: zulipLocalizations.errorFailedToUploadFileTitle(filename),
482+
message: e.toString());
479483
} finally {
480484
contentController.registerUploadEnd(tag, url);
481485
}

0 commit comments

Comments
 (0)