Skip to content

Commit

Permalink
chore(localizations): improve success and error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
EchoEllet committed Dec 2, 2024
1 parent bb45e33 commit 5221d8d
Show file tree
Hide file tree
Showing 45 changed files with 1,252 additions and 64 deletions.
14 changes: 6 additions & 8 deletions flutter_quill_extensions/lib/src/editor/image/image_menu.dart
Original file line number Diff line number Diff line change
Expand Up @@ -157,23 +157,22 @@ class ImageOptionsMenu extends StatelessWidget {
if (result == null) {
messenger.showSnackBar(SnackBar(
content: Text(
localizations.errorWhileSavingImage,
localizations.errorUnexpectedSavingImage,
)));
return;
}

if (kIsWeb) {
messenger.showSnackBar(SnackBar(
content: Text(localizations.savedUsingTheNetwork)));
content: Text(localizations.successImageDownloaded)));
return;
}

if (result.isGallerySave) {
// TODO(save-image): Improve all messages in here
messenger.showSnackBar(SnackBar(
content: Text(localizations.saved),
content: Text(localizations.successImageSavedGallery),
action: SnackBarAction(
label: localizations.open,
label: localizations.openGallery,
onPressed: () =>
QuillNativeProvider.instance.openGalleryApp(),
),
Expand All @@ -190,10 +189,9 @@ class ImageOptionsMenu extends StatelessWidget {

messenger.showSnackBar(
SnackBar(
content: Text(
localizations.theImageHasBeenSavedAt(imageFilePath)),
content: Text(localizations.successImageSaved),
action: SnackBarAction(
label: localizations.open,
label: localizations.openFileLocation,
onPressed: () => launchUrl(Uri.file(imageFilePath)),
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,37 @@ void main() {
);
});

if (kIsWeb) {
testWidgets(
'shows a success message when the image downloaded on the web',
(tester) async {
mockSaveImageResult(const SaveImageResult(
imageFilePath: null, isGallerySave: false));

await pumpTargetWidget(tester);
await tapTargetWidget(tester);

final localizations =
tester.localizationsFromElement(ImageOptionsMenu);

expect(
find.text(localizations.successImageDownloaded),
findsOneWidget,
);
},
);
}

testWidgets('shows error message when saving fails', (tester) async {
mockSaveImageResult(null);

await pumpTargetWidget(tester);

final saveButtonFinder = findTargetWidget();

await tester.tap(saveButtonFinder);
await tester.pump();
await tapTargetWidget(tester);

final localizations = tester.localizationsFromElement(ImageOptionsMenu);

expect(
find.text(localizations.errorWhileSavingImage),
find.text(localizations.errorUnexpectedSavingImage),
findsOneWidget,
);

Expand All @@ -117,19 +134,19 @@ void main() {
final localizations = tester.localizationsFromElement(ImageOptionsMenu);

expect(
find.text(localizations.saved),
find.text(localizations.successImageSavedGallery),
findsOneWidget,
);

expect(
find.text(localizations.open),
find.text(localizations.openGallery),
findsOneWidget,
);
});

for (final desktopPlatform in TargetPlatformVariant.desktop().values) {
testWidgets(
'shows saved file path and open desktop path on ${desktopPlatform.name}',
'shows saved success image and open file path action on ${desktopPlatform.name}',
(tester) async {
debugDefaultTargetPlatformOverride = desktopPlatform;

Expand All @@ -144,12 +161,12 @@ void main() {
tester.localizationsFromElement(ImageOptionsMenu);

expect(
find.text(localizations.theImageHasBeenSavedAt(savedImagePath)),
find.text(localizations.successImageSaved),
findsOneWidget,
);

expect(
find.text(localizations.open),
find.text(localizations.openFileLocation),
findsOneWidget,
);

Expand Down
36 changes: 36 additions & 0 deletions lib/src/l10n/generated/quill_localizations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,42 @@ abstract class FlutterQuillLocalizations {
/// In en, this message translates to:
/// **'Insert video'**
String get insertVideo;

/// A generic error message shown when an image cannot be saved due to an unknown issue.
///
/// In en, this message translates to:
/// **'An unexpected error occurred while saving the image. Please try again.'**
String get errorUnexpectedSavingImage;

/// Message shown on mobile when an image is successfully saved to the gallery.
///
/// In en, this message translates to:
/// **'Image saved to your gallery.'**
String get successImageSavedGallery;

/// Message shown on desktop when an image is successfully saved. The user is prompted to open the file location.
///
/// In en, this message translates to:
/// **'Image saved successfully.'**
String get successImageSaved;

/// Message shown on web when an image is successfully downloaded.
///
/// In en, this message translates to:
/// **'Image downloaded successfully.'**
String get successImageDownloaded;

/// Label for the button that opens the system gallery app.
///
/// In en, this message translates to:
/// **'Open Gallery'**
String get openGallery;

/// Label for the button that opens the file explorer to the file's location.
///
/// In en, this message translates to:
/// **'Open File Location'**
String get openFileLocation;
}

class _FlutterQuillLocalizationsDelegate
Expand Down
21 changes: 21 additions & 0 deletions lib/src/l10n/generated/quill_localizations_ar.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// ignore: unused_import
import 'package:intl/intl.dart' as intl;
import 'quill_localizations.dart';

// ignore_for_file: type=lint
Expand Down Expand Up @@ -302,4 +304,23 @@ class FlutterQuillLocalizationsAr extends FlutterQuillLocalizations {

@override
String get insertVideo => 'Insert video';

@override
String get errorUnexpectedSavingImage =>
'An unexpected error occurred while saving the image. Please try again.';

@override
String get successImageSavedGallery => 'Image saved to your gallery.';

@override
String get successImageSaved => 'Image saved successfully.';

@override
String get successImageDownloaded => 'Image downloaded successfully.';

@override
String get openGallery => 'Open Gallery';

@override
String get openFileLocation => 'Open File Location';
}
21 changes: 21 additions & 0 deletions lib/src/l10n/generated/quill_localizations_bg.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// ignore: unused_import
import 'package:intl/intl.dart' as intl;
import 'quill_localizations.dart';

// ignore_for_file: type=lint
Expand Down Expand Up @@ -304,4 +306,23 @@ class FlutterQuillLocalizationsBg extends FlutterQuillLocalizations {

@override
String get insertVideo => 'Insert video';

@override
String get errorUnexpectedSavingImage =>
'An unexpected error occurred while saving the image. Please try again.';

@override
String get successImageSavedGallery => 'Image saved to your gallery.';

@override
String get successImageSaved => 'Image saved successfully.';

@override
String get successImageDownloaded => 'Image downloaded successfully.';

@override
String get openGallery => 'Open Gallery';

@override
String get openFileLocation => 'Open File Location';
}
21 changes: 21 additions & 0 deletions lib/src/l10n/generated/quill_localizations_bn.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// ignore: unused_import
import 'package:intl/intl.dart' as intl;
import 'quill_localizations.dart';

// ignore_for_file: type=lint
Expand Down Expand Up @@ -310,4 +312,23 @@ class FlutterQuillLocalizationsBn extends FlutterQuillLocalizations {

@override
String get insertVideo => 'Insert video';

@override
String get errorUnexpectedSavingImage =>
'An unexpected error occurred while saving the image. Please try again.';

@override
String get successImageSavedGallery => 'Image saved to your gallery.';

@override
String get successImageSaved => 'Image saved successfully.';

@override
String get successImageDownloaded => 'Image downloaded successfully.';

@override
String get openGallery => 'Open Gallery';

@override
String get openFileLocation => 'Open File Location';
}
21 changes: 21 additions & 0 deletions lib/src/l10n/generated/quill_localizations_ca.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// ignore: unused_import
import 'package:intl/intl.dart' as intl;
import 'quill_localizations.dart';

// ignore_for_file: type=lint
Expand Down Expand Up @@ -306,4 +308,23 @@ class FlutterQuillLocalizationsCa extends FlutterQuillLocalizations {

@override
String get insertVideo => 'Insert video';

@override
String get errorUnexpectedSavingImage =>
'An unexpected error occurred while saving the image. Please try again.';

@override
String get successImageSavedGallery => 'Image saved to your gallery.';

@override
String get successImageSaved => 'Image saved successfully.';

@override
String get successImageDownloaded => 'Image downloaded successfully.';

@override
String get openGallery => 'Open Gallery';

@override
String get openFileLocation => 'Open File Location';
}
21 changes: 21 additions & 0 deletions lib/src/l10n/generated/quill_localizations_cs.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// ignore: unused_import
import 'package:intl/intl.dart' as intl;
import 'quill_localizations.dart';

// ignore_for_file: type=lint
Expand Down Expand Up @@ -304,4 +306,23 @@ class FlutterQuillLocalizationsCs extends FlutterQuillLocalizations {

@override
String get insertVideo => 'Insert video';

@override
String get errorUnexpectedSavingImage =>
'An unexpected error occurred while saving the image. Please try again.';

@override
String get successImageSavedGallery => 'Image saved to your gallery.';

@override
String get successImageSaved => 'Image saved successfully.';

@override
String get successImageDownloaded => 'Image downloaded successfully.';

@override
String get openGallery => 'Open Gallery';

@override
String get openFileLocation => 'Open File Location';
}
21 changes: 21 additions & 0 deletions lib/src/l10n/generated/quill_localizations_da.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// ignore: unused_import
import 'package:intl/intl.dart' as intl;
import 'quill_localizations.dart';

// ignore_for_file: type=lint
Expand Down Expand Up @@ -302,4 +304,23 @@ class FlutterQuillLocalizationsDa extends FlutterQuillLocalizations {

@override
String get insertVideo => 'Insert video';

@override
String get errorUnexpectedSavingImage =>
'An unexpected error occurred while saving the image. Please try again.';

@override
String get successImageSavedGallery => 'Image saved to your gallery.';

@override
String get successImageSaved => 'Image saved successfully.';

@override
String get successImageDownloaded => 'Image downloaded successfully.';

@override
String get openGallery => 'Open Gallery';

@override
String get openFileLocation => 'Open File Location';
}
21 changes: 21 additions & 0 deletions lib/src/l10n/generated/quill_localizations_de.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// ignore: unused_import
import 'package:intl/intl.dart' as intl;
import 'quill_localizations.dart';

// ignore_for_file: type=lint
Expand Down Expand Up @@ -308,4 +310,23 @@ class FlutterQuillLocalizationsDe extends FlutterQuillLocalizations {

@override
String get insertVideo => 'Insert video';

@override
String get errorUnexpectedSavingImage =>
'An unexpected error occurred while saving the image. Please try again.';

@override
String get successImageSavedGallery => 'Image saved to your gallery.';

@override
String get successImageSaved => 'Image saved successfully.';

@override
String get successImageDownloaded => 'Image downloaded successfully.';

@override
String get openGallery => 'Open Gallery';

@override
String get openFileLocation => 'Open File Location';
}
Loading

0 comments on commit 5221d8d

Please sign in to comment.