@@ -4,6 +4,7 @@ import 'dart:io' show Platform;
4
4
import 'dart:math' ;
5
5
6
6
import 'package:awesome_notifications/awesome_notifications.dart' ;
7
+ import 'package:easy_localization/easy_localization.dart' ;
7
8
import 'package:enum_to_string/enum_to_string.dart' ;
8
9
import 'package:firebase_core/firebase_core.dart' ;
9
10
import 'package:firebase_messaging/firebase_messaging.dart' ;
@@ -41,7 +42,7 @@ class NotificationService {
41
42
await locator.allReady ();
42
43
await Firebase .initializeApp (
43
44
options: DefaultFirebaseOptions .currentPlatform);
44
-
45
+ await EasyLocalization . ensureInitialized ();
45
46
NotificationService notificationService = locator <NotificationService >();
46
47
notificationService._logger.d (
47
48
"Handling a background message: ${message .messageId } with ${message .data }" );
@@ -198,15 +199,17 @@ class NotificationService {
198
199
return [
199
200
NotificationChannel (
200
201
channelKey: printerSetting.statusUpdatedChannelKey,
201
- channelName: 'Print Status Updates - ${printerSetting .name }' ,
202
- channelDescription: 'Notifications regarding the print progress.' ,
202
+ channelName: tr ('notifications.channels.status.name' ,
203
+ args: [printerSetting.name]),
204
+ channelDescription: tr ('notifications.channels.status.desc' ),
203
205
channelGroupKey: printerSetting.uuid,
204
206
importance: NotificationImportance .Max ,
205
207
defaultColor: brownish.shade500),
206
208
NotificationChannel (
207
209
channelKey: printerSetting.printProgressChannelKey,
208
- channelName: 'Print Progress Updates - ${printerSetting .name }' ,
209
- channelDescription: 'Notifications regarding the print progress.' ,
210
+ channelName: tr ('notifications.channels.progress.name' ,
211
+ args: [printerSetting.name]),
212
+ channelDescription: tr ('notifications.channels.progress.desc' ),
210
213
channelGroupKey: printerSetting.uuid,
211
214
playSound: false ,
212
215
enableVibration: false ,
@@ -220,7 +223,8 @@ class NotificationService {
220
223
PrinterSetting printerSetting) {
221
224
return NotificationChannelGroup (
222
225
channelGroupkey: printerSetting.uuid,
223
- channelGroupName: "Printer ${printerSetting .name }" );
226
+ channelGroupName: tr ('notifications.channel_printer_grp' ,
227
+ args: [printerSetting.name]));
224
228
}
225
229
226
230
Future <void > _setupFCMOnPrinterOnceConnected (PrinterSetting setting) async {
@@ -262,57 +266,48 @@ class NotificationService {
262
266
if (oldState == null && updatedState != PrintState .printing)
263
267
return updatedState;
264
268
269
+ NotificationContent notificationContent = NotificationContent (
270
+ id: Random ().nextInt (20000000 ),
271
+ channelKey: printerSetting.statusUpdatedChannelKey,
272
+ title: tr ('notifications.channels.status.title' ,
273
+ args: [printerSetting.name]),
274
+ notificationLayout: NotificationLayout .BigText ,
275
+ );
276
+
265
277
switch (updatedState) {
266
278
case PrintState .standby:
267
279
await _removePrintProgressNotification (printerSetting);
268
280
break ;
269
281
case PrintState .printing:
270
- await _notifyAPI.createNotification (
271
- content: NotificationContent (
272
- id: Random ().nextInt (20000000 ),
273
- channelKey: printerSetting.statusUpdatedChannelKey,
274
- title: 'Print state of ${printerSetting .name } changed!' ,
275
- body: 'Started to print file: "${updatedFile ?? "UNKNOWN" }"' ,
276
- notificationLayout: NotificationLayout .BigText ,
277
- ));
282
+ notificationContent.body = tr (
283
+ 'notifications.channels.status.body_printing' ,
284
+ args: [updatedFile ?? 'Unknown' ]);
278
285
printerSetting.lastPrintProgress = null ;
279
286
break ;
280
287
case PrintState .paused:
281
- await _notifyAPI.createNotification (
282
- content: NotificationContent (
283
- id: Random ().nextInt (20000000 ),
284
- channelKey: printerSetting.statusUpdatedChannelKey,
285
- title: 'Print state of ${printerSetting .name } changed!' ,
286
- body: 'Paused printing of file: "${updatedFile ?? "UNKNOWN" }"' ,
287
- notificationLayout: NotificationLayout .BigText ,
288
- ));
288
+ notificationContent.body = tr (
289
+ 'notifications.channels.status.body_paused' ,
290
+ args: [updatedFile ?? 'Unknown' ]);
289
291
break ;
290
292
case PrintState .complete:
291
- await _notifyAPI.createNotification (
292
- content: NotificationContent (
293
- id: Random ().nextInt (20000000 ),
294
- channelKey: printerSetting.statusUpdatedChannelKey,
295
- title: 'Print state of ${printerSetting .name } changed!' ,
296
- body: 'Finished printing "${updatedFile ?? "UNKNOWN" }"' ,
297
- notificationLayout: NotificationLayout .BigText ,
298
- ));
299
-
293
+ notificationContent.body = tr (
294
+ 'notifications.channels.status.body_complete' ,
295
+ args: [updatedFile ?? 'Unknown' ]);
300
296
await _removePrintProgressNotification (printerSetting);
301
297
break ;
302
298
case PrintState .error:
303
- if (oldState == PrintState .printing)
304
- await _notifyAPI.createNotification (
305
- content: NotificationContent (
306
- id: Random ().nextInt (20000000 ),
307
- channelKey: printerSetting.statusUpdatedChannelKey,
308
- title: 'Print state of ${printerSetting .name } changed!' ,
309
- body:
310
- 'Error while printing file: "${updatedFile ?? "UNKNOWN" }"' ,
311
- notificationLayout: NotificationLayout .BigText ,
312
- color: Colors .red));
299
+ if (oldState == PrintState .printing) {
300
+ notificationContent.body = tr (
301
+ 'notifications.channels.status.body_error' ,
302
+ args: [updatedFile ?? 'Unknown' ]);
303
+ notificationContent.color = Colors .red;
304
+ }
313
305
await _removePrintProgressNotification (printerSetting);
314
306
break ;
315
307
}
308
+ if (updatedState != PrintState .standby)
309
+ await _notifyAPI.createNotification (content: notificationContent);
310
+
316
311
return updatedState;
317
312
}
318
313
@@ -330,7 +325,9 @@ class NotificationService {
330
325
double est = printDuration / progress - printDuration;
331
326
dt = DateTime .now ().add (Duration (seconds: est.round ()));
332
327
}
333
- String eta = (dt != null ) ? 'ETA:${DateFormat .Hm ().format (dt )}' : '' ;
328
+ String eta = (dt != null )
329
+ ? '${tr ('pages.overview.general.print_card.eta' )}:${DateFormat .Hm ().format (dt )}'
330
+ : '' ;
334
331
335
332
int index = await _machineService.indexOfMachine (printerSetting);
336
333
if (index < 0 ) return ;
@@ -340,7 +337,8 @@ class NotificationService {
340
337
content: NotificationContent (
341
338
id: index * 3 + 3 ,
342
339
channelKey: printerSetting.printProgressChannelKey,
343
- title: 'Print progress of ${printerSetting .name }' ,
340
+ title: tr ('notifications.channels.progress.title' ,
341
+ args: [printerSetting.name]),
344
342
body: '$eta $progressPerc %' ,
345
343
notificationLayout: NotificationLayout .ProgressBar ,
346
344
locked: true ,
0 commit comments