Skip to content

Commit

Permalink
compose: Add translations in _uploadFiles
Browse files Browse the repository at this point in the history
  • Loading branch information
sirpengi committed Oct 2, 2023
1 parent 742b92b commit 058598f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 10 deletions.
30 changes: 30 additions & 0 deletions assets/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,29 @@
"@errorCopyingFailed": {
"description": "Error message when copying the text of a message to the users system clipboard failed."
},
"errorFailedToUploadFileTitle": "Failed to upload file: {filename}",
"@errorFailedToUploadFileTitle": {
"description": "Error title when the specified file failed to upload.",
"placeholders": {
"filename": {"type": "String", "example": "file.txt"}
}
},
"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}",
"@errorFilesTooLarge": {
"description": "Error message when attached files are too large in size.",
"placeholders": {
"num": {"type": "int", "example": "2"},
"maxFileUploadSizeMib": {"type": "int", "example": "15"},
"listMessage": {"type": "String", "example": "foo.txt\nbar.txt"}
}
},
"errorFilesTooLargeTitle": "{num, plural, =1{File} other{Files}} too large",
"@errorFilesTooLargeTitle": {
"description": "Error title when attached files are too large in size.",
"placeholders": {
"num": {"type": "int", "example": "4"}
}
},
"errorLoginInvalidInputTitle": "Invalid input",
"@errorLoginInvalidInputTitle": {
"description": "Error title for login when input is invalid."
Expand Down Expand Up @@ -101,6 +124,13 @@
"@successMessageCopied": {
"description": "Message when content of a message was copied to the users system clipboard."
},
"composeBoxUploadingFilename": "Uploading {filename}...",
"@composeBoxUploadingFilename": {
"description": "Label in compose box showing the specified file is currently uploading.",
"placeholders": {
"filename": {"type": "String", "example": "file.txt"}
}
},
"contentValidationErrorTooLong": "Message length shouldn't be greater than 10000 characters.",
"@contentValidationErrorTooLong": {
"description": "Content validation error message when the message is too long."
Expand Down
24 changes: 14 additions & 10 deletions lib/widgets/compose_box.dart
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,11 @@ class ComposeContentController extends ComposeController<ContentValidationError>
///
/// Returns an int "tag" that should be passed to registerUploadEnd on the
/// upload's success or failure.
int registerUploadStart(String filename) {
int registerUploadStart(String filename, ZulipLocalizations zulipLocalizations) {
final tag = _nextUploadTag;
_nextUploadTag += 1;
final placeholder = inlineLink('Uploading $filename...', null); // TODO(i18n)
final linkText = zulipLocalizations.composeBoxUploadingFilename(filename);
final placeholder = inlineLink(linkText, null);
_uploads[tag] = (filename: filename, placeholder: placeholder);
notifyListeners(); // _uploads change could affect validationErrors
value = value.replaced(insertionIndex(), '$placeholder\n\n');
Expand Down Expand Up @@ -430,6 +431,7 @@ Future<void> _uploadFiles({
}) async {
assert(context.mounted);
final store = PerAccountStoreWidget.of(context);
final zulipLocalizations = ZulipLocalizations.of(context);

final List<_File> tooLargeFiles = [];
final List<_File> rightSizeFiles = [];
Expand All @@ -445,18 +447,19 @@ Future<void> _uploadFiles({
final listMessage = tooLargeFiles
.map((file) => '${file.filename}: ${(file.length / (1 << 20)).toStringAsFixed(1)} MiB')
.join('\n');
showErrorDialog( // TODO(i18n)
showErrorDialog(
context: context,
title: 'File(s) too large',
message:
'${tooLargeFiles.length} file(s) are larger than the server\'s limit'
' of ${store.maxFileUploadSizeMib} MiB and will not be uploaded:'
'\n\n$listMessage');
title: zulipLocalizations.errorFilesTooLargeTitle(tooLargeFiles.length),
message: zulipLocalizations.errorFilesTooLarge(
tooLargeFiles.length,
store.maxFileUploadSizeMib,
listMessage));
}

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

0 comments on commit 058598f

Please sign in to comment.