diff --git a/CHANGELOG.md b/CHANGELOG.md index e6b2b4d0..017e956d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.1.0 +* Finished basic API +* Added localization feature + ## 0.0.12 * Fixed notification report mode bug diff --git a/README.md b/README.md index e5e433f2..b977bc54 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ your own backend where you're storing application logs, so you can manipulate it Add this line to your **pubspec.yaml**: ```yaml dependencies: - catcher: ^0.0.12 + catcher: ^0.1.0 ``` Then run this command: @@ -39,9 +39,10 @@ import 'package:catcher/catcher_plugin.dart'; [AndroidX](#androidx) [Catcher usage](#catcher-usage) [Adding navigator key](#adding-navigator-key) -[Catcher configuration](#catcher-configuration) -[Report catched exception](#report-catched-exception) - +[Catcher configuration](#catcher-configuration) +[Report catched exception](#report-catched-exception) +[Localization](#localization) + [Report modes](#report-modes) * [Silent Report Mode](#silent-report-mode) * [Notification Report Mode](#notification-report-mode) @@ -258,6 +259,175 @@ try { } ``` +### Localization +Catcher allows to create localizations for Report modes. To add localization support, you need setup +few things: + +Add navigatorKey in your MaterialApp: +```dart + navigatorKey: Catcher.navigatorKey, +``` + +Add flutter localizations delegates and locales in your MaterialApp: +```dart + localizationsDelegates: [ + GlobalMaterialLocalizations.delegate, + GlobalWidgetsLocalizations.delegate, + ], + supportedLocales: [ + const Locale('en', 'US'), + const Locale('pl', 'PL'), + ], +``` + +Add localizationOptions in catcherOptions: +```dart +CatcherOptions( +... + localizationOptions: [ + LocalizationOptions("pl", notificationReportModeTitle: "My translation" ...), + LocalizationOptions("de", notificationReportModeTitle: "My translation" ...), + ] +) +``` + +You can add translate for given parameters: +```dart + final String notificationReportModeTitle; // notification report mode title + final String notificationReportModeContent; // notification report mode subtitle + + final String dialogReportModeTitle; // dialog report mode title + final String dialogReportModeDescription; // dialog report mode description + final String dialogReportModeAccept; // dialog report mode accept button + final String dialogReportModeCancel; // dialog report mode cancel button + + final String pageReportModeTitle; // page report mode toolbar title + final String pageReportModeDescription; // page report mode description + final String pageReportModeAccept; // page report mode accept button + final String pageReportModeCancel; // page report mode cancel button +``` + +If you want to override default english texts, just add simply localization options for "en" language. + +There are build in support for languages: +* english +```dart +LocalizationOptions.buildDefaultEnglishOptions(); +``` +* chinese +```dart +LocalizationOptions.buildDefaultChineseOptions(); +``` +* hindi +```dart +LocalizationOptions.buildDefaultHindiOptions(); +``` +* spanish +```dart +LocalizationOptions.buildDefaultSpanishOptions(); +``` +* malay +```dart +LocalizationOptions.buildDefaultMalayOptions(); +``` +* russian +```dart +LocalizationOptions.buildDefaultRussianOptions(); +``` +* portuguese +```dart +LocalizationOptions.buildDefaultPortugueseOptions(); +``` +* french +```dart +LocalizationOptions.buildDefaultFrenchOptions(); +``` +* polish +```dart +LocalizationOptions.buildDefaultPolishOptions(); +``` + +Complete Example: +```dart +import 'package:flutter/material.dart'; +import 'package:catcher/catcher_plugin.dart'; +import 'package:flutter_localizations/flutter_localizations.dart'; + +main() { + CatcherOptions debugOptions = CatcherOptions(DialogReportMode(), [ + ConsoleHandler(), + HttpHandler(HttpRequestType.post, Uri.parse("https://httpstat.us/200"), + printLogs: true) + ], localizationOptions: [ + LocalizationOptions("pl", + notificationReportModeTitle: "Wystąpił błąd aplikacji", + notificationReportModeContent: + "Naciśnij tutaj aby wysłać raport do zespołu wpsarcia", + dialogReportModeTitle: "Błąd aplikacji", + dialogReportModeDescription: + "Wystąpił niespodziewany błąd aplikacji. Raport z błędem jest gotowy do wysłania do zespołu wsparcia. Naciśnij akceptuj aby wysłać raport lub odrzuć aby odrzucić raport.", + dialogReportModeAccept: "Akceptuj", + dialogReportModeCancel: "Odrzuć", + pageReportModeTitle: "Błąd aplikacji", + pageReportModeDescription: + "Wystąpił niespodziewany błąd aplikacji. Raport z błędem jest gotowy do wysłania do zespołu wsparcia. Naciśnij akceptuj aby wysłać raport lub odrzuć aby odrzucić raport.", + pageReportModeAccept: "Akceptuj", + pageReportModeCancel: "Odrzuć") + ]); + CatcherOptions releaseOptions = CatcherOptions(NotificationReportMode(), [ + EmailManualHandler(["recipient@email.com"]) + ]); + + Catcher(MyApp(), debugConfig: debugOptions, releaseConfig: releaseOptions); +} + +class MyApp extends StatefulWidget { + @override + _MyAppState createState() => _MyAppState(); +} + +class _MyAppState extends State { + @override + void initState() { + super.initState(); + } + + @override + Widget build(BuildContext context) { + return MaterialApp( + navigatorKey: Catcher.navigatorKey, + localizationsDelegates: [ + GlobalMaterialLocalizations.delegate, + GlobalWidgetsLocalizations.delegate, + ], + supportedLocales: [ + const Locale('en', 'US'), + const Locale('pl', 'PL'), + ], + home: Scaffold( + appBar: AppBar( + title: const Text('Plugin example app'), + ), + body: ChildWidget()), + ); + } +} + +class ChildWidget extends StatelessWidget { + @override + Widget build(BuildContext context) { + return Container( + child: FlatButton( + child: Text("Generate error"), onPressed: () => generateError())); + } + + generateError() async { + throw "Test exception"; + } +} + +``` + ### Report modes Report mode is the process of gathering user permission to handle error. User can accept or deny permission to handle error. There are 4 types of report mode: @@ -276,6 +446,8 @@ Notification Report Mode shows local notification about error. Once user clicks ReportMode reportMode = NotificationReportMode(); ``` +See localization options to change default texts. +


Notification Report Mode @@ -285,17 +457,10 @@ ReportMode reportMode = NotificationReportMode(); Dialog Report Mode shows dialog with information about error. Dialog has title, description and 2 buttons: Accept and Cancel. Once user clicks on Accept button, report will be pushed to handlers. ```dart - ReportMode reportMode = DialogReportMode( - titleText: "Crash", - descriptionText: "My description", - acceptText: "OK", - cancelText: "Back"); + ReportMode reportMode = DialogReportMode(); ``` -Dialog Report Mode can be configured with optional parameters: -titleText (optional) - text for dialog title -descriptionText (optional) - text for dialog description -acceptText (optional) - confirmation button text -cancelText (optional) - cancel button text + +See localization options to change default texts.

@@ -307,20 +472,14 @@ cancelText (optional) - cancel button text Page Report Mode shows new page with information about error. Page has title, description, stack trace view and 2 buttons: Accept and Cancel. Once user clicks on Accept button, report will be pushed to handlers. ```dart - ReportMode reportMode = PageReportMode( - titleText: "Crash", - descriptionText: "My description", - acceptText: "OK", - cancelText: "Back", - showStackTrace: false); + ReportMode reportMode = PageReportMode(showStackTrace: false); ``` Page Report Mode can be configured with optional parameters: -titleText (optional) - text for title in toobar -descriptionText (optional) - text for page descrption -acceptText (optional) - confirmation button text -cancelText (optional) - cancel button text -showStackTrace (optional) - enables/disables stack trace view +showStackTrace (optional) - enables/disables stack trace view + +See localization options to change default texts. +


diff --git a/example/lib/basic_example.dart b/example/lib/basic_example.dart index 24e08c76..4742cdde 100644 --- a/example/lib/basic_example.dart +++ b/example/lib/basic_example.dart @@ -2,7 +2,7 @@ import 'package:flutter/material.dart'; import 'package:catcher/catcher_plugin.dart'; main() { - CatcherOptions debugOptions = CatcherOptions(NotificationReportMode(), [ + CatcherOptions debugOptions = CatcherOptions(DialogReportMode(), [ ConsoleHandler(), HttpHandler(HttpRequestType.post, Uri.parse("https://httpstat.us/200"), printLogs: true) @@ -11,10 +11,7 @@ main() { EmailManualHandler(["recipient@email.com"]) ]); - - Catcher(MyApp(), - debugConfig: debugOptions, - releaseConfig: releaseOptions); + Catcher(MyApp(), debugConfig: debugOptions, releaseConfig: releaseOptions); } class MyApp extends StatefulWidget { diff --git a/example/lib/localization_example.dart b/example/lib/localization_example.dart new file mode 100644 index 00000000..a00f0fd6 --- /dev/null +++ b/example/lib/localization_example.dart @@ -0,0 +1,83 @@ +import 'package:flutter/material.dart'; +import 'package:catcher/catcher_plugin.dart'; +import 'package:flutter_localizations/flutter_localizations.dart'; + +main() { + CatcherOptions debugOptions = CatcherOptions(DialogReportMode(), [ + ConsoleHandler(), + HttpHandler(HttpRequestType.post, Uri.parse("https://httpstat.us/200"), + printLogs: true) + ], localizationOptions: [ + LocalizationOptions( + "en", + dialogReportModeTitle: "Custom message", + dialogReportModeDescription: "Custom message", + dialogReportModeAccept: "YES", + dialogReportModeCancel: "NO", + ), + LocalizationOptions("pl", + notificationReportModeTitle: "Wystąpił błąd aplikacji", + notificationReportModeContent: + "Naciśnij tutaj aby wysłać raport do zespołu wpsarcia", + dialogReportModeTitle: "Błąd aplikacji", + dialogReportModeDescription: + "Wystąpił niespodziewany błąd aplikacji. Raport z błędem jest gotowy do wysłania do zespołu wsparcia. Naciśnij akceptuj aby wysłać raport lub odrzuć aby odrzucić raport.", + dialogReportModeAccept: "Akceptuj", + dialogReportModeCancel: "Odrzuć", + pageReportModeTitle: "Błąd aplikacji", + pageReportModeDescription: + "Wystąpił niespodziewany błąd aplikacji. Raport z błędem jest gotowy do wysłania do zespołu wsparcia. Naciśnij akceptuj aby wysłać raport lub odrzuć aby odrzucić raport.", + pageReportModeAccept: "Akceptuj", + pageReportModeCancel: "Odrzuć") + ]); + CatcherOptions releaseOptions = CatcherOptions(NotificationReportMode(), [ + EmailManualHandler(["recipient@email.com"]) + ]); + + Catcher(MyApp(), debugConfig: debugOptions, releaseConfig: releaseOptions); +} + +class MyApp extends StatefulWidget { + @override + _MyAppState createState() => _MyAppState(); +} + +class _MyAppState extends State { + @override + void initState() { + super.initState(); + } + + @override + Widget build(BuildContext context) { + return MaterialApp( + navigatorKey: Catcher.navigatorKey, + localizationsDelegates: [ + GlobalMaterialLocalizations.delegate, + GlobalWidgetsLocalizations.delegate, + ], + supportedLocales: [ + const Locale('en', 'US'), + const Locale('pl', 'PL'), + ], + home: Scaffold( + appBar: AppBar( + title: const Text('Plugin example app'), + ), + body: ChildWidget()), + ); + } +} + +class ChildWidget extends StatelessWidget { + @override + Widget build(BuildContext context) { + return Container( + child: FlatButton( + child: Text("Generate error"), onPressed: () => generateError())); + } + + generateError() async { + throw "Test exception"; + } +} diff --git a/example/lib/report_modes_example.dart b/example/lib/report_modes_example.dart index b66cca5c..f574415c 100644 --- a/example/lib/report_modes_example.dart +++ b/example/lib/report_modes_example.dart @@ -17,10 +17,6 @@ main() { //page: ReportMode reportMode = PageReportMode( - titleText: "Crash", - descriptionText: "My description", - acceptText: "OK", - cancelText: "Back", showStackTrace: false); CatcherOptions debugOptions = CatcherOptions(reportMode, [ConsoleHandler()]); diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 6705db2a..6cc5c0e0 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -8,6 +8,8 @@ environment: dependencies: flutter: sdk: flutter + flutter_localizations: + sdk: flutter path_provider: ^0.5.0 # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. diff --git a/lib/catcher_plugin.dart b/lib/catcher_plugin.dart index 94c6dd6e..7f3ab210 100644 --- a/lib/catcher_plugin.dart +++ b/lib/catcher_plugin.dart @@ -19,4 +19,5 @@ export 'package:catcher/model/report_mode_type.dart'; export 'package:catcher/model/toast_handler_gravity.dart'; export 'package:catcher/model/toast_handler_length.dart'; export 'package:catcher/model/catcher_options.dart'; +export 'package:catcher/model/localization_options.dart'; export 'package:catcher/core/catcher.dart'; diff --git a/lib/core/catcher.dart b/lib/core/catcher.dart index 97332f15..344b5e64 100644 --- a/lib/core/catcher.dart +++ b/lib/core/catcher.dart @@ -9,6 +9,7 @@ import 'package:catcher/mode/page_report_mode.dart'; import 'package:catcher/model/application_profile.dart'; import 'package:catcher/model/catcher_options.dart'; import 'package:catcher/mode/report_mode_action_confirmed.dart'; +import 'package:catcher/model/localization_options.dart'; import 'package:catcher/model/report.dart'; import 'package:device_info/device_info.dart'; import 'package:flutter/foundation.dart'; @@ -30,6 +31,7 @@ class Catcher with ReportModeAction { Map _deviceParameters = Map(); Map _applicationParameters = Map(); List _cachedReports = List(); + LocalizationOptions _localizationOptions; static Catcher _instance; @@ -42,10 +44,12 @@ class Catcher with ReportModeAction { _instance = this; _configureLogger(); _setupCurrentConfig(); + _setupErrorHooks(); + _setupLocalization(); _setupReportMode(); _loadDeviceInfo(); _loadApplicationInfo(); - _setupErrorHooks(); + if (_currentConfig.handlers.isEmpty) { _logger .warning("Handlers list is empty. Configure at least one handler to " @@ -91,7 +95,7 @@ class Catcher with ReportModeAction { } void _setupReportMode() { - this._currentConfig.reportMode.setReportModeAction(this); + this._currentConfig.reportMode.initialize(this, _localizationOptions); } _setupErrorHooks() { @@ -100,9 +104,10 @@ class Catcher with ReportModeAction { }; Isolate.current.addErrorListener(new RawReceivePort((dynamic pair) async { + var isolateError = pair as List; await _reportError( - (pair as List).first, - (pair as List).last, + isolateError.first.toString(), + isolateError.last.toString(), ); }).sendPort); @@ -129,7 +134,7 @@ class Catcher with ReportModeAction { }); } else { deviceInfo.iosInfo.then((iosInfo) { - _loadiOSParameters(iosInfo); + _loadIosParameters(iosInfo); }); } } @@ -163,7 +168,7 @@ class Catcher with ReportModeAction { androidDeviceInfo.version.securityPatch; } - void _loadiOSParameters(IosDeviceInfo iosInfo) { + void _loadIosParameters(IosDeviceInfo iosInfo) { _deviceParameters["model"] = iosInfo.model; _deviceParameters["isPsychicalDevice"] = iosInfo.isPhysicalDevice; _deviceParameters["name"] = iosInfo.name; @@ -186,6 +191,56 @@ class Catcher with ReportModeAction { }); } + _setupLocalization() { + Locale locale = Locale("en", "US"); + if (_isContextValid()) { + BuildContext context = _getContext(); + if (context != null) { + locale = Localizations.localeOf(context); + } + + if (_currentConfig.localizationOptions != null) { + for (var options in _currentConfig.localizationOptions) { + if (options.languageCode.toLowerCase() == + locale.languageCode.toLowerCase()) { + _localizationOptions = options; + } + } + } + } + + if (_localizationOptions == null) { + _localizationOptions = + _getDefaultLocalizationOptionsForLanguage(locale.languageCode); + } + } + + LocalizationOptions _getDefaultLocalizationOptionsForLanguage( + String language) { + switch (language.toLowerCase()) { + case "en": + return LocalizationOptions.buildDefaultEnglishOptions(); + case "zh": + return LocalizationOptions.buildDefaultChineseOptions(); + case "hi": + return LocalizationOptions.buildDefaultHindiOptions(); + case "es": + return LocalizationOptions.buildDefaultSpanishOptions(); + case "ms": + return LocalizationOptions.buildDefaultMalayOptions(); + case "ru": + return LocalizationOptions.buildDefaultRussianOptions(); + case "pt": + return LocalizationOptions.buildDefaultPortugueseOptions(); + case "fr": + return LocalizationOptions.buildDefaultFrenchOptions(); + case "pl": + return LocalizationOptions.buildDefaultPolishOptions(); + default: + return LocalizationOptions.buildDefaultEnglishOptions(); + } + } + static reportCheckedError(dynamic error, dynamic stackTrace) { if (error == null) { error = "undefined error"; @@ -245,6 +300,7 @@ class Catcher with ReportModeAction { } bool _isContextValid() { - return navigatorKey.currentState != null; + return navigatorKey.currentState != null && + navigatorKey.currentState.overlay != null; } } diff --git a/lib/mode/dialog_report_mode.dart b/lib/mode/dialog_report_mode.dart index 6ae64cc9..e1149326 100644 --- a/lib/mode/dialog_report_mode.dart +++ b/lib/mode/dialog_report_mode.dart @@ -3,18 +3,6 @@ import 'package:catcher/model/report.dart'; import 'package:flutter/material.dart'; class DialogReportMode extends ReportMode { - final String titleText; - final String descriptionText; - final String acceptText; - final String cancelText; - - DialogReportMode( - {this.titleText = "Crash", - this.descriptionText = "Unexpected error occurred in application. " - "Error report is ready to send to support team. " - "Please click Accept to send error report or Cancel to dismiss report.", - this.acceptText = "Accept", - this.cancelText = "Cancel"}); @override void requestAction(Report report, BuildContext context) { @@ -26,15 +14,15 @@ class DialogReportMode extends ReportMode { context: context, builder: (BuildContext build) { return AlertDialog( - title: Text(titleText), - content: Text(descriptionText), + title: Text(localizationOptions.dialogReportModeTitle), + content: Text(localizationOptions.dialogReportModeDescription), actions: [ FlatButton( - child: Text(acceptText), + child: Text(localizationOptions.dialogReportModeAccept), onPressed: () => _acceptReport(context, report), ), FlatButton( - child: Text(cancelText), + child: Text(localizationOptions.dialogReportModeCancel), onPressed: () => _cancelReport(context, report), ), ], diff --git a/lib/mode/notification_report_mode.dart b/lib/mode/notification_report_mode.dart index 2bdb23fc..1e03b0b8 100644 --- a/lib/mode/notification_report_mode.dart +++ b/lib/mode/notification_report_mode.dart @@ -1,4 +1,5 @@ import 'package:catcher/mode/report_mode_action_confirmed.dart'; +import 'package:catcher/model/localization_options.dart'; import 'package:catcher/model/report_mode.dart'; import 'package:catcher/model/report.dart'; import 'package:flutter/widgets.dart'; @@ -8,34 +9,29 @@ class NotificationReportMode extends ReportMode { FlutterLocalNotificationsPlugin _flutterLocalNotificationsPlugin; Report _lastReport; - final String titleText; - final String contentText; final String channelId; final String channelName; final String channelDescription; final String icon; NotificationReportMode( - {this.titleText = "Application error occurred", - this.contentText = "Click here to send error report to support team.", - this.channelId = "Catcher", + {this.channelId = "Catcher", this.channelName = "Catcher", this.channelDescription = "Catcher default channel", this.icon = "@mipmap/ic_launcher"}); @override - setReportModeAction(ReportModeAction reportModeAction) { + initialize(ReportModeAction reportModeAction, + LocalizationOptions localizationOptions) { _initializeNotificationsPlugin(); - return super.setReportModeAction(reportModeAction); + return super.initialize(reportModeAction, localizationOptions); } - /** - * We need to init notifications plugin after constructor. If we init - * in constructor, and there will be 2 catcher options which uses this report - * mode, only notification report mode from second catcher options will be - * initialized correctly. That's why init is delayed. - */ - void _initializeNotificationsPlugin(){ + /// We need to init notifications plugin after constructor. If we init + /// in constructor, and there will be 2 catcher options which uses this report + /// mode, only notification report mode from second catcher options will be + /// initialized correctly. That's why init is delayed. + void _initializeNotificationsPlugin() { _flutterLocalNotificationsPlugin = new FlutterLocalNotificationsPlugin(); var initializationSettingsAndroid = new AndroidInitializationSettings(icon); var initializationSettingsIOS = new IOSInitializationSettings(); @@ -64,7 +60,11 @@ class NotificationReportMode extends ReportMode { var platformChannelSpecifics = new NotificationDetails( androidPlatformChannelSpecifics, iOSPlatformChannelSpecifics); - await _flutterLocalNotificationsPlugin - .show(0, titleText, contentText, platformChannelSpecifics, payload: ""); + await _flutterLocalNotificationsPlugin.show( + 0, + localizationOptions.notificationReportModeTitle, + localizationOptions.notificationReportModeContent, + platformChannelSpecifics, + payload: ""); } } diff --git a/lib/mode/page_report_mode.dart b/lib/mode/page_report_mode.dart index 90b5d73a..103516de 100644 --- a/lib/mode/page_report_mode.dart +++ b/lib/mode/page_report_mode.dart @@ -4,19 +4,9 @@ import 'package:flutter/material.dart'; import 'package:flutter/widgets.dart'; class PageReportMode extends ReportMode { - final String titleText; - final String descriptionText; final bool showStackTrace; - final String acceptText; - final String cancelText; PageReportMode({ - this.titleText = "Crash", - this.descriptionText = "Unexpected error occurred in application. " - "Error report is ready to send to support team. " - "Please click Accept to send error report or Cancel to dismiss report.", - this.acceptText = "Accept", - this.cancelText = "Cancel", this.showStackTrace = true, }); @@ -49,7 +39,7 @@ class PageWidgetState extends State { _context = context; return Scaffold( appBar: AppBar( - title: Text(widget.pageReportMode.titleText), + title: Text(widget.pageReportMode.localizationOptions.pageReportModeTitle), ), body: Container( padding: EdgeInsets.only(left: 10, right: 10), @@ -58,7 +48,7 @@ class PageWidgetState extends State { children: [ Padding(padding: EdgeInsets.only(top: 10)), Text( - widget.pageReportMode.descriptionText, + widget.pageReportMode.localizationOptions.pageReportModeDescription, style: _getTextStyle(15), textAlign: TextAlign.center, ), @@ -68,11 +58,11 @@ class PageWidgetState extends State { mainAxisAlignment: MainAxisAlignment.center, children: [ FlatButton( - child: Text(widget.pageReportMode.acceptText), + child: Text(widget.pageReportMode.localizationOptions.pageReportModeAccept), onPressed: () => _acceptReport(), ), FlatButton( - child: Text(widget.pageReportMode.cancelText), + child: Text(widget.pageReportMode.localizationOptions.pageReportModeCancel), onPressed: () => _cancelReport(), ), ], diff --git a/lib/model/catcher_options.dart b/lib/model/catcher_options.dart index 559a9692..ac1bc0b1 100644 --- a/lib/model/catcher_options.dart +++ b/lib/model/catcher_options.dart @@ -2,6 +2,7 @@ import 'package:catcher/handlers/console_handler.dart'; import 'package:catcher/handlers/report_handler.dart'; import 'package:catcher/mode/notification_report_mode.dart'; import 'package:catcher/mode/silent_report_mode.dart'; +import 'package:catcher/model/localization_options.dart'; import 'package:catcher/model/report_mode.dart'; class CatcherOptions { @@ -9,25 +10,31 @@ class CatcherOptions { final int handlerTimeout; final ReportMode reportMode; final Map customParameters; + final List localizationOptions; CatcherOptions(this.reportMode, this.handlers, - {this.handlerTimeout = 5000, this.customParameters = const {}}); + {this.handlerTimeout = 5000, + this.customParameters = const {}, + this.localizationOptions = const []}); CatcherOptions.getDefaultReleaseOptions() : this.handlers = [ConsoleHandler()], this.reportMode = NotificationReportMode(), handlerTimeout = 5000, - customParameters = Map(); + customParameters = Map(), + localizationOptions = []; CatcherOptions.getDefaultDebugOptions() : this.handlers = [ConsoleHandler()], this.reportMode = SilentReportMode(), handlerTimeout = 10000, - customParameters = Map(); + customParameters = Map(), + localizationOptions = []; CatcherOptions.getDefaultProfileOptions() : this.handlers = [ConsoleHandler()], this.reportMode = SilentReportMode(), handlerTimeout = 10000, - customParameters = Map(); + customParameters = Map(), + localizationOptions = []; } diff --git a/lib/model/localization_options.dart b/lib/model/localization_options.dart new file mode 100644 index 00000000..c9219eb5 --- /dev/null +++ b/lib/model/localization_options.dart @@ -0,0 +1,174 @@ +class LocalizationOptions { + final String languageCode; + final String notificationReportModeTitle; + final String notificationReportModeContent; + + final String dialogReportModeTitle; + final String dialogReportModeDescription; + final String dialogReportModeAccept; + final String dialogReportModeCancel; + + final String pageReportModeTitle; + final String pageReportModeDescription; + final String pageReportModeAccept; + final String pageReportModeCancel; + + LocalizationOptions( + this.languageCode, { + this.notificationReportModeTitle = "Application error occurred", + this.notificationReportModeContent = + "Click here to send error report to support team.", + this.dialogReportModeTitle = "Crash", + this.dialogReportModeDescription = + "Unexpected error occurred in application. Error report is ready to send to support team. Please click Accept to send error report or Cancel to dismiss report.", + this.dialogReportModeAccept = "Accept", + this.dialogReportModeCancel = "Cancel", + this.pageReportModeTitle = "Crash", + this.pageReportModeDescription = + "Unexpected error occurred in application. Error report is ready to send to support team. Please click Accept to send error report or Cancel to dismiss report.", + this.pageReportModeAccept = "Accept", + this.pageReportModeCancel = "Cancel", + }); + + static LocalizationOptions buildDefaultEnglishOptions() { + return LocalizationOptions("en"); + } + + static LocalizationOptions buildDefaultChineseOptions() { + return LocalizationOptions("zh", + notificationReportModeTitle: "發生應用錯誤", + notificationReportModeContent: "單擊此處將錯誤報告發送給支持團隊。", + dialogReportModeTitle: "緊急", + dialogReportModeDescription: + "應用程序中發生意外錯誤。 錯誤報告已準備好發送給支持團隊。 請單擊“接受”以發送錯誤報告,或單擊“取消”以關閉報告。", + dialogReportModeAccept: "接受", + dialogReportModeCancel: "取消", + pageReportModeTitle: "緊急", + pageReportModeDescription: + "應用程序中發生意外錯誤。 錯誤報告已準備好發送給支持團隊。 請單擊“接受”以發送錯誤報告,或單擊“取消”以關閉報告。", + pageReportModeAccept: "接受", + pageReportModeCancel: "取消"); + } + + static LocalizationOptions buildDefaultHindiOptions() { + return LocalizationOptions("hi", + notificationReportModeTitle: "एप्लिकेशन त्रुटि हुई", + notificationReportModeContent: + "समर्थन टीम को त्रुटि रिपोर्ट भेजने के लिए यहां क्लिक करें।.", + dialogReportModeTitle: "दुर्घटना", + dialogReportModeDescription: + "आवेदन में अप्रत्याशित त्रुटि हुई। त्रुटि रिपोर्ट समर्थन टीम को भेजने के लिए तैयार है। कृपया त्रुटि रिपोर्ट भेजने के लिए स्वीकार करें या रिपोर्ट को रद्द करने के लिए रद्द करें पर क्लिक करें।", + dialogReportModeAccept: "स्वीकार करना", + dialogReportModeCancel: "रद्द करना", + pageReportModeTitle: "दुर्घटना", + pageReportModeDescription: + "आवेदन में अप्रत्याशित त्रुटि हुई। त्रुटि रिपोर्ट समर्थन टीम को भेजने के लिए तैयार है। कृपया त्रुटि रिपोर्ट भेजने के लिए स्वीकार करें या रिपोर्ट को रद्द करने के लिए रद्द करें पर क्लिक करें।", + pageReportModeAccept: "स्वीकार करना", + pageReportModeCancel: "रद्द करना"); + } + + static LocalizationOptions buildDefaultSpanishOptions() { + return LocalizationOptions("es", + notificationReportModeTitle: "Error de aplicación ocurrió", + notificationReportModeContent: + "Haga clic aquí para enviar un informe de error al equipo de soporte.", + dialogReportModeTitle: "Choque", + dialogReportModeDescription: + "Se ha producido un error inesperado en la aplicación. El informe de errores está listo para enviar al equipo de soporte. Haga clic en Aceptar para enviar el informe de errores o en Cancelar para cancelar el informe.", + dialogReportModeAccept: "Aceptar", + dialogReportModeCancel: "Cancelar", + pageReportModeTitle: "Choque", + pageReportModeDescription: + "Se ha producido un error inesperado en la aplicación. El informe de errores está listo para enviar al equipo de soporte. Haga clic en Aceptar para enviar el informe de errores o en Cancelar para cancelar el informe.", + pageReportModeAccept: "Aceptar", + pageReportModeCancel: "Cancelar"); + } + + static LocalizationOptions buildDefaultMalayOptions() { + return LocalizationOptions("ms", + notificationReportModeTitle: "Ralat permohonan berlaku", + notificationReportModeContent: + "Klik di sini untuk menghantar laporan ralat untuk menyokong pasukan.", + dialogReportModeTitle: "Kemalangan", + dialogReportModeDescription: + "Ralat tidak dijangka berlaku dalam aplikasi. Laporan ralat sedia dihantar untuk menyokong pasukan. Sila klik Terima untuk menghantar laporan ralat atau Batal untuk menolak laporan.", + dialogReportModeAccept: "Terima", + dialogReportModeCancel: "Batalkan", + pageReportModeTitle: "Kemalangan", + pageReportModeDescription: + "Ralat tidak dijangka berlaku dalam aplikasi. Laporan ralat sedia dihantar untuk menyokong pasukan. Sila klik Terima untuk menghantar laporan ralat atau Batal untuk menolak laporan.", + pageReportModeAccept: "Terima", + pageReportModeCancel: "Batalkan"); + } + + static LocalizationOptions buildDefaultRussianOptions() { + return LocalizationOptions("ru", + notificationReportModeTitle: "Произошла ошибка приложения", + notificationReportModeContent: + "Нажмите здесь, чтобы отправить отчет об ошибке в службу поддержки.", + dialogReportModeTitle: "авария", + dialogReportModeDescription: + "В приложении произошла непредвиденная ошибка. Отчет об ошибке готов к отправке в службу поддержки. Пожалуйста, нажмите Принять, чтобы отправить отчет об ошибке или Отмена, чтобы закрыть отчет.", + dialogReportModeAccept: "принимать", + dialogReportModeCancel: "отменить", + pageReportModeTitle: "авария", + pageReportModeDescription: + "В приложении произошла непредвиденная ошибка. Отчет об ошибке готов к отправке в службу поддержки. Пожалуйста, нажмите Принять, чтобы отправить отчет об ошибке или Отмена, чтобы закрыть отчет.", + pageReportModeAccept: "принимать", + pageReportModeCancel: "отменить"); + } + + static LocalizationOptions buildDefaultPortugueseOptions() { + return LocalizationOptions("pt", + notificationReportModeTitle: "Erro de aplicaçãod", + notificationReportModeContent: + "Clique aqui para enviar um relatório de erros para a equipe de suporte.", + dialogReportModeTitle: "Batido", + dialogReportModeDescription: + "Ocorreu um erro inesperado no aplicativo. O relatório de erros está pronto para enviar para a equipe de suporte. Por favor, clique em Aceitar para enviar um relatório de erro ou em Cancelar para descartar o relatório.", + dialogReportModeAccept: "Aceitar", + dialogReportModeCancel: "Cancelar", + pageReportModeTitle: "Batido", + pageReportModeDescription: + "Ocorreu um erro inesperado no aplicativo. O relatório de erros está pronto para enviar para a equipe de suporte. Por favor, clique em Aceitar para enviar um relatório de erro ou em Cancelar para descartar o relatório.", + pageReportModeAccept: "Aceitar", + pageReportModeCancel: "Cancelar"); + } + + static LocalizationOptions buildDefaultFrenchOptions() { + return LocalizationOptions("fr", + notificationReportModeTitle: "Une erreur d'application s'est produite", + notificationReportModeContent: + "Cliquez ici pour envoyer un rapport d'erreur à l'équipe de support.", + dialogReportModeTitle: "Fracas", + dialogReportModeDescription: + "Une erreur inattendue s'est produite dans l'application. Le rapport d'erreur est prêt à être envoyé à l'équipe de support. Cliquez sur Accepter pour envoyer le rapport d'erreur ou sur Annuler pour rejeter le rapport.", + dialogReportModeAccept: "Acceptez", + dialogReportModeCancel: "Annuler", + pageReportModeTitle: "Fracas", + pageReportModeDescription: + "Une erreur inattendue s'est produite dans l'application. Le rapport d'erreur est prêt à être envoyé à l'équipe de support. Cliquez sur Accepter pour envoyer le rapport d'erreur ou sur Annuler pour rejeter le rapport.", + pageReportModeAccept: "Acceptez", + pageReportModeCancel: "Annuler"); + } + + static LocalizationOptions buildDefaultPolishOptions() { + return LocalizationOptions("pl", + notificationReportModeTitle: "Wystąpił błąd aplikacji", + notificationReportModeContent: + "Naciśnij tutaj aby wysłać raport do zespołu wpsarcia", + dialogReportModeTitle: "Błąd aplikacji", + dialogReportModeDescription: + "Wystąpił niespodziewany błąd aplikacji. Raport z błędem jest gotowy do wysłania do zespołu wsparcia. Naciśnij akceptuj aby wysłać raport lub odrzuć aby odrzucić raport.", + dialogReportModeAccept: "Akceptuj", + dialogReportModeCancel: "Odrzuć", + pageReportModeTitle: "Błąd aplikacji", + pageReportModeDescription: + "Wystąpił niespodziewany błąd aplikacji. Raport z błędem jest gotowy do wysłania do zespołu wsparcia. Naciśnij akceptuj aby wysłać raport lub odrzuć aby odrzucić raport.", + pageReportModeAccept: "Akceptuj", + pageReportModeCancel: "Odrzuć"); + } + + + +} diff --git a/lib/model/report.dart b/lib/model/report.dart index a00635d2..d898167d 100644 --- a/lib/model/report.dart +++ b/lib/model/report.dart @@ -1,6 +1,6 @@ class Report { final dynamic error; - final StackTrace stackTrace; + final dynamic stackTrace; final DateTime dateTime; final Map deviceParameters; final Map applicationParameters; diff --git a/lib/model/report_mode.dart b/lib/model/report_mode.dart index 06355dc3..a2f8807a 100644 --- a/lib/model/report_mode.dart +++ b/lib/model/report_mode.dart @@ -1,12 +1,15 @@ import 'package:catcher/mode/report_mode_action_confirmed.dart'; +import 'package:catcher/model/localization_options.dart'; import 'package:catcher/model/report.dart'; import 'package:flutter/widgets.dart'; abstract class ReportMode { ReportModeAction _reportModeAction; + LocalizationOptions _localizationOptions; - setReportModeAction(ReportModeAction reportModeAction) { + void initialize(ReportModeAction reportModeAction, LocalizationOptions localizationOptions){ this._reportModeAction = reportModeAction; + this._localizationOptions = localizationOptions; } void requestAction(Report report, BuildContext context); @@ -18,4 +21,6 @@ abstract class ReportMode { void onActionRejected(Report report) { _reportModeAction.onActionRejected(report); } + + LocalizationOptions get localizationOptions => _localizationOptions; } diff --git a/pubspec.yaml b/pubspec.yaml index a6a2bb11..bc0d3143 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: catcher description: Plugin for error catching. Allows handling errors when they're not catched by developer. Plugin provides multiple handlers for errors. -version: 0.0.12 +version: 0.1.0 author: Jakub Homlala homepage: https://github.com/jhomlala/catcher