1
1
import 'package:flutter/material.dart' ;
2
2
import 'package:flutter/services.dart' ;
3
+ import 'package:flutter_gen/gen_l10n/zulip_localizations.dart' ;
3
4
import 'package:share_plus/share_plus.dart' ;
4
5
5
6
import '../api/exception.dart' ;
@@ -43,18 +44,19 @@ abstract class MessageActionSheetMenuItemButton extends StatelessWidget {
43
44
}) : assert (messageListContext.findAncestorWidgetOfExactType <MessageListPage >() != null );
44
45
45
46
IconData get icon;
46
- String get label ;
47
+ String Function ( ZulipLocalizations ) get translateLabel ;
47
48
void Function (BuildContext ) get onPressed;
48
49
49
50
final Message message;
50
51
final BuildContext messageListContext;
51
52
52
53
@override
53
54
Widget build (BuildContext context) {
55
+ final zulipLocalizations = ZulipLocalizations .of (context);
54
56
return MenuItemButton (
55
57
leadingIcon: Icon (icon),
56
58
onPressed: () => onPressed (context),
57
- child: Text (label ));
59
+ child: Text (translateLabel (zulipLocalizations) ));
58
60
}
59
61
}
60
62
@@ -67,7 +69,9 @@ class ShareButton extends MessageActionSheetMenuItemButton {
67
69
68
70
@override get icon => Icons .adaptive.share;
69
71
70
- @override get label => 'Share' ;
72
+ @override get translateLabel => (ZulipLocalizations zulipLocalizations) {
73
+ return zulipLocalizations.actionSheetShare;
74
+ };
71
75
72
76
@override get onPressed => (BuildContext context) async {
73
77
// Close the message action sheet; we're about to show the share
@@ -104,22 +108,23 @@ Future<String?> fetchRawContentWithFeedback({
104
108
// - If request(s) take(s) a long time, show snackbar with cancel
105
109
// button, like "Still working on quote-and-reply…".
106
110
// On final failure or success, auto-dismiss the snackbar.
111
+ final zulipLocalizations = ZulipLocalizations .of (context);
107
112
try {
108
113
fetchedMessage = await getMessageCompat (PerAccountStoreWidget .of (context).connection,
109
114
messageId: messageId,
110
115
applyMarkdown: false ,
111
116
);
112
117
if (fetchedMessage == null ) {
113
- errorMessage = 'That message does not seem to exist.' ;
118
+ errorMessage = zulipLocalizations.actionSheetMessageDoesNotSeemToExist ;
114
119
}
115
120
} catch (e) {
116
121
switch (e) {
117
122
case ZulipApiException ():
118
- errorMessage = e.message ;
123
+ errorMessage = e.toTranslatedString (zulipLocalizations) ;
119
124
// TODO specific messages for common errors, like network errors
120
125
// (support with reusable code)
121
126
default :
122
- errorMessage = 'Could not fetch message source.' ;
127
+ errorMessage = zulipLocalizations.actionSheetCouldNotFetchMessageSource ;
123
128
}
124
129
}
125
130
@@ -146,12 +151,15 @@ class QuoteAndReplyButton extends MessageActionSheetMenuItemButton {
146
151
147
152
@override get icon => Icons .format_quote_outlined;
148
153
149
- @override get label => 'Quote and reply' ;
154
+ @override get translateLabel => (ZulipLocalizations zulipLocalizations) {
155
+ return zulipLocalizations.actionSheetQuoteAndReply;
156
+ };
150
157
151
158
@override get onPressed => (BuildContext bottomSheetContext) async {
152
159
// Close the message action sheet. We'll show the request progress
153
160
// in the compose-box content input with a "[Quoting…]" placeholder.
154
161
Navigator .of (bottomSheetContext).pop ();
162
+ final zulipLocalizations = ZulipLocalizations .of (messageListContext);
155
163
156
164
// This will be null only if the compose box disappeared after the
157
165
// message action sheet opened, and before "Quote and reply" was pressed.
@@ -174,7 +182,7 @@ class QuoteAndReplyButton extends MessageActionSheetMenuItemButton {
174
182
final rawContent = await fetchRawContentWithFeedback (
175
183
context: messageListContext,
176
184
messageId: message.id,
177
- errorDialogTitle: 'Quotation failed' ,
185
+ errorDialogTitle: zulipLocalizations.actionSheetQuotationFailed ,
178
186
);
179
187
180
188
if (! messageListContext.mounted) return ;
@@ -203,26 +211,29 @@ class CopyButton extends MessageActionSheetMenuItemButton {
203
211
204
212
@override get icon => Icons .copy;
205
213
206
- @override get label => 'Copy message text' ;
214
+ @override get translateLabel => (ZulipLocalizations zulipLocalizations) {
215
+ return zulipLocalizations.actionSheetCopyMessageText;
216
+ };
207
217
208
218
@override get onPressed => (BuildContext context) async {
209
219
// Close the message action sheet. We won't be showing request progress,
210
220
// but hopefully it won't take long at all, and
211
221
// fetchRawContentWithFeedback has a TODO for giving feedback if it does.
212
222
Navigator .of (context).pop ();
223
+ final zulipLocalizations = ZulipLocalizations .of (messageListContext);
213
224
214
225
final rawContent = await fetchRawContentWithFeedback (
215
226
context: messageListContext,
216
227
messageId: message.id,
217
- errorDialogTitle: 'Copying failed' ,
228
+ errorDialogTitle: zulipLocalizations.actionSheetCopyingFailed ,
218
229
);
219
230
220
231
if (rawContent == null ) return ;
221
232
222
233
if (! messageListContext.mounted) return ;
223
234
224
- // TODO(i18n)
225
- copyWithPopup (context : context, successContent: const Text ('Message copied' ),
235
+ copyWithPopup (context : context,
236
+ successContent: Text (zulipLocalizations.actionSheetMessageCopied ),
226
237
data: ClipboardData (text: rawContent));
227
238
};
228
239
}
0 commit comments