Skip to content

Commit f9f3d9a

Browse files
committed
action_sheet: translations
1 parent 84ad638 commit f9f3d9a

File tree

3 files changed

+58
-12
lines changed

3 files changed

+58
-12
lines changed

assets/l10n/app_en.arb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,38 @@
4343
"@cameraAccessDeniedButtonText": {
4444
"description": "Message for dialog when the user needs to grant permissions for camera access."
4545
},
46+
"actionSheetCopyMessageText": "Copy message text",
47+
"@actionSheetCopyMessageText": {
48+
"description": "Label for copy message text button on action sheet."
49+
},
50+
"actionSheetCouldNotFetchMessageSource": "Could not fetch message source",
51+
"@actionSheetCouldNotFetchMessageSource": {
52+
"description": "Dialog message when the source of a message could not be fetched."
53+
},
54+
"actionSheetCopyingFailed": "Copying failed",
55+
"@actionSheetCopyingFailed": {
56+
"description": "Dialog message when copying the text of a message to the users system clipboard failed."
57+
},
58+
"actionSheetMessageCopied": "Message Copied",
59+
"@actionSheetMessageCopied": {
60+
"description": "Dialog message when content of a message was copied to the users system clipboard."
61+
},
62+
"actionSheetMessageDoesNotSeemToExist": "That message does not seem to exist.",
63+
"@actionSheetMessageDoesNotSeemToExist": {
64+
"description": "Dialog message in action sheet when loading a message that does not exist."
65+
},
66+
"actionSheetQuoteAndReply": "Quote and reply",
67+
"@actionSheetQuoteAndReply": {
68+
"description": "Label for Quote and reply button on action sheet."
69+
},
70+
"actionSheetQuotationFailed": "Quotation failed",
71+
"@actionSheetQuotationFailed": {
72+
"description": "Error dialog message when quoting a message failed."
73+
},
74+
"actionSheetShare": "Share",
75+
"@actionSheetShare": {
76+
"description": "Label for share button on action sheet."
77+
},
4678
"subscribedToNStreams": "Subscribed to {num, plural, =0{no streams} =1{1 stream} other{{num} streams}}",
4779
"@subscribedToNStreams": {
4880
"description": "Test page label showing number of streams user is subscribed to.",

lib/widgets/action_sheet.dart

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'package:flutter/material.dart';
22
import 'package:flutter/services.dart';
3+
import 'package:flutter_gen/gen_l10n/zulip_localizations.dart';
34
import 'package:share_plus/share_plus.dart';
45

56
import '../api/exception.dart';
@@ -43,18 +44,19 @@ abstract class MessageActionSheetMenuItemButton extends StatelessWidget {
4344
}) : assert(messageListContext.findAncestorWidgetOfExactType<MessageListPage>() != null);
4445

4546
IconData get icon;
46-
String get label;
47+
String Function(ZulipLocalizations) get translateLabel;
4748
void Function(BuildContext) get onPressed;
4849

4950
final Message message;
5051
final BuildContext messageListContext;
5152

5253
@override
5354
Widget build(BuildContext context) {
55+
final zulipLocalizations = ZulipLocalizations.of(context);
5456
return MenuItemButton(
5557
leadingIcon: Icon(icon),
5658
onPressed: () => onPressed(context),
57-
child: Text(label));
59+
child: Text(translateLabel(zulipLocalizations)));
5860
}
5961
}
6062

@@ -67,7 +69,9 @@ class ShareButton extends MessageActionSheetMenuItemButton {
6769

6870
@override get icon => Icons.adaptive.share;
6971

70-
@override get label => 'Share';
72+
@override get translateLabel => (ZulipLocalizations zulipLocalizations) {
73+
return zulipLocalizations.actionSheetShare;
74+
};
7175

7276
@override get onPressed => (BuildContext context) async {
7377
// Close the message action sheet; we're about to show the share
@@ -104,22 +108,23 @@ Future<String?> fetchRawContentWithFeedback({
104108
// - If request(s) take(s) a long time, show snackbar with cancel
105109
// button, like "Still working on quote-and-reply…".
106110
// On final failure or success, auto-dismiss the snackbar.
111+
final zulipLocalizations = ZulipLocalizations.of(context);
107112
try {
108113
fetchedMessage = await getMessageCompat(PerAccountStoreWidget.of(context).connection,
109114
messageId: messageId,
110115
applyMarkdown: false,
111116
);
112117
if (fetchedMessage == null) {
113-
errorMessage = 'That message does not seem to exist.';
118+
errorMessage = zulipLocalizations.actionSheetMessageDoesNotSeemToExist;
114119
}
115120
} catch (e) {
116121
switch (e) {
117122
case ZulipApiException():
118-
errorMessage = e.message;
123+
errorMessage = e.toTranslatedString(zulipLocalizations);
119124
// TODO specific messages for common errors, like network errors
120125
// (support with reusable code)
121126
default:
122-
errorMessage = 'Could not fetch message source.';
127+
errorMessage = zulipLocalizations.actionSheetCouldNotFetchMessageSource;
123128
}
124129
}
125130

@@ -146,12 +151,15 @@ class QuoteAndReplyButton extends MessageActionSheetMenuItemButton {
146151

147152
@override get icon => Icons.format_quote_outlined;
148153

149-
@override get label => 'Quote and reply';
154+
@override get translateLabel => (ZulipLocalizations zulipLocalizations) {
155+
return zulipLocalizations.actionSheetQuoteAndReply;
156+
};
150157

151158
@override get onPressed => (BuildContext bottomSheetContext) async {
152159
// Close the message action sheet. We'll show the request progress
153160
// in the compose-box content input with a "[Quoting…]" placeholder.
154161
Navigator.of(bottomSheetContext).pop();
162+
final zulipLocalizations = ZulipLocalizations.of(messageListContext);
155163

156164
// This will be null only if the compose box disappeared after the
157165
// message action sheet opened, and before "Quote and reply" was pressed.
@@ -174,7 +182,7 @@ class QuoteAndReplyButton extends MessageActionSheetMenuItemButton {
174182
final rawContent = await fetchRawContentWithFeedback(
175183
context: messageListContext,
176184
messageId: message.id,
177-
errorDialogTitle: 'Quotation failed',
185+
errorDialogTitle: zulipLocalizations.actionSheetQuotationFailed,
178186
);
179187

180188
if (!messageListContext.mounted) return;
@@ -203,26 +211,29 @@ class CopyButton extends MessageActionSheetMenuItemButton {
203211

204212
@override get icon => Icons.copy;
205213

206-
@override get label => 'Copy message text';
214+
@override get translateLabel => (ZulipLocalizations zulipLocalizations) {
215+
return zulipLocalizations.actionSheetCopyMessageText;
216+
};
207217

208218
@override get onPressed => (BuildContext context) async {
209219
// Close the message action sheet. We won't be showing request progress,
210220
// but hopefully it won't take long at all, and
211221
// fetchRawContentWithFeedback has a TODO for giving feedback if it does.
212222
Navigator.of(context).pop();
223+
final zulipLocalizations = ZulipLocalizations.of(messageListContext);
213224

214225
final rawContent = await fetchRawContentWithFeedback(
215226
context: messageListContext,
216227
messageId: message.id,
217-
errorDialogTitle: 'Copying failed',
228+
errorDialogTitle: zulipLocalizations.actionSheetCopyingFailed,
218229
);
219230

220231
if (rawContent == null) return;
221232

222233
if (!messageListContext.mounted) return;
223234

224-
// TODO(i18n)
225-
copyWithPopup(context: context, successContent: const Text('Message copied'),
235+
copyWithPopup(context: context,
236+
successContent: Text(zulipLocalizations.actionSheetMessageCopied),
226237
data: ClipboardData(text: rawContent));
227238
};
228239
}

test/widgets/action_sheet_test.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'package:checks/checks.dart';
22
import 'package:flutter/material.dart';
33
import 'package:flutter/services.dart';
4+
import 'package:flutter_gen/gen_l10n/zulip_localizations.dart';
45
import 'package:flutter_test/flutter_test.dart';
56
import 'package:zulip/api/model/model.dart';
67
import 'package:zulip/api/route/messages.dart';
@@ -48,6 +49,8 @@ Future<void> setupToMessageActionSheet(WidgetTester tester, {
4849

4950
await tester.pumpWidget(
5051
MaterialApp(
52+
localizationsDelegates: ZulipLocalizations.localizationsDelegates,
53+
supportedLocales: ZulipLocalizations.supportedLocales,
5154
home: GlobalStoreWidget(
5255
child: PerAccountStoreWidget(
5356
accountId: eg.selfAccount.id,

0 commit comments

Comments
 (0)