Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/i18n #7

Merged
merged 8 commits into from
Feb 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.1.0
* Finished basic API
* Added localization feature

## 0.0.12
* Fixed notification report mode bug

Expand Down
209 changes: 184 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
Expand Down Expand Up @@ -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<MyApp> {
@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:

Expand All @@ -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.

<p align="center">
<img width="250px" src="https://github.com/jhomlala/catcher/blob/master/screenshots/1.png"><br/>
<i>Notification Report Mode</i>
Expand All @@ -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.


<p align="center">
Expand All @@ -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.


<p align="center">
<img width="250px" src="https://github.com/jhomlala/catcher/blob/master/screenshots/7.png"><br/>
Expand Down
7 changes: 2 additions & 5 deletions example/lib/basic_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 {
Expand Down
83 changes: 83 additions & 0 deletions example/lib/localization_example.dart
Original file line number Diff line number Diff line change
@@ -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<MyApp> {
@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";
}
}
4 changes: 0 additions & 4 deletions example/lib/report_modes_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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()]);
Expand Down
2 changes: 2 additions & 0 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions lib/catcher_plugin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Loading