Skip to content

Commit 8b9ea0f

Browse files
committed
action_sheet: Translations
1 parent 174982b commit 8b9ea0f

File tree

3 files changed

+60
-11
lines changed

3 files changed

+60
-11
lines changed

assets/l10n/app_en.arb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,38 @@
3939
"@cameraAccessDeniedButtonText": {
4040
"description": "Message for dialog when the user needs to grant permissions for camera access."
4141
},
42+
"actionSheetOptionCopy": "Copy message text",
43+
"@actionSheetOptionCopy": {
44+
"description": "Label for copy message text button on action sheet."
45+
},
46+
"actionSheetOptionShare": "Share",
47+
"@actionSheetOptionShare": {
48+
"description": "Label for share button on action sheet."
49+
},
50+
"actionSheetOptionQuoteAndReply": "Quote and reply",
51+
"@actionSheetOptionQuoteAndReply": {
52+
"description": "Label for Quote and reply button on action sheet."
53+
},
54+
"errorCouldNotFetchMessageSource": "Could not fetch message source",
55+
"@errorCouldNotFetchMessageSource": {
56+
"description": "Error message when the source of a message could not be fetched."
57+
},
58+
"errorCopyingFailed": "Copying failed",
59+
"@errorCopyingFailed": {
60+
"description": "Error message when copying the text of a message to the users system clipboard failed."
61+
},
62+
"errorMessageDoesNotSeemToExist": "That message does not seem to exist.",
63+
"@errorMessageDoesNotSeemToExist": {
64+
"description": "Error message when loading a message that does not exist."
65+
},
66+
"errorQuotationFailed": "Quotation failed",
67+
"@errorQuotationFailed": {
68+
"description": "Error message when quoting a message failed."
69+
},
70+
"successMessageCopied": "Message Copied",
71+
"@successMessageCopied": {
72+
"description": "Message when content of a message was copied to the users system clipboard."
73+
},
4274
"subscribedToNStreams": "Subscribed to {num, plural, =0{no streams} =1{1 stream} other{{num} streams}}",
4375
"@subscribedToNStreams": {
4476
"description": "Test page label showing number of streams user is subscribed to.",

lib/widgets/action_sheet.dart

Lines changed: 25 additions & 11 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 label(ZulipLocalizations zulipLocalizations);
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(label(zulipLocalizations)));
5860
}
5961
}
6062

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

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

70-
@override get label => 'Share';
72+
@override
73+
String label(ZulipLocalizations zulipLocalizations) {
74+
return zulipLocalizations.actionSheetOptionShare;
75+
}
7176

7277
@override get onPressed => (BuildContext context) async {
7378
// Close the message action sheet; we're about to show the share
@@ -104,13 +109,14 @@ Future<String?> fetchRawContentWithFeedback({
104109
// - If request(s) take(s) a long time, show snackbar with cancel
105110
// button, like "Still working on quote-and-reply…".
106111
// On final failure or success, auto-dismiss the snackbar.
112+
final zulipLocalizations = ZulipLocalizations.of(context);
107113
try {
108114
fetchedMessage = await getMessageCompat(PerAccountStoreWidget.of(context).connection,
109115
messageId: messageId,
110116
applyMarkdown: false,
111117
);
112118
if (fetchedMessage == null) {
113-
errorMessage = 'That message does not seem to exist.';
119+
errorMessage = zulipLocalizations.errorMessageDoesNotSeemToExist;
114120
}
115121
} catch (e) {
116122
switch (e) {
@@ -119,7 +125,7 @@ Future<String?> fetchRawContentWithFeedback({
119125
// TODO specific messages for common errors, like network errors
120126
// (support with reusable code)
121127
default:
122-
errorMessage = 'Could not fetch message source.';
128+
errorMessage = zulipLocalizations.errorCouldNotFetchMessageSource;
123129
}
124130
}
125131

@@ -146,12 +152,16 @@ class QuoteAndReplyButton extends MessageActionSheetMenuItemButton {
146152

147153
@override get icon => Icons.format_quote_outlined;
148154

149-
@override get label => 'Quote and reply';
155+
@override
156+
String label(ZulipLocalizations zulipLocalizations) {
157+
return zulipLocalizations.actionSheetOptionQuoteAndReply;
158+
}
150159

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

156166
// This will be null only if the compose box disappeared after the
157167
// message action sheet opened, and before "Quote and reply" was pressed.
@@ -174,7 +184,7 @@ class QuoteAndReplyButton extends MessageActionSheetMenuItemButton {
174184
final rawContent = await fetchRawContentWithFeedback(
175185
context: messageListContext,
176186
messageId: message.id,
177-
errorDialogTitle: 'Quotation failed',
187+
errorDialogTitle: zulipLocalizations.errorQuotationFailed,
178188
);
179189

180190
if (!messageListContext.mounted) return;
@@ -203,26 +213,30 @@ class CopyButton extends MessageActionSheetMenuItemButton {
203213

204214
@override get icon => Icons.copy;
205215

206-
@override get label => 'Copy message text';
216+
@override
217+
String label(ZulipLocalizations zulipLocalizations) {
218+
return zulipLocalizations.actionSheetOptionCopy;
219+
}
207220

208221
@override get onPressed => (BuildContext context) async {
209222
// Close the message action sheet. We won't be showing request progress,
210223
// but hopefully it won't take long at all, and
211224
// fetchRawContentWithFeedback has a TODO for giving feedback if it does.
212225
Navigator.of(context).pop();
226+
final zulipLocalizations = ZulipLocalizations.of(messageListContext);
213227

214228
final rawContent = await fetchRawContentWithFeedback(
215229
context: messageListContext,
216230
messageId: message.id,
217-
errorDialogTitle: 'Copying failed',
231+
errorDialogTitle: zulipLocalizations.errorCopyingFailed,
218232
);
219233

220234
if (rawContent == null) return;
221235

222236
if (!messageListContext.mounted) return;
223237

224-
// TODO(i18n)
225-
copyWithPopup(context: context, successContent: const Text('Message copied'),
238+
copyWithPopup(context: context,
239+
successContent: Text(zulipLocalizations.successMessageCopied),
226240
data: ClipboardData(text: rawContent));
227241
};
228242
}

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)