From 03b4fa4005f428f4e4ea1a371064d137a8ccf9f6 Mon Sep 17 00:00:00 2001 From: Jakub Homlala Date: Wed, 26 Jun 2024 22:32:20 +0200 Subject: [PATCH 01/16] feat: added translations implementation --- packages/alice/CHANGELOG.md | 2 +- .../alice/lib/model/alice_translation.dart | 18 ++++++++++ .../page/alice_call_details_page.dart | 2 +- .../widget/alice_call_error_screen.dart | 2 +- .../widget/alice_call_overview_screen.dart | 2 +- .../widget/alice_call_request_screen.dart | 2 +- .../widget/alice_call_response_screen.dart | 2 +- .../page/alice_calls_list_page.dart | 2 +- .../widget/alice_call_list_item_widget.dart | 2 +- .../widget/alice_calls_list_screen.dart | 2 +- .../widget/alice_empty_logs_widget.dart | 2 +- .../widget/alice_log_list_widget.dart | 4 +-- .../lib/ui/common/alice_context_ext.dart | 16 +++++++++ .../alice/lib/ui/common/alice_dialog.dart | 2 +- packages/alice/lib/ui/common/alice_page.dart | 2 +- .../common}/alice_scroll_behavior.dart | 0 .../lib/{utils => ui/common}/alice_theme.dart | 0 .../lib/ui/common/alice_translations.dart | 34 +++++++++++++++++++ 18 files changed, 82 insertions(+), 14 deletions(-) create mode 100644 packages/alice/lib/model/alice_translation.dart create mode 100644 packages/alice/lib/ui/common/alice_context_ext.dart rename packages/alice/lib/{utils => ui/common}/alice_scroll_behavior.dart (100%) rename packages/alice/lib/{utils => ui/common}/alice_theme.dart (100%) create mode 100644 packages/alice/lib/ui/common/alice_translations.dart diff --git a/packages/alice/CHANGELOG.md b/packages/alice/CHANGELOG.md index 29529b2d..bd21970d 100644 --- a/packages/alice/CHANGELOG.md +++ b/packages/alice/CHANGELOG.md @@ -1,4 +1,4 @@ -# 1.0.0-dev-7 +# 1.0.0-dev.7 * Refactored UI code. # 1.0.0-dev.6 diff --git a/packages/alice/lib/model/alice_translation.dart b/packages/alice/lib/model/alice_translation.dart new file mode 100644 index 00000000..0d7ab16e --- /dev/null +++ b/packages/alice/lib/model/alice_translation.dart @@ -0,0 +1,18 @@ +/// Definition of translations for specific locale +class AliceTranslationData { + final String languageCode; + final Map values; + + AliceTranslationData({ + required this.languageCode, + required this.values, + }); +} + +/// Translation keys +enum AliceTranslationKey { + callDetailsOverview, + callDetailsRequest, + callDetailsResponse, + callDetailsError +} diff --git a/packages/alice/lib/ui/call_details/page/alice_call_details_page.dart b/packages/alice/lib/ui/call_details/page/alice_call_details_page.dart index d664f924..885023dc 100644 --- a/packages/alice/lib/ui/call_details/page/alice_call_details_page.dart +++ b/packages/alice/lib/ui/call_details/page/alice_call_details_page.dart @@ -7,7 +7,7 @@ import 'package:alice/ui/call_details/widget/alice_call_overview_screen.dart'; import 'package:alice/ui/call_details/widget/alice_call_request_screen.dart'; import 'package:alice/ui/call_details/widget/alice_call_response_screen.dart'; import 'package:alice/ui/common/alice_page.dart'; -import 'package:alice/utils/alice_theme.dart'; +import 'package:alice/ui/common/alice_theme.dart'; import 'package:collection/collection.dart' show IterableExtension; import 'package:flutter/material.dart'; import 'package:share_plus/share_plus.dart'; diff --git a/packages/alice/lib/ui/call_details/widget/alice_call_error_screen.dart b/packages/alice/lib/ui/call_details/widget/alice_call_error_screen.dart index be744bb2..9ae9c572 100644 --- a/packages/alice/lib/ui/call_details/widget/alice_call_error_screen.dart +++ b/packages/alice/lib/ui/call_details/widget/alice_call_error_screen.dart @@ -1,7 +1,7 @@ import 'package:alice/model/alice_http_call.dart'; import 'package:alice/ui/call_details/widget/alice_call_expandable_list_row.dart'; import 'package:alice/ui/call_details/widget/alice_call_list_row.dart'; -import 'package:alice/utils/alice_scroll_behavior.dart'; +import 'package:alice/ui/common/alice_scroll_behavior.dart'; import 'package:flutter/material.dart'; /// Call error screen which displays info on HTTP call error. diff --git a/packages/alice/lib/ui/call_details/widget/alice_call_overview_screen.dart b/packages/alice/lib/ui/call_details/widget/alice_call_overview_screen.dart index 507320de..f18ba390 100644 --- a/packages/alice/lib/ui/call_details/widget/alice_call_overview_screen.dart +++ b/packages/alice/lib/ui/call_details/widget/alice_call_overview_screen.dart @@ -1,7 +1,7 @@ import 'package:alice/helper/alice_conversion_helper.dart'; import 'package:alice/model/alice_http_call.dart'; import 'package:alice/ui/call_details/widget/alice_call_list_row.dart'; -import 'package:alice/utils/alice_scroll_behavior.dart'; +import 'package:alice/ui/common/alice_scroll_behavior.dart'; import 'package:flutter/material.dart'; /// Screen which displays call overview data, for example method, server. diff --git a/packages/alice/lib/ui/call_details/widget/alice_call_request_screen.dart b/packages/alice/lib/ui/call_details/widget/alice_call_request_screen.dart index 017adbc6..8f227e26 100644 --- a/packages/alice/lib/ui/call_details/widget/alice_call_request_screen.dart +++ b/packages/alice/lib/ui/call_details/widget/alice_call_request_screen.dart @@ -4,7 +4,7 @@ import 'package:alice/model/alice_from_data_field.dart'; import 'package:alice/model/alice_http_call.dart'; import 'package:alice/ui/call_details/widget/alice_call_list_row.dart'; import 'package:alice/utils/alice_parser.dart'; -import 'package:alice/utils/alice_scroll_behavior.dart'; +import 'package:alice/ui/common/alice_scroll_behavior.dart'; import 'package:flutter/material.dart'; /// Screen which displays information about call request: content, transfer, diff --git a/packages/alice/lib/ui/call_details/widget/alice_call_response_screen.dart b/packages/alice/lib/ui/call_details/widget/alice_call_response_screen.dart index d9d9906b..2522d519 100644 --- a/packages/alice/lib/ui/call_details/widget/alice_call_response_screen.dart +++ b/packages/alice/lib/ui/call_details/widget/alice_call_response_screen.dart @@ -2,7 +2,7 @@ import 'package:alice/helper/alice_conversion_helper.dart'; import 'package:alice/model/alice_http_call.dart'; import 'package:alice/ui/call_details/widget/alice_call_list_row.dart'; import 'package:alice/utils/alice_parser.dart'; -import 'package:alice/utils/alice_scroll_behavior.dart'; +import 'package:alice/ui/common/alice_scroll_behavior.dart'; import 'package:alice/utils/num_comparison.dart'; import 'package:flutter/material.dart'; import 'package:url_launcher/url_launcher.dart'; diff --git a/packages/alice/lib/ui/calls_list/page/alice_calls_list_page.dart b/packages/alice/lib/ui/calls_list/page/alice_calls_list_page.dart index 79ae2bb0..6713f722 100644 --- a/packages/alice/lib/ui/calls_list/page/alice_calls_list_page.dart +++ b/packages/alice/lib/ui/calls_list/page/alice_calls_list_page.dart @@ -11,7 +11,7 @@ import 'package:alice/ui/common/alice_page.dart'; import 'package:alice/ui/calls_list/widget/alice_calls_list_screen.dart'; import 'package:alice/ui/calls_list/widget/alice_empty_logs_widget.dart'; import 'package:alice/ui/calls_list/widget/alice_logs_screen.dart'; -import 'package:alice/utils/alice_theme.dart'; +import 'package:alice/ui/common/alice_theme.dart'; import 'package:flutter/material.dart'; /// Page which displays list of calls caught by Alice. It displays tab view diff --git a/packages/alice/lib/ui/calls_list/widget/alice_call_list_item_widget.dart b/packages/alice/lib/ui/calls_list/widget/alice_call_list_item_widget.dart index c36ad100..3a780c8a 100644 --- a/packages/alice/lib/ui/calls_list/widget/alice_call_list_item_widget.dart +++ b/packages/alice/lib/ui/calls_list/widget/alice_call_list_item_widget.dart @@ -1,7 +1,7 @@ import 'package:alice/helper/alice_conversion_helper.dart'; import 'package:alice/model/alice_http_call.dart'; import 'package:alice/model/alice_http_response.dart'; -import 'package:alice/utils/alice_theme.dart'; +import 'package:alice/ui/common/alice_theme.dart'; import 'package:flutter/material.dart'; const int _endpointMaxLines = 10; diff --git a/packages/alice/lib/ui/calls_list/widget/alice_calls_list_screen.dart b/packages/alice/lib/ui/calls_list/widget/alice_calls_list_screen.dart index 3dfd2151..9ed7097e 100644 --- a/packages/alice/lib/ui/calls_list/widget/alice_calls_list_screen.dart +++ b/packages/alice/lib/ui/calls_list/widget/alice_calls_list_screen.dart @@ -1,7 +1,7 @@ import 'package:alice/model/alice_http_call.dart'; import 'package:alice/ui/calls_list/model/alice_calls_list_sort_option.dart'; import 'package:alice/ui/calls_list/widget/alice_call_list_item_widget.dart'; -import 'package:alice/utils/alice_scroll_behavior.dart'; +import 'package:alice/ui/common/alice_scroll_behavior.dart'; import 'package:flutter/material.dart'; /// Widget which displays calls list. It's hosted in tab in calls list page. diff --git a/packages/alice/lib/ui/calls_list/widget/alice_empty_logs_widget.dart b/packages/alice/lib/ui/calls_list/widget/alice_empty_logs_widget.dart index 282a5561..56df0104 100644 --- a/packages/alice/lib/ui/calls_list/widget/alice_empty_logs_widget.dart +++ b/packages/alice/lib/ui/calls_list/widget/alice_empty_logs_widget.dart @@ -1,4 +1,4 @@ -import 'package:alice/utils/alice_theme.dart'; +import 'package:alice/ui/common/alice_theme.dart'; import 'package:flutter/material.dart'; /// Widget which renders empty text for calls list. diff --git a/packages/alice/lib/ui/calls_list/widget/alice_log_list_widget.dart b/packages/alice/lib/ui/calls_list/widget/alice_log_list_widget.dart index 4058768d..a182fe5e 100644 --- a/packages/alice/lib/ui/calls_list/widget/alice_log_list_widget.dart +++ b/packages/alice/lib/ui/calls_list/widget/alice_log_list_widget.dart @@ -1,8 +1,8 @@ import 'dart:convert'; import 'package:alice/model/alice_log.dart'; -import 'package:alice/utils/alice_scroll_behavior.dart'; -import 'package:alice/utils/alice_theme.dart'; +import 'package:alice/ui/common/alice_scroll_behavior.dart'; +import 'package:alice/ui/common/alice_theme.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; diff --git a/packages/alice/lib/ui/common/alice_context_ext.dart b/packages/alice/lib/ui/common/alice_context_ext.dart new file mode 100644 index 00000000..ce270159 --- /dev/null +++ b/packages/alice/lib/ui/common/alice_context_ext.dart @@ -0,0 +1,16 @@ + import 'package:alice/model/alice_translation.dart'; +import 'package:alice/ui/common/alice_translations.dart'; +import 'package:flutter/material.dart'; + +extension AliceContextExt on BuildContext{ + String i18n(AliceTranslationKey key){ + try{ + final locale = Localizations.localeOf(this); + final languageCode = locale.languageCode; + return AliceTranslations.get(languageCode: languageCode, key: key); + + } catch (error){ + return key.toString(); + } + } +} \ No newline at end of file diff --git a/packages/alice/lib/ui/common/alice_dialog.dart b/packages/alice/lib/ui/common/alice_dialog.dart index 02ae6473..fa286045 100644 --- a/packages/alice/lib/ui/common/alice_dialog.dart +++ b/packages/alice/lib/ui/common/alice_dialog.dart @@ -1,4 +1,4 @@ -import 'package:alice/utils/alice_theme.dart'; +import 'package:alice/ui/common/alice_theme.dart'; import 'package:flutter/material.dart'; /// General dialogs used in Alice. diff --git a/packages/alice/lib/ui/common/alice_page.dart b/packages/alice/lib/ui/common/alice_page.dart index 1f4167e1..748815f6 100644 --- a/packages/alice/lib/ui/common/alice_page.dart +++ b/packages/alice/lib/ui/common/alice_page.dart @@ -1,5 +1,5 @@ import 'package:alice/core/alice_core.dart'; -import 'package:alice/utils/alice_theme.dart'; +import 'package:alice/ui/common/alice_theme.dart'; import 'package:flutter/material.dart'; /// Common page widget which is used across Alice pages. diff --git a/packages/alice/lib/utils/alice_scroll_behavior.dart b/packages/alice/lib/ui/common/alice_scroll_behavior.dart similarity index 100% rename from packages/alice/lib/utils/alice_scroll_behavior.dart rename to packages/alice/lib/ui/common/alice_scroll_behavior.dart diff --git a/packages/alice/lib/utils/alice_theme.dart b/packages/alice/lib/ui/common/alice_theme.dart similarity index 100% rename from packages/alice/lib/utils/alice_theme.dart rename to packages/alice/lib/ui/common/alice_theme.dart diff --git a/packages/alice/lib/ui/common/alice_translations.dart b/packages/alice/lib/ui/common/alice_translations.dart new file mode 100644 index 00000000..78d89f6a --- /dev/null +++ b/packages/alice/lib/ui/common/alice_translations.dart @@ -0,0 +1,34 @@ +import 'package:alice/model/alice_translation.dart'; + +class AliceTranslations { + static final List _translations = _initialise(); + + static List _initialise() { + List translations = []; + translations.add(_buildEnTranslations()); + return translations; + } + + static AliceTranslationData _buildEnTranslations() { + return AliceTranslationData(languageCode: "en", values: { + AliceTranslationKey.callDetailsRequest: "Request", + AliceTranslationKey.callDetailsResponse: "Response", + AliceTranslationKey.callDetailsOverview: "Overview", + AliceTranslationKey.callDetailsError: "Error", + }); + } + + static String get({ + required String languageCode, + required AliceTranslationKey key, + }) { + try { + final data = _translations + .firstWhere((element) => element.languageCode == languageCode); + final value = data.values[key] ?? key.toString(); + return value; + } catch (error) { + return key.toString(); + } + } +} From c46122efd02740ac6c08cd7d60a947cdb1558253 Mon Sep 17 00:00:00 2001 From: Jakub Homlala Date: Thu, 27 Jun 2024 07:43:29 +0200 Subject: [PATCH 02/16] feat: added translations --- .../alice/lib/model/alice_translation.dart | 31 +++++++++++- .../page/alice_call_details_page.dart | 33 +++++++++---- .../widget/alice_call_error_screen.dart | 22 ++++++--- .../widget/alice_call_overview_screen.dart | 25 ++++++---- .../widget/alice_call_request_screen.dart | 48 +++++++++++++------ .../lib/ui/common/alice_translations.dart | 29 +++++++++++ 6 files changed, 147 insertions(+), 41 deletions(-) diff --git a/packages/alice/lib/model/alice_translation.dart b/packages/alice/lib/model/alice_translation.dart index 0d7ab16e..5d4fbf84 100644 --- a/packages/alice/lib/model/alice_translation.dart +++ b/packages/alice/lib/model/alice_translation.dart @@ -11,8 +11,37 @@ class AliceTranslationData { /// Translation keys enum AliceTranslationKey { + alice, + callDetails, + emailSubject, callDetailsOverview, callDetailsRequest, callDetailsResponse, - callDetailsError + callDetailsError, + callDetailsEmpty, + callErrorScreenErrorEmpty, + callErrorScreenError, + callErrorScreenStacktrace, + callErrorScreenEmpty, + callOverviewMethod, + callOverviewServer, + callOverviewEndpoint, + callOverviewStarted, + callOverviewFinished, + callOverviewDuration, + callOverviewBytesSent, + callOverviewBytesReceived, + callOverviewClient, + callOverviewSecure, + callRequestStarted, + callRequestBytesSent, + callRequestContentType, + callRequestBody, + callRequestBodyEmpty, + callRequestFormDataFields, + callRequestFormDataFiles, + callRequestHeaders, + callRequestHeadersEmpty, + callRequestQueryParameters, + callRequestQueryParametersEmpty } diff --git a/packages/alice/lib/ui/call_details/page/alice_call_details_page.dart b/packages/alice/lib/ui/call_details/page/alice_call_details_page.dart index 885023dc..ae95973a 100644 --- a/packages/alice/lib/ui/call_details/page/alice_call_details_page.dart +++ b/packages/alice/lib/ui/call_details/page/alice_call_details_page.dart @@ -1,11 +1,13 @@ import 'package:alice/core/alice_core.dart'; import 'package:alice/helper/alice_save_helper.dart'; import 'package:alice/model/alice_http_call.dart'; +import 'package:alice/model/alice_translation.dart'; import 'package:alice/ui/call_details/model/alice_call_details_tab.dart'; import 'package:alice/ui/call_details/widget/alice_call_error_screen.dart'; import 'package:alice/ui/call_details/widget/alice_call_overview_screen.dart'; import 'package:alice/ui/call_details/widget/alice_call_request_screen.dart'; import 'package:alice/ui/call_details/widget/alice_call_response_screen.dart'; +import 'package:alice/ui/common/alice_context_ext.dart'; import 'package:alice/ui/common/alice_page.dart'; import 'package:alice/ui/common/alice_theme.dart'; import 'package:collection/collection.dart' show IterableExtension; @@ -60,7 +62,8 @@ class _AliceCallDetailsPageState extends State ); }).toList(), ), - title: const Text('Alice - HTTP Call Details'), + title: Text('${context.i18n(AliceTranslationKey.alice)} -' + ' ${context.i18n(AliceTranslationKey.callDetails)}'), ), body: TabBarView( children: [ @@ -74,10 +77,7 @@ class _AliceCallDetailsPageState extends State ? FloatingActionButton( backgroundColor: AliceTheme.lightRed, key: const Key('share_key'), - onPressed: () async => await Share.share( - await AliceSaveHelper.buildCallLog(widget.call), - subject: 'Request Details', - ), + onPressed: () async => _saveCallsToFile(), child: const Icon( Icons.share, color: AliceTheme.white, @@ -89,23 +89,36 @@ class _AliceCallDetailsPageState extends State } } - return const Center(child: Text('Failed to load data')); + return Center( + child: Text( + context.i18n( + AliceTranslationKey.callDetailsEmpty, + ), + ), + ); }, ), ); } + void _saveCallsToFile() async { + await Share.share( + await AliceSaveHelper.buildCallLog(widget.call), + subject: context.i18n(AliceTranslationKey.emailSubject), + ); + } + /// Get tab name based on [item] type. String _getTabName({required AliceCallDetailsTabItem item}) { switch (item) { case AliceCallDetailsTabItem.overview: - return "Overview"; + return context.i18n(AliceTranslationKey.callDetailsOverview); case AliceCallDetailsTabItem.request: - return "Request"; + return context.i18n(AliceTranslationKey.callDetailsRequest); case AliceCallDetailsTabItem.response: - return "Response"; + return context.i18n(AliceTranslationKey.callDetailsResponse); case AliceCallDetailsTabItem.error: - return "Error"; + return context.i18n(AliceTranslationKey.callDetailsError); } } diff --git a/packages/alice/lib/ui/call_details/widget/alice_call_error_screen.dart b/packages/alice/lib/ui/call_details/widget/alice_call_error_screen.dart index 9ae9c572..4e2fa401 100644 --- a/packages/alice/lib/ui/call_details/widget/alice_call_error_screen.dart +++ b/packages/alice/lib/ui/call_details/widget/alice_call_error_screen.dart @@ -1,6 +1,8 @@ import 'package:alice/model/alice_http_call.dart'; +import 'package:alice/model/alice_translation.dart'; import 'package:alice/ui/call_details/widget/alice_call_expandable_list_row.dart'; import 'package:alice/ui/call_details/widget/alice_call_list_row.dart'; +import 'package:alice/ui/common/alice_context_ext.dart'; import 'package:alice/ui/common/alice_scroll_behavior.dart'; import 'package:flutter/material.dart'; @@ -15,8 +17,9 @@ class AliceCallErrorScreen extends StatelessWidget { if (call.error != null) { final dynamic error = call.error?.error; final StackTrace? stackTrace = call.error?.stackTrace; - final String errorText = - error != null ? error.toString() : 'Error is empty'; + final String errorText = error != null + ? error.toString() + : context.i18n(AliceTranslationKey.callErrorScreenErrorEmpty); return Container( padding: const EdgeInsets.all(6), @@ -24,10 +27,13 @@ class AliceCallErrorScreen extends StatelessWidget { behavior: AliceScrollBehavior(), child: ListView( children: [ - AliceCallListRow(name: 'Error:', value: errorText), + AliceCallListRow( + name: context.i18n(AliceTranslationKey.callErrorScreenError), + value: errorText), if (stackTrace != null) AliceCallExpandableListRow( - name: 'Stack trace:', + name: context + .i18n(AliceTranslationKey.callErrorScreenStacktrace), value: stackTrace.toString(), ), ], @@ -35,8 +41,12 @@ class AliceCallErrorScreen extends StatelessWidget { ), ); } else { - return const Center( - child: Text('Nothing to display here'), + return Center( + child: Text( + context.i18n( + AliceTranslationKey.callErrorScreenEmpty, + ), + ), ); } } diff --git a/packages/alice/lib/ui/call_details/widget/alice_call_overview_screen.dart b/packages/alice/lib/ui/call_details/widget/alice_call_overview_screen.dart index f18ba390..a1f8f08d 100644 --- a/packages/alice/lib/ui/call_details/widget/alice_call_overview_screen.dart +++ b/packages/alice/lib/ui/call_details/widget/alice_call_overview_screen.dart @@ -1,12 +1,15 @@ import 'package:alice/helper/alice_conversion_helper.dart'; import 'package:alice/model/alice_http_call.dart'; +import 'package:alice/model/alice_translation.dart'; import 'package:alice/ui/call_details/widget/alice_call_list_row.dart'; +import 'package:alice/ui/common/alice_context_ext.dart'; import 'package:alice/ui/common/alice_scroll_behavior.dart'; import 'package:flutter/material.dart'; /// Screen which displays call overview data, for example method, server. class AliceCallOverviewScreen extends StatelessWidget { final AliceHttpCall call; + const AliceCallOverviewScreen({super.key, required this.call}); @override @@ -18,44 +21,46 @@ class AliceCallOverviewScreen extends StatelessWidget { child: ListView( children: [ AliceCallListRow( - name: 'Method: ', + name: context.i18n(AliceTranslationKey.callOverviewMethod), value: call.method, ), AliceCallListRow( - name: 'Server: ', + name: context.i18n(AliceTranslationKey.callOverviewServer), value: call.server, ), AliceCallListRow( - name: 'Endpoint: ', + name: context.i18n(AliceTranslationKey.callOverviewEndpoint), value: call.endpoint, ), AliceCallListRow( - name: 'Started:', + name: context.i18n(AliceTranslationKey.callOverviewStarted), value: call.request?.time.toString(), ), AliceCallListRow( - name: 'Finished:', + name: context.i18n(AliceTranslationKey.callOverviewFinished), value: call.response?.time.toString(), ), AliceCallListRow( - name: 'Duration:', + name: context.i18n(AliceTranslationKey.callOverviewDuration), value: AliceConversionHelper.formatTime(call.duration), ), AliceCallListRow( - name: 'Bytes sent:', + name: context.i18n(AliceTranslationKey.callOverviewBytesSent), value: AliceConversionHelper.formatBytes( call.request?.size ?? 0, ), ), AliceCallListRow( - name: 'Bytes received:', + name: context.i18n(AliceTranslationKey.callOverviewBytesReceived), value: AliceConversionHelper.formatBytes( call.response?.size ?? 0, ), ), - AliceCallListRow(name: 'Client:', value: call.client), AliceCallListRow( - name: 'Secure:', + name: context.i18n(AliceTranslationKey.callOverviewClient), + value: call.client), + AliceCallListRow( + name: context.i18n(AliceTranslationKey.callOverviewSecure), value: call.secure.toString(), ), ], diff --git a/packages/alice/lib/ui/call_details/widget/alice_call_request_screen.dart b/packages/alice/lib/ui/call_details/widget/alice_call_request_screen.dart index 8f227e26..d034a222 100644 --- a/packages/alice/lib/ui/call_details/widget/alice_call_request_screen.dart +++ b/packages/alice/lib/ui/call_details/widget/alice_call_request_screen.dart @@ -2,9 +2,12 @@ import 'package:alice/helper/alice_conversion_helper.dart'; import 'package:alice/model/alice_form_data_file.dart'; import 'package:alice/model/alice_from_data_field.dart'; import 'package:alice/model/alice_http_call.dart'; +import 'package:alice/model/alice_translation.dart'; import 'package:alice/ui/call_details/widget/alice_call_list_row.dart'; +import 'package:alice/ui/common/alice_context_ext.dart'; import 'package:alice/utils/alice_parser.dart'; import 'package:alice/ui/common/alice_scroll_behavior.dart'; +import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; /// Screen which displays information about call request: content, transfer, @@ -17,21 +20,30 @@ class AliceCallRequestScreen extends StatelessWidget { @override Widget build(BuildContext context) { final List rows = [ - AliceCallListRow(name: 'Started:', value: call.request?.time.toString()), AliceCallListRow( - name: 'Bytes sent:', + name: context.i18n(AliceTranslationKey.callRequestStarted), + value: call.request?.time.toString()), + AliceCallListRow( + name: context.i18n(AliceTranslationKey.callRequestBytesSent), value: AliceConversionHelper.formatBytes(call.request?.size ?? 0)), AliceCallListRow( - name: 'Content type:', + name: context.i18n(AliceTranslationKey.callRequestContentType), value: AliceBodyParser.getContentType(call.request?.headers)), ]; - rows.add(AliceCallListRow(name: 'Body:', value: _getBodyContent())); + rows.add(AliceCallListRow( + name: context.i18n(AliceTranslationKey.callRequestBody), + value: _getBodyContent( + context: context, + ), + )); final List? formDataFields = call.request?.formDataFields; if (formDataFields?.isNotEmpty ?? false) { - rows.add(const AliceCallListRow(name: 'Form data fields: ', value: '')); + rows.add(AliceCallListRow( + name: context.i18n(AliceTranslationKey.callRequestFormDataFields), + value: '')); rows.addAll([ for (final AliceFormDataField field in formDataFields!) AliceCallListRow(name: ' • ${field.name}:', value: field.value) @@ -40,7 +52,9 @@ class AliceCallRequestScreen extends StatelessWidget { final List? formDataFiles = call.request!.formDataFiles; if (formDataFiles?.isNotEmpty ?? false) { - rows.add(const AliceCallListRow(name: 'Form data files: ', value: '')); + rows.add(AliceCallListRow( + name: context.i18n(AliceTranslationKey.callRequestFormDataFiles), + value: '')); rows.addAll([ for (final AliceFormDataFile file in formDataFiles!) AliceCallListRow( @@ -51,9 +65,12 @@ class AliceCallRequestScreen extends StatelessWidget { } final Map? headers = call.request?.headers; - final String headersContent = - headers?.isEmpty ?? true ? 'Headers are empty' : ''; - rows.add(AliceCallListRow(name: 'Headers: ', value: headersContent)); + final String headersContent = headers?.isEmpty ?? true + ? context.i18n(AliceTranslationKey.callRequestHeadersEmpty) + : ''; + rows.add(AliceCallListRow( + name: context.i18n(AliceTranslationKey.callRequestHeaders), + value: headersContent)); rows.addAll([ for (final MapEntry header in headers?.entries ?? []) AliceCallListRow( @@ -61,10 +78,12 @@ class AliceCallRequestScreen extends StatelessWidget { ]); final Map? queryParameters = call.request?.queryParameters; - final String queryParametersContent = - queryParameters?.isEmpty ?? true ? 'Query parameters are empty' : ''; + final String queryParametersContent = queryParameters?.isEmpty ?? true + ? context.i18n(AliceTranslationKey.callRequestQueryParametersEmpty) + : ''; rows.add(AliceCallListRow( - name: 'Query Parameters: ', value: queryParametersContent)); + name: context.i18n(AliceTranslationKey.callRequestQueryParameters), + value: queryParametersContent)); rows.addAll([ for (final MapEntry queryParam in queryParameters?.entries ?? []) @@ -81,11 +100,12 @@ class AliceCallRequestScreen extends StatelessWidget { ); } - String _getBodyContent() { + /// Returns body content formatted. + String _getBodyContent({required BuildContext context}) { final dynamic body = call.request?.body; return body != null ? AliceBodyParser.formatBody( body, AliceBodyParser.getContentType(call.request?.headers)) - : 'Body is empty'; + : context.i18n(AliceTranslationKey.callRequestBodyEmpty); } } diff --git a/packages/alice/lib/ui/common/alice_translations.dart b/packages/alice/lib/ui/common/alice_translations.dart index 78d89f6a..3c602be2 100644 --- a/packages/alice/lib/ui/common/alice_translations.dart +++ b/packages/alice/lib/ui/common/alice_translations.dart @@ -11,10 +11,39 @@ class AliceTranslations { static AliceTranslationData _buildEnTranslations() { return AliceTranslationData(languageCode: "en", values: { + AliceTranslationKey.alice: "Alice", + AliceTranslationKey.callDetails: "HTTP Call Details", + AliceTranslationKey.emailSubject: "Alice report", AliceTranslationKey.callDetailsRequest: "Request", AliceTranslationKey.callDetailsResponse: "Response", AliceTranslationKey.callDetailsOverview: "Overview", AliceTranslationKey.callDetailsError: "Error", + AliceTranslationKey.callDetailsEmpty: "Loading data failed", + AliceTranslationKey.callErrorScreenErrorEmpty: "Error is empty", + AliceTranslationKey.callErrorScreenError: "Error:", + AliceTranslationKey.callErrorScreenStacktrace: "Stack trace:", + AliceTranslationKey.callErrorScreenEmpty: "Nothing to display here", + AliceTranslationKey.callOverviewMethod: "Method:", + AliceTranslationKey.callOverviewServer: "Server:", + AliceTranslationKey.callOverviewEndpoint: "Endpoint:", + AliceTranslationKey.callOverviewStarted: "Started:", + AliceTranslationKey.callOverviewFinished: "Finished:", + AliceTranslationKey.callOverviewDuration: "Duration:", + AliceTranslationKey.callOverviewBytesSent: "Bytes sent:", + AliceTranslationKey.callOverviewBytesReceived: "Bytes received:", + AliceTranslationKey.callOverviewClient: "Client:", + AliceTranslationKey.callOverviewSecure: "Secure:", + AliceTranslationKey.callRequestStarted: "Started:", + AliceTranslationKey.callRequestBytesSent: "Bytes sent:", + AliceTranslationKey.callRequestContentType:"Content type:", + AliceTranslationKey.callRequestBody:"Body:", + AliceTranslationKey.callRequestBodyEmpty:"Body is empty", + AliceTranslationKey.callRequestFormDataFields:"Form data fields:", + AliceTranslationKey.callRequestFormDataFiles:"Form files:", + AliceTranslationKey.callRequestHeaders:"Headers:", + AliceTranslationKey.callRequestHeadersEmpty:"Headers are empty", + AliceTranslationKey.callRequestQueryParameters:"Query parameters", + AliceTranslationKey.callRequestQueryParametersEmpty:"Query parameters are empty" }); } From ecf06fdaac56363a563f449d121e2996996d61d7 Mon Sep 17 00:00:00 2001 From: Jakub Homlala Date: Thu, 27 Jun 2024 08:47:18 +0200 Subject: [PATCH 03/16] feat: added translations --- .../alice/lib/model/alice_translation.dart | 19 +++- .../widget/alice_call_response_screen.dart | 88 +++++++++++------- .../lib/ui/common/alice_translations.dart | 89 ++++++++++++------- 3 files changed, 132 insertions(+), 64 deletions(-) diff --git a/packages/alice/lib/model/alice_translation.dart b/packages/alice/lib/model/alice_translation.dart index 5d4fbf84..65ef95d4 100644 --- a/packages/alice/lib/model/alice_translation.dart +++ b/packages/alice/lib/model/alice_translation.dart @@ -43,5 +43,22 @@ enum AliceTranslationKey { callRequestHeaders, callRequestHeadersEmpty, callRequestQueryParameters, - callRequestQueryParametersEmpty + callRequestQueryParametersEmpty, + callResponseWaitingForResponse, + callResponseError, + callResponseReceived, + callResponseBytesReceived, + callResponseStatus, + callResponseHeaders, + callResponseHeadersEmpty, + callResponseBodyImage, + callResponseBody, + callResponseTooLargeToShow, + callResponseBodyShow, + callResponseLargeBodyShowWarning, + callResponseBodyVideo, + callResponseBodyVideoWebBrowser, + callResponseHeadersUnknown, + callResponseBodyUnknown, + callResponseBodyUnknownShow, } diff --git a/packages/alice/lib/ui/call_details/widget/alice_call_response_screen.dart b/packages/alice/lib/ui/call_details/widget/alice_call_response_screen.dart index 2522d519..3ccb79d8 100644 --- a/packages/alice/lib/ui/call_details/widget/alice_call_response_screen.dart +++ b/packages/alice/lib/ui/call_details/widget/alice_call_response_screen.dart @@ -1,6 +1,8 @@ import 'package:alice/helper/alice_conversion_helper.dart'; import 'package:alice/model/alice_http_call.dart'; +import 'package:alice/model/alice_translation.dart'; import 'package:alice/ui/call_details/widget/alice_call_list_row.dart'; +import 'package:alice/ui/common/alice_context_ext.dart'; import 'package:alice/utils/alice_parser.dart'; import 'package:alice/ui/common/alice_scroll_behavior.dart'; import 'package:alice/utils/num_comparison.dart'; @@ -48,18 +50,21 @@ class _GeneralDataColumn extends StatelessWidget { @override Widget build(BuildContext context) { final int? status = call.response?.status; - final String statusText = status == -1 ? 'Error' : '$status'; + final String statusText = status == -1 + ? context.i18n(AliceTranslationKey.callResponseError) + : '$status'; return Column( children: [ AliceCallListRow( - name: 'Received:', value: call.response?.time.toString()), + name: context.i18n(AliceTranslationKey.callResponseReceived), + value: call.response?.time.toString()), AliceCallListRow( - name: 'Bytes received:', + name: context.i18n(AliceTranslationKey.callResponseBytesReceived), value: AliceConversionHelper.formatBytes(call.response?.size ?? 0), ), AliceCallListRow( - name: 'Status:', + name: context.i18n(AliceTranslationKey.callResponseStatus), value: statusText, ), ], @@ -75,12 +80,15 @@ class _HeaderDataColumn extends StatelessWidget { @override Widget build(BuildContext context) { final Map? headers = call.response?.headers; - final String headersContent = - headers?.isEmpty ?? true ? 'Headers are empty' : ''; + final String headersContent = headers?.isEmpty ?? true + ? context.i18n(AliceTranslationKey.callResponseHeadersEmpty) + : ''; return Column( children: [ - AliceCallListRow(name: 'Headers: ', value: headersContent), + AliceCallListRow( + name: context.i18n(AliceTranslationKey.callResponseHeaders), + value: headersContent), for (final MapEntry header in headers?.entries ?? []) AliceCallListRow( name: ' • ${header.key}:', @@ -192,11 +200,11 @@ class _ImageBody extends StatelessWidget { Widget build(BuildContext context) { return Column( children: [ - const Row( + Row( children: [ Text( - 'Body: Image', - style: TextStyle(fontWeight: FontWeight.bold), + context.i18n(AliceTranslationKey.callResponseBodyImage), + style: const TextStyle(fontWeight: FontWeight.bold), ), ], ), @@ -260,16 +268,25 @@ class _LargeTextBody extends StatelessWidget { } else { return Column(children: [ AliceCallListRow( - name: 'Body:', - value: 'Too large to show ' - '(${call.response?.body.toString().length ?? 0} Bytes)', + name: context.i18n(AliceTranslationKey.callResponseBody), + value: + '${context.i18n(AliceTranslationKey.callResponseTooLargeToShow)}' + '(${call.response?.body.toString().length ?? 0} B)', ), const SizedBox(height: 8), TextButton( onPressed: onShowLargeBodyPressed, - child: const Text('Show body'), + child: Text( + context.i18n( + AliceTranslationKey.callResponseBodyShow, + ), + ), + ), + Text( + context.i18n( + AliceTranslationKey.callResponseLargeBodyShowWarning, + ), ), - const Text('Warning! It will take some time to render output.') ]); } } @@ -285,7 +302,9 @@ class _TextBody extends StatelessWidget { final Map? headers = call.response?.headers; final String bodyContent = AliceBodyParser.formatBody( call.response?.body, AliceBodyParser.getContentType(headers)); - return AliceCallListRow(name: 'Body:', value: bodyContent); + return AliceCallListRow( + name: context.i18n(AliceTranslationKey.callResponseBody), + value: bodyContent); } } @@ -298,17 +317,18 @@ class _VideoBody extends StatelessWidget { Widget build(BuildContext context) { return Column( children: [ - const Row( + Row( children: [ Text( - 'Body: Video', - style: TextStyle(fontWeight: FontWeight.bold), + context.i18n(AliceTranslationKey.callResponseBodyVideo), + style: const TextStyle(fontWeight: FontWeight.bold), ), ], ), const SizedBox(height: 8), TextButton( - child: const Text('Open video in web browser'), + child: Text(context + .i18n(AliceTranslationKey.callResponseBodyVideoWebBrowser)), onPressed: () async { await launchUrl(Uri.parse(call.uri)); }, @@ -332,26 +352,34 @@ class _UnknownBody extends StatelessWidget { @override Widget build(BuildContext context) { final Map? headers = call.response?.headers; - final String contentType = - AliceBodyParser.getContentType(headers) ?? ''; + final String contentType = AliceBodyParser.getContentType(headers) ?? + context.i18n(AliceTranslationKey.callResponseHeadersUnknown); if (showUnsupportedBody) { final bodyContent = AliceBodyParser.formatBody( call.response?.body, AliceBodyParser.getContentType(headers)); - return AliceCallListRow(name: 'Body:', value: bodyContent); + return AliceCallListRow( + name: context.i18n(AliceTranslationKey.callResponseBody), + value: bodyContent); } else { return Column( children: [ AliceCallListRow( - name: 'Body:', - value: - 'Unsupported body. Alice can render video/image/text body. ' - "Response has Content-Type: $contentType which can't be " - "handled. If you're feeling lucky you can try button below " - 'to try render body as text, but it may fail.'), + name: context.i18n(AliceTranslationKey.callResponseBody), + value: context + .i18n(AliceTranslationKey.callResponseBodyUnknown) + .replaceAll( + "[contentType]", + contentType, + ), + ), TextButton( onPressed: onShowUnsupportedBodyPressed, - child: const Text('Show unsupported body'), + child: Text( + context.i18n( + AliceTranslationKey.callResponseBodyUnknownShow, + ), + ), ), ], ); diff --git a/packages/alice/lib/ui/common/alice_translations.dart b/packages/alice/lib/ui/common/alice_translations.dart index 3c602be2..6961eaad 100644 --- a/packages/alice/lib/ui/common/alice_translations.dart +++ b/packages/alice/lib/ui/common/alice_translations.dart @@ -11,39 +11,62 @@ class AliceTranslations { static AliceTranslationData _buildEnTranslations() { return AliceTranslationData(languageCode: "en", values: { - AliceTranslationKey.alice: "Alice", - AliceTranslationKey.callDetails: "HTTP Call Details", - AliceTranslationKey.emailSubject: "Alice report", - AliceTranslationKey.callDetailsRequest: "Request", - AliceTranslationKey.callDetailsResponse: "Response", - AliceTranslationKey.callDetailsOverview: "Overview", - AliceTranslationKey.callDetailsError: "Error", - AliceTranslationKey.callDetailsEmpty: "Loading data failed", - AliceTranslationKey.callErrorScreenErrorEmpty: "Error is empty", - AliceTranslationKey.callErrorScreenError: "Error:", - AliceTranslationKey.callErrorScreenStacktrace: "Stack trace:", - AliceTranslationKey.callErrorScreenEmpty: "Nothing to display here", - AliceTranslationKey.callOverviewMethod: "Method:", - AliceTranslationKey.callOverviewServer: "Server:", - AliceTranslationKey.callOverviewEndpoint: "Endpoint:", - AliceTranslationKey.callOverviewStarted: "Started:", - AliceTranslationKey.callOverviewFinished: "Finished:", - AliceTranslationKey.callOverviewDuration: "Duration:", - AliceTranslationKey.callOverviewBytesSent: "Bytes sent:", - AliceTranslationKey.callOverviewBytesReceived: "Bytes received:", - AliceTranslationKey.callOverviewClient: "Client:", - AliceTranslationKey.callOverviewSecure: "Secure:", - AliceTranslationKey.callRequestStarted: "Started:", - AliceTranslationKey.callRequestBytesSent: "Bytes sent:", - AliceTranslationKey.callRequestContentType:"Content type:", - AliceTranslationKey.callRequestBody:"Body:", - AliceTranslationKey.callRequestBodyEmpty:"Body is empty", - AliceTranslationKey.callRequestFormDataFields:"Form data fields:", - AliceTranslationKey.callRequestFormDataFiles:"Form files:", - AliceTranslationKey.callRequestHeaders:"Headers:", - AliceTranslationKey.callRequestHeadersEmpty:"Headers are empty", - AliceTranslationKey.callRequestQueryParameters:"Query parameters", - AliceTranslationKey.callRequestQueryParametersEmpty:"Query parameters are empty" + AliceTranslationKey.alice: "Alice", + AliceTranslationKey.callDetails: "HTTP Call Details", + AliceTranslationKey.emailSubject: "Alice report", + AliceTranslationKey.callDetailsRequest: "Request", + AliceTranslationKey.callDetailsResponse: "Response", + AliceTranslationKey.callDetailsOverview: "Overview", + AliceTranslationKey.callDetailsError: "Error", + AliceTranslationKey.callDetailsEmpty: "Loading data failed", + AliceTranslationKey.callErrorScreenErrorEmpty: "Error is empty", + AliceTranslationKey.callErrorScreenError: "Error:", + AliceTranslationKey.callErrorScreenStacktrace: "Stack trace:", + AliceTranslationKey.callErrorScreenEmpty: "Nothing to display here", + AliceTranslationKey.callOverviewMethod: "Method:", + AliceTranslationKey.callOverviewServer: "Server:", + AliceTranslationKey.callOverviewEndpoint: "Endpoint:", + AliceTranslationKey.callOverviewStarted: "Started:", + AliceTranslationKey.callOverviewFinished: "Finished:", + AliceTranslationKey.callOverviewDuration: "Duration:", + AliceTranslationKey.callOverviewBytesSent: "Bytes sent:", + AliceTranslationKey.callOverviewBytesReceived: "Bytes received:", + AliceTranslationKey.callOverviewClient: "Client:", + AliceTranslationKey.callOverviewSecure: "Secure:", + AliceTranslationKey.callRequestStarted: "Started:", + AliceTranslationKey.callRequestBytesSent: "Bytes sent:", + AliceTranslationKey.callRequestContentType: "Content type:", + AliceTranslationKey.callRequestBody: "Body:", + AliceTranslationKey.callRequestBodyEmpty: "Body is empty", + AliceTranslationKey.callRequestFormDataFields: "Form data fields:", + AliceTranslationKey.callRequestFormDataFiles: "Form files:", + AliceTranslationKey.callRequestHeaders: "Headers:", + AliceTranslationKey.callRequestHeadersEmpty: "Headers are empty", + AliceTranslationKey.callRequestQueryParameters: "Query parameters", + AliceTranslationKey.callRequestQueryParametersEmpty: + "Query parameters are empty", + AliceTranslationKey.callResponseWaitingForResponse: + "Awaiting response...", + AliceTranslationKey.callResponseError: "Error", + AliceTranslationKey.callResponseReceived: "Received", + AliceTranslationKey.callResponseBytesReceived: "Bytes received:", + AliceTranslationKey.callResponseStatus: "Status:", + AliceTranslationKey.callResponseHeaders: "Headers:", + AliceTranslationKey.callResponseHeadersEmpty: "Headers are empty", + AliceTranslationKey.callResponseBodyImage: "Body: Image", + AliceTranslationKey.callResponseBody: "Body:", + AliceTranslationKey.callResponseTooLargeToShow: "Too large to show", + AliceTranslationKey.callResponseBodyShow: "Show body", + AliceTranslationKey.callResponseLargeBodyShowWarning: + 'Warning! It will take some time to render output.', + AliceTranslationKey.callResponseBodyVideo: 'Body: Video', + AliceTranslationKey.callResponseBodyVideoWebBrowser: 'Open video in web browser', + AliceTranslationKey.callResponseHeadersUnknown: "Unknown", + AliceTranslationKey.callResponseBodyUnknown: 'Unsupported body. Alice' + ' can render video/image/text body. Response has Content-Type: ' + "[contentType] which can't be handled. If you're feeling lucky you " + "can try button below to try render body as text, but it may fail.", + AliceTranslationKey.callResponseBodyUnknownShow:"Show unsupported body", }); } From 9e9b987a913fb386e9b520ba1b940863a202f2ca Mon Sep 17 00:00:00 2001 From: Jakub Homlala Date: Thu, 27 Jun 2024 08:59:12 +0200 Subject: [PATCH 04/16] feat: added translations --- .../alice/lib/model/alice_translation.dart | 14 ++ .../page/alice_calls_list_page.dart | 59 +++++--- .../lib/ui/common/alice_translations.dart | 128 ++++++++++-------- 3 files changed, 123 insertions(+), 78 deletions(-) diff --git a/packages/alice/lib/model/alice_translation.dart b/packages/alice/lib/model/alice_translation.dart index 65ef95d4..fa1d17c4 100644 --- a/packages/alice/lib/model/alice_translation.dart +++ b/packages/alice/lib/model/alice_translation.dart @@ -61,4 +61,18 @@ enum AliceTranslationKey { callResponseHeadersUnknown, callResponseBodyUnknown, callResponseBodyUnknownShow, + callsListInspector, + callsListLogger, + callsListDeleteLogsDialogTitle, + callsListDeleteLogsDialogDescription, + callsListYes, + callsListNo, + callsListDeleteCallsDialogTitle, + callsListDeleteCallsDialogDescription, + callsListSearchHint, + callsListSort, + callsListDelete, + callsListStats, + callsListSave, + } diff --git a/packages/alice/lib/ui/calls_list/page/alice_calls_list_page.dart b/packages/alice/lib/ui/calls_list/page/alice_calls_list_page.dart index 6713f722..ef7bec8e 100644 --- a/packages/alice/lib/ui/calls_list/page/alice_calls_list_page.dart +++ b/packages/alice/lib/ui/calls_list/page/alice_calls_list_page.dart @@ -1,10 +1,12 @@ import 'package:alice/core/alice_core.dart'; import 'package:alice/core/alice_logger.dart'; import 'package:alice/model/alice_http_call.dart'; +import 'package:alice/model/alice_translation.dart'; import 'package:alice/ui/call_details/model/alice_menu_item.dart'; import 'package:alice/ui/calls_list/model/alice_calls_list_sort_option.dart'; import 'package:alice/ui/calls_list/model/alice_calls_list_tab_item.dart'; import 'package:alice/ui/calls_list/widget/alice_sort_dialog.dart'; +import 'package:alice/ui/common/alice_context_ext.dart'; import 'package:alice/ui/common/alice_dialog.dart'; import 'package:alice/ui/common/alice_navigation.dart'; import 'package:alice/ui/common/alice_page.dart'; @@ -91,7 +93,11 @@ class _AliceCallsListPageState extends State textEditingController: _queryTextEditingController, onChanged: _updateSearchQuery, ) - : const Text('Alice'), + : Text( + context.i18n( + AliceTranslationKey.alice, + ), + ), actions: isLoggerTab ? [ IconButton( @@ -165,9 +171,9 @@ class _AliceCallsListPageState extends State String _getTabName({required AliceCallsListTabItem item}) { switch (item) { case AliceCallsListTabItem.inspector: - return "Inspector"; + return context.i18n(AliceTranslationKey.callsListInspector); case AliceCallsListTabItem.logger: - return "Logger"; + return context.i18n(AliceTranslationKey.callsListLogger); } } @@ -181,10 +187,11 @@ class _AliceCallsListPageState extends State /// user confirmation. void _onClearLogsPressed() => AliceGeneralDialog.show( context: context, - title: 'Delete logs', - description: 'Do you want to clear logs?', - firstButtonTitle: 'No', - secondButtonTitle: 'Yes', + title: context.i18n(AliceTranslationKey.callsListDeleteLogsDialogTitle), + description: context + .i18n(AliceTranslationKey.callsListDeleteLogsDialogDescription), + firstButtonTitle: context.i18n(AliceTranslationKey.callsListNo), + secondButtonTitle: context.i18n(AliceTranslationKey.callsListYes), secondButtonAction: _onLogsClearPressed, ); @@ -202,7 +209,7 @@ class _AliceCallsListPageState extends State } }); - /// Called when search button. It displays search textfield. + /// Called when search button. It displays search text field. void _onSearchPressed() => setState(() { _searchEnabled = !_searchEnabled; if (!_searchEnabled) { @@ -242,11 +249,13 @@ class _AliceCallsListPageState extends State /// Called when remove all calls button has been pressed. void _onRemovePressed() => AliceGeneralDialog.show( context: context, - title: 'Delete calls', - description: 'Do you want to delete http calls?', - firstButtonTitle: 'No', + title: + context.i18n(AliceTranslationKey.callsListDeleteCallsDialogTitle), + description: context + .i18n(AliceTranslationKey.callsListDeleteCallsDialogDescription), + firstButtonTitle: context.i18n(AliceTranslationKey.callsListNo), firstButtonAction: () => {}, - secondButtonTitle: 'Yes', + secondButtonTitle: context.i18n(AliceTranslationKey.callsListYes), secondButtonAction: _removeCalls, ); @@ -323,9 +332,9 @@ class _SearchTextField extends StatelessWidget { return TextField( controller: textEditingController, autofocus: true, - decoration: const InputDecoration( - hintText: 'Search http request...', - hintStyle: TextStyle(fontSize: 16, color: AliceTheme.grey), + decoration: InputDecoration( + hintText: context.i18n(AliceTranslationKey.callsListSearchHint), + hintStyle: const TextStyle(fontSize: 16, color: AliceTheme.grey), border: InputBorder.none, ), style: const TextStyle(fontSize: 16), @@ -334,7 +343,7 @@ class _SearchTextField extends StatelessWidget { } } -/// Menu button displayed in app bar. It displays overflow menu with addtional +/// Menu button displayed in app bar. It displays overflow menu with additional /// actions. class _ContextMenuButton extends StatelessWidget { const _ContextMenuButton({required this.onMenuItemSelected}); @@ -359,7 +368,10 @@ class _ContextMenuButton extends StatelessWidget { const Padding( padding: EdgeInsets.only(left: 10), ), - Text(_getTitle(itemType: item)), + Text(_getTitle( + context: context, + itemType: item, + )), ], ), ), @@ -368,16 +380,19 @@ class _ContextMenuButton extends StatelessWidget { } /// Get title of the menu item based on [itemType]. - String _getTitle({required AliceCallDetailsMenuItemType itemType}) { + String _getTitle({ + required BuildContext context, + required AliceCallDetailsMenuItemType itemType, + }) { switch (itemType) { case AliceCallDetailsMenuItemType.sort: - return "Sort"; + return context.i18n(AliceTranslationKey.callsListSort); case AliceCallDetailsMenuItemType.delete: - return "Delete"; + return context.i18n(AliceTranslationKey.callsListDelete); case AliceCallDetailsMenuItemType.stats: - return "Stats"; + return context.i18n(AliceTranslationKey.callsListStats); case AliceCallDetailsMenuItemType.save: - return "Save"; + return context.i18n(AliceTranslationKey.callsListSave); } } diff --git a/packages/alice/lib/ui/common/alice_translations.dart b/packages/alice/lib/ui/common/alice_translations.dart index 6961eaad..14146b2f 100644 --- a/packages/alice/lib/ui/common/alice_translations.dart +++ b/packages/alice/lib/ui/common/alice_translations.dart @@ -11,62 +11,78 @@ class AliceTranslations { static AliceTranslationData _buildEnTranslations() { return AliceTranslationData(languageCode: "en", values: { - AliceTranslationKey.alice: "Alice", - AliceTranslationKey.callDetails: "HTTP Call Details", - AliceTranslationKey.emailSubject: "Alice report", - AliceTranslationKey.callDetailsRequest: "Request", - AliceTranslationKey.callDetailsResponse: "Response", - AliceTranslationKey.callDetailsOverview: "Overview", - AliceTranslationKey.callDetailsError: "Error", - AliceTranslationKey.callDetailsEmpty: "Loading data failed", - AliceTranslationKey.callErrorScreenErrorEmpty: "Error is empty", - AliceTranslationKey.callErrorScreenError: "Error:", - AliceTranslationKey.callErrorScreenStacktrace: "Stack trace:", - AliceTranslationKey.callErrorScreenEmpty: "Nothing to display here", - AliceTranslationKey.callOverviewMethod: "Method:", - AliceTranslationKey.callOverviewServer: "Server:", - AliceTranslationKey.callOverviewEndpoint: "Endpoint:", - AliceTranslationKey.callOverviewStarted: "Started:", - AliceTranslationKey.callOverviewFinished: "Finished:", - AliceTranslationKey.callOverviewDuration: "Duration:", - AliceTranslationKey.callOverviewBytesSent: "Bytes sent:", - AliceTranslationKey.callOverviewBytesReceived: "Bytes received:", - AliceTranslationKey.callOverviewClient: "Client:", - AliceTranslationKey.callOverviewSecure: "Secure:", - AliceTranslationKey.callRequestStarted: "Started:", - AliceTranslationKey.callRequestBytesSent: "Bytes sent:", - AliceTranslationKey.callRequestContentType: "Content type:", - AliceTranslationKey.callRequestBody: "Body:", - AliceTranslationKey.callRequestBodyEmpty: "Body is empty", - AliceTranslationKey.callRequestFormDataFields: "Form data fields:", - AliceTranslationKey.callRequestFormDataFiles: "Form files:", - AliceTranslationKey.callRequestHeaders: "Headers:", - AliceTranslationKey.callRequestHeadersEmpty: "Headers are empty", - AliceTranslationKey.callRequestQueryParameters: "Query parameters", - AliceTranslationKey.callRequestQueryParametersEmpty: - "Query parameters are empty", - AliceTranslationKey.callResponseWaitingForResponse: - "Awaiting response...", - AliceTranslationKey.callResponseError: "Error", - AliceTranslationKey.callResponseReceived: "Received", - AliceTranslationKey.callResponseBytesReceived: "Bytes received:", - AliceTranslationKey.callResponseStatus: "Status:", - AliceTranslationKey.callResponseHeaders: "Headers:", - AliceTranslationKey.callResponseHeadersEmpty: "Headers are empty", - AliceTranslationKey.callResponseBodyImage: "Body: Image", - AliceTranslationKey.callResponseBody: "Body:", - AliceTranslationKey.callResponseTooLargeToShow: "Too large to show", - AliceTranslationKey.callResponseBodyShow: "Show body", - AliceTranslationKey.callResponseLargeBodyShowWarning: - 'Warning! It will take some time to render output.', - AliceTranslationKey.callResponseBodyVideo: 'Body: Video', - AliceTranslationKey.callResponseBodyVideoWebBrowser: 'Open video in web browser', - AliceTranslationKey.callResponseHeadersUnknown: "Unknown", - AliceTranslationKey.callResponseBodyUnknown: 'Unsupported body. Alice' - ' can render video/image/text body. Response has Content-Type: ' - "[contentType] which can't be handled. If you're feeling lucky you " - "can try button below to try render body as text, but it may fail.", - AliceTranslationKey.callResponseBodyUnknownShow:"Show unsupported body", + AliceTranslationKey.alice: "Alice", + AliceTranslationKey.callDetails: "HTTP Call Details", + AliceTranslationKey.emailSubject: "Alice report", + AliceTranslationKey.callDetailsRequest: "Request", + AliceTranslationKey.callDetailsResponse: "Response", + AliceTranslationKey.callDetailsOverview: "Overview", + AliceTranslationKey.callDetailsError: "Error", + AliceTranslationKey.callDetailsEmpty: "Loading data failed", + AliceTranslationKey.callErrorScreenErrorEmpty: "Error is empty", + AliceTranslationKey.callErrorScreenError: "Error:", + AliceTranslationKey.callErrorScreenStacktrace: "Stack trace:", + AliceTranslationKey.callErrorScreenEmpty: "Nothing to display here", + AliceTranslationKey.callOverviewMethod: "Method:", + AliceTranslationKey.callOverviewServer: "Server:", + AliceTranslationKey.callOverviewEndpoint: "Endpoint:", + AliceTranslationKey.callOverviewStarted: "Started:", + AliceTranslationKey.callOverviewFinished: "Finished:", + AliceTranslationKey.callOverviewDuration: "Duration:", + AliceTranslationKey.callOverviewBytesSent: "Bytes sent:", + AliceTranslationKey.callOverviewBytesReceived: "Bytes received:", + AliceTranslationKey.callOverviewClient: "Client:", + AliceTranslationKey.callOverviewSecure: "Secure:", + AliceTranslationKey.callRequestStarted: "Started:", + AliceTranslationKey.callRequestBytesSent: "Bytes sent:", + AliceTranslationKey.callRequestContentType: "Content type:", + AliceTranslationKey.callRequestBody: "Body:", + AliceTranslationKey.callRequestBodyEmpty: "Body is empty", + AliceTranslationKey.callRequestFormDataFields: "Form data fields:", + AliceTranslationKey.callRequestFormDataFiles: "Form files:", + AliceTranslationKey.callRequestHeaders: "Headers:", + AliceTranslationKey.callRequestHeadersEmpty: "Headers are empty", + AliceTranslationKey.callRequestQueryParameters: "Query parameters", + AliceTranslationKey.callRequestQueryParametersEmpty: + "Query parameters are empty", + AliceTranslationKey.callResponseWaitingForResponse: + "Awaiting response...", + AliceTranslationKey.callResponseError: "Error", + AliceTranslationKey.callResponseReceived: "Received", + AliceTranslationKey.callResponseBytesReceived: "Bytes received:", + AliceTranslationKey.callResponseStatus: "Status:", + AliceTranslationKey.callResponseHeaders: "Headers:", + AliceTranslationKey.callResponseHeadersEmpty: "Headers are empty", + AliceTranslationKey.callResponseBodyImage: "Body: Image", + AliceTranslationKey.callResponseBody: "Body:", + AliceTranslationKey.callResponseTooLargeToShow: "Too large to show", + AliceTranslationKey.callResponseBodyShow: "Show body", + AliceTranslationKey.callResponseLargeBodyShowWarning: + 'Warning! It will take some time to render output.', + AliceTranslationKey.callResponseBodyVideo: 'Body: Video', + AliceTranslationKey.callResponseBodyVideoWebBrowser: + 'Open video in web browser', + AliceTranslationKey.callResponseHeadersUnknown: "Unknown", + AliceTranslationKey.callResponseBodyUnknown: 'Unsupported body. Alice' + ' can render video/image/text body. Response has Content-Type: ' + "[contentType] which can't be handled. If you're feeling lucky you " + "can try button below to try render body as text, but it may fail.", + AliceTranslationKey.callResponseBodyUnknownShow: "Show unsupported body", + AliceTranslationKey.callsListInspector: "Inspector", + AliceTranslationKey.callsListLogger: "Logger", + AliceTranslationKey.callsListDeleteLogsDialogTitle: "Delete logs", + AliceTranslationKey.callsListDeleteLogsDialogDescription: + "Do you want to clear logs?", + AliceTranslationKey.callsListYes: "Yes", + AliceTranslationKey.callsListNo: "No", + AliceTranslationKey.callsListDeleteCallsDialogTitle: "Delete calls", + AliceTranslationKey.callsListDeleteCallsDialogDescription: + "Do you want to delete http calls?", + AliceTranslationKey.callsListSearchHint: "Search http request...", + AliceTranslationKey.callsListSort: "Sort", + AliceTranslationKey.callsListDelete: "Delete", + AliceTranslationKey.callsListStats: "Stats", + AliceTranslationKey.callsListSave: "Save", }); } From 57e77b50260f767a4237f907478f32b222dc0dbd Mon Sep 17 00:00:00 2001 From: Jakub Homlala Date: Thu, 27 Jun 2024 09:25:54 +0200 Subject: [PATCH 05/16] feat: added translations --- .../alice/lib/model/alice_translation.dart | 14 +++++ .../widget/alice_empty_logs_widget.dart | 12 +++-- .../widget/alice_log_list_widget.dart | 21 ++++++-- .../widget/alice_raw_log_list_widger.dart | 10 +++- .../calls_list/widget/alice_sort_dialog.dart | 52 ++++++++++++++----- .../lib/ui/common/alice_translations.dart | 14 +++++ 6 files changed, 97 insertions(+), 26 deletions(-) diff --git a/packages/alice/lib/model/alice_translation.dart b/packages/alice/lib/model/alice_translation.dart index fa1d17c4..1b72cbcb 100644 --- a/packages/alice/lib/model/alice_translation.dart +++ b/packages/alice/lib/model/alice_translation.dart @@ -74,5 +74,19 @@ enum AliceTranslationKey { callsListDelete, callsListStats, callsListSave, + logsEmpty, + logsItemError, + logsItemStackTrace, + logsCopied, + sortDialogTitle, + sortDialogAscending, + sortDialogDescending, + sortDialogAccept, + sortDialogCancel, + sortDialogTime, + sortDialogResponseTime, + sortDialogResponseCode, + sortDialogResponseSize, + sortDialogEndpoint } diff --git a/packages/alice/lib/ui/calls_list/widget/alice_empty_logs_widget.dart b/packages/alice/lib/ui/calls_list/widget/alice_empty_logs_widget.dart index 56df0104..17283445 100644 --- a/packages/alice/lib/ui/calls_list/widget/alice_empty_logs_widget.dart +++ b/packages/alice/lib/ui/calls_list/widget/alice_empty_logs_widget.dart @@ -1,3 +1,5 @@ +import 'package:alice/model/alice_translation.dart'; +import 'package:alice/ui/common/alice_context_ext.dart'; import 'package:alice/ui/common/alice_theme.dart'; import 'package:flutter/material.dart'; @@ -11,18 +13,18 @@ class AliceEmptyLogsWidget extends StatelessWidget { Widget build(BuildContext context) { return Container( margin: const EdgeInsets.symmetric(horizontal: 32), - child: const Center( + child: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ - Icon( + const Icon( Icons.error_outline, color: AliceTheme.orange, ), - SizedBox(height: 6), + const SizedBox(height: 6), Text( - 'There are no logs to show', - style: TextStyle(fontSize: 18), + context.i18n(AliceTranslationKey.logsEmpty), + style: const TextStyle(fontSize: 18), ), ], ), diff --git a/packages/alice/lib/ui/calls_list/widget/alice_log_list_widget.dart b/packages/alice/lib/ui/calls_list/widget/alice_log_list_widget.dart index a182fe5e..2c83abce 100644 --- a/packages/alice/lib/ui/calls_list/widget/alice_log_list_widget.dart +++ b/packages/alice/lib/ui/calls_list/widget/alice_log_list_widget.dart @@ -1,6 +1,8 @@ import 'dart:convert'; import 'package:alice/model/alice_log.dart'; +import 'package:alice/model/alice_translation.dart'; +import 'package:alice/ui/common/alice_context_ext.dart'; import 'package:alice/ui/common/alice_scroll_behavior.dart'; import 'package:alice/ui/common/alice_theme.dart'; import 'package:flutter/foundation.dart'; @@ -83,10 +85,11 @@ class _AliceLogEntryWidget extends StatelessWidget { ), ), TextSpan(text: ' ${log.message}'), - ..._toText(context, 'Error', log.error), + ..._toText(context, context.i18n(AliceTranslationKey.logsItemError), + log.error), ..._toText( context, - 'Stack Trace', + context.i18n(AliceTranslationKey.logsItemStackTrace), log.stackTrace, addLineBreakAfterTitle: true, ), @@ -159,15 +162,23 @@ class _AliceLogEntryWidget extends StatelessWidget { final StringBuffer text = StringBuffer() ..writeAll([ '${log.timestamp}: ${log.message}\n', - if (error != null) 'Error: $error\n', - if (stackTrace != null) 'Stack Trace: $stackTrace\n', + if (error != null) + '${context.i18n(AliceTranslationKey.logsItemError)} $error\n', + if (stackTrace != null) + '${context.i18n(AliceTranslationKey.logsItemStackTrace)}: $stackTrace\n', ]); await Clipboard.setData(ClipboardData(text: text.toString())); if (context.mounted) { ScaffoldMessenger.of(context).showSnackBar( - const SnackBar(content: Text('Copied!')), + SnackBar( + content: Text( + context.i18n( + AliceTranslationKey.logsCopied, + ), + ), + ), ); } } diff --git a/packages/alice/lib/ui/calls_list/widget/alice_raw_log_list_widger.dart b/packages/alice/lib/ui/calls_list/widget/alice_raw_log_list_widger.dart index 2ab1a20a..58537d7f 100644 --- a/packages/alice/lib/ui/calls_list/widget/alice_raw_log_list_widger.dart +++ b/packages/alice/lib/ui/calls_list/widget/alice_raw_log_list_widger.dart @@ -1,3 +1,5 @@ +import 'package:alice/model/alice_translation.dart'; +import 'package:alice/ui/common/alice_context_ext.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; @@ -52,8 +54,12 @@ class AliceRawLogListWidget extends StatelessWidget { if (context.mounted) { ScaffoldMessenger.of(context).showSnackBar( - const SnackBar( - content: Text('Copied!'), + SnackBar( + content: Text( + context.i18n( + AliceTranslationKey.logsCopied, + ), + ), ), ); } diff --git a/packages/alice/lib/ui/calls_list/widget/alice_sort_dialog.dart b/packages/alice/lib/ui/calls_list/widget/alice_sort_dialog.dart index 6cba9274..e3ddf1b1 100644 --- a/packages/alice/lib/ui/calls_list/widget/alice_sort_dialog.dart +++ b/packages/alice/lib/ui/calls_list/widget/alice_sort_dialog.dart @@ -1,4 +1,6 @@ +import 'package:alice/model/alice_translation.dart'; import 'package:alice/ui/calls_list/model/alice_calls_list_sort_option.dart'; +import 'package:alice/ui/common/alice_context_ext.dart'; import 'package:flutter/material.dart'; /// Dialog which can be used to sort alice calls. @@ -23,15 +25,22 @@ class AliceSortDialog extends StatelessWidget { child: StatefulBuilder( builder: (context, setState) { return AlertDialog( - title: const Text('Select filter'), + title: Text( + context.i18n( + AliceTranslationKey.sortDialogTitle, + ), + ), content: Wrap( children: [ for (final AliceCallsListSortOption sortOption in AliceCallsListSortOption.values) RadioListTile( - title: Text(_getName( - option: sortOption, - )), + title: Text( + _getName( + context: context, + option: sortOption, + ), + ), value: sortOption, groupValue: currentSortOption, onChanged: (AliceCallsListSortOption? value) { @@ -45,7 +54,9 @@ class AliceSortDialog extends StatelessWidget { Row( mainAxisAlignment: MainAxisAlignment.center, children: [ - const Text('Descending'), + Text( + context.i18n(AliceTranslationKey.sortDialogDescending), + ), Switch( value: currentSortAscending, onChanged: (value) { @@ -56,7 +67,9 @@ class AliceSortDialog extends StatelessWidget { activeTrackColor: Colors.grey, activeColor: Colors.white, ), - const Text('Ascending'), + Text( + context.i18n(AliceTranslationKey.sortDialogAscending), + ), ], ), ], @@ -64,7 +77,9 @@ class AliceSortDialog extends StatelessWidget { actions: [ TextButton( onPressed: Navigator.of(context).pop, - child: const Text('Cancel'), + child: Text( + context.i18n(AliceTranslationKey.sortDialogCancel), + ), ), TextButton( onPressed: () { @@ -75,7 +90,9 @@ class AliceSortDialog extends StatelessWidget { ), ); }, - child: const Text('Use filter'), + child: Text( + context.i18n(AliceTranslationKey.sortDialogAccept), + ), ), ], ); @@ -85,13 +102,20 @@ class AliceSortDialog extends StatelessWidget { } /// Get sort option name based on [option]. - String _getName({required AliceCallsListSortOption option}) { + String _getName( + {required BuildContext context, + required AliceCallsListSortOption option}) { return switch (option) { - AliceCallsListSortOption.time => 'Create time (default)', - AliceCallsListSortOption.responseTime => 'Response time', - AliceCallsListSortOption.responseCode => 'Response code', - AliceCallsListSortOption.responseSize => 'Response size', - AliceCallsListSortOption.endpoint => 'Endpoint', + AliceCallsListSortOption.time => + context.i18n(AliceTranslationKey.sortDialogTime), + AliceCallsListSortOption.responseTime => + context.i18n(AliceTranslationKey.sortDialogResponseTime), + AliceCallsListSortOption.responseCode => + context.i18n(AliceTranslationKey.sortDialogResponseCode), + AliceCallsListSortOption.responseSize => + context.i18n(AliceTranslationKey.sortDialogResponseSize), + AliceCallsListSortOption.endpoint => + context.i18n(AliceTranslationKey.sortDialogEndpoint), }; } } diff --git a/packages/alice/lib/ui/common/alice_translations.dart b/packages/alice/lib/ui/common/alice_translations.dart index 14146b2f..d61051fb 100644 --- a/packages/alice/lib/ui/common/alice_translations.dart +++ b/packages/alice/lib/ui/common/alice_translations.dart @@ -83,6 +83,20 @@ class AliceTranslations { AliceTranslationKey.callsListDelete: "Delete", AliceTranslationKey.callsListStats: "Stats", AliceTranslationKey.callsListSave: "Save", + AliceTranslationKey.logsEmpty: "There are no logs to show", + AliceTranslationKey.logsItemError: "Error:", + AliceTranslationKey.logsItemStackTrace: "Stack trace:", + AliceTranslationKey.logsCopied: "Copied to clipboard.", + AliceTranslationKey.sortDialogTitle: "Select filter", + AliceTranslationKey.sortDialogAscending:'Ascending', + AliceTranslationKey.sortDialogDescending:"Descending", + AliceTranslationKey.sortDialogAccept:"Accept", + AliceTranslationKey.sortDialogCancel:"Cancel", + AliceTranslationKey.sortDialogTime:"Create time (default)", + AliceTranslationKey.sortDialogResponseTime:"Response time", + AliceTranslationKey.sortDialogResponseCode:"Response code", + AliceTranslationKey.sortDialogResponseSize:"Response size", + AliceTranslationKey.sortDialogEndpoint:"Endpoint" }); } From 2aa9275d99cdba3ab08ee26c4ceb4a95f280f164 Mon Sep 17 00:00:00 2001 From: Jakub Homlala Date: Thu, 27 Jun 2024 10:54:21 +0200 Subject: [PATCH 06/16] feat: added translations --- .../alice/lib/model/alice_translation.dart | 21 ++++++- .../lib/ui/common/alice_translations.dart | 36 +++++++++--- .../alice/lib/ui/stats/alice_stats_page.dart | 57 +++++++++++++------ 3 files changed, 86 insertions(+), 28 deletions(-) diff --git a/packages/alice/lib/model/alice_translation.dart b/packages/alice/lib/model/alice_translation.dart index 1b72cbcb..341834f7 100644 --- a/packages/alice/lib/model/alice_translation.dart +++ b/packages/alice/lib/model/alice_translation.dart @@ -87,6 +87,25 @@ enum AliceTranslationKey { sortDialogResponseTime, sortDialogResponseCode, sortDialogResponseSize, - sortDialogEndpoint + sortDialogEndpoint, + statsTitle, + statsTotalRequests, + statsPendingRequests, + statsSuccessRequests, + statsRedirectionRequests, + statsErrorRequests, + statsBytesSent, + statsBytesReceived, + statsAverageRequestTime, + statsMaxRequestTime, + statsMinRequestTime, + statsGetRequests, + statsPostRequests, + statsDeleteRequests, + statsPutRequests, + statsPatchRequests, + statsSecuredRequests, + statsUnsecuredRequests, + } diff --git a/packages/alice/lib/ui/common/alice_translations.dart b/packages/alice/lib/ui/common/alice_translations.dart index d61051fb..46a29011 100644 --- a/packages/alice/lib/ui/common/alice_translations.dart +++ b/packages/alice/lib/ui/common/alice_translations.dart @@ -88,15 +88,33 @@ class AliceTranslations { AliceTranslationKey.logsItemStackTrace: "Stack trace:", AliceTranslationKey.logsCopied: "Copied to clipboard.", AliceTranslationKey.sortDialogTitle: "Select filter", - AliceTranslationKey.sortDialogAscending:'Ascending', - AliceTranslationKey.sortDialogDescending:"Descending", - AliceTranslationKey.sortDialogAccept:"Accept", - AliceTranslationKey.sortDialogCancel:"Cancel", - AliceTranslationKey.sortDialogTime:"Create time (default)", - AliceTranslationKey.sortDialogResponseTime:"Response time", - AliceTranslationKey.sortDialogResponseCode:"Response code", - AliceTranslationKey.sortDialogResponseSize:"Response size", - AliceTranslationKey.sortDialogEndpoint:"Endpoint" + AliceTranslationKey.sortDialogAscending: 'Ascending', + AliceTranslationKey.sortDialogDescending: "Descending", + AliceTranslationKey.sortDialogAccept: "Accept", + AliceTranslationKey.sortDialogCancel: "Cancel", + AliceTranslationKey.sortDialogTime: "Create time (default)", + AliceTranslationKey.sortDialogResponseTime: "Response time", + AliceTranslationKey.sortDialogResponseCode: "Response code", + AliceTranslationKey.sortDialogResponseSize: "Response size", + AliceTranslationKey.sortDialogEndpoint: "Endpoint", + AliceTranslationKey.statsTitle: "Stats", + AliceTranslationKey.statsTotalRequests: "Total requests:", + AliceTranslationKey.statsPendingRequests: "Pending requests:", + AliceTranslationKey.statsSuccessRequests: "Success requests:", + AliceTranslationKey.statsRedirectionRequests: "Redirection requests:", + AliceTranslationKey.statsErrorRequests: "Error requests:", + AliceTranslationKey.statsBytesSent: "Bytes sent:", + AliceTranslationKey.statsBytesReceived: "Bytes received:", + AliceTranslationKey.statsAverageRequestTime: "Average request time:", + AliceTranslationKey.statsMaxRequestTime: "Max request time:", + AliceTranslationKey.statsMinRequestTime: "Min request time:", + AliceTranslationKey.statsGetRequests: "GET requests:", + AliceTranslationKey.statsPostRequests: "POST requests:", + AliceTranslationKey.statsDeleteRequests: "DELETE requests:", + AliceTranslationKey.statsPutRequests: "PUT requests:", + AliceTranslationKey.statsPatchRequests: "PATCH requests:", + AliceTranslationKey.statsSecuredRequests: "Secured requests:", + AliceTranslationKey.statsUnsecuredRequests: "Unsecured requests:", }); } diff --git a/packages/alice/lib/ui/stats/alice_stats_page.dart b/packages/alice/lib/ui/stats/alice_stats_page.dart index d139046e..b5617783 100644 --- a/packages/alice/lib/ui/stats/alice_stats_page.dart +++ b/packages/alice/lib/ui/stats/alice_stats_page.dart @@ -1,6 +1,8 @@ import 'package:alice/core/alice_core.dart'; import 'package:alice/helper/alice_conversion_helper.dart'; import 'package:alice/model/alice_http_call.dart'; +import 'package:alice/model/alice_translation.dart'; +import 'package:alice/ui/common/alice_context_ext.dart'; import 'package:alice/ui/common/alice_page.dart'; import 'package:alice/ui/widget/alice_stats_row.dart'; import 'package:alice/utils/num_comparison.dart'; @@ -21,48 +23,67 @@ class AliceStatsPage extends StatelessWidget { core: aliceCore, child: Scaffold( appBar: AppBar( - title: const Text('Alice - HTTP Inspector - Stats'), + title: Text('${context.i18n(AliceTranslationKey.alice)} - ' + '${context.i18n(AliceTranslationKey.statsTitle)}'), ), body: Container( padding: const EdgeInsets.all(8), child: ListView( children: [ - AliceStatsRow('Total requests:', '${_getTotalRequests()}'), - AliceStatsRow('Pending requests:', '${_getPendingRequests()}'), - AliceStatsRow('Success requests:', '${_getSuccessRequests()}'), AliceStatsRow( - 'Redirection requests:', + context.i18n(AliceTranslationKey.statsTotalRequests), + '${_getTotalRequests()}'), + AliceStatsRow( + context.i18n(AliceTranslationKey.statsPendingRequests), + '${_getPendingRequests()}'), + AliceStatsRow( + context.i18n(AliceTranslationKey.statsSuccessRequests), + '${_getSuccessRequests()}'), + AliceStatsRow( + context.i18n(AliceTranslationKey.statsRedirectionRequests), '${_getRedirectionRequests()}', ), - AliceStatsRow('Error requests:', '${_getErrorRequests()}'), AliceStatsRow( - 'Bytes send:', + context.i18n(AliceTranslationKey.statsErrorRequests), + '${_getErrorRequests()}'), + AliceStatsRow( + context.i18n(AliceTranslationKey.statsBytesSent), AliceConversionHelper.formatBytes(_getBytesSent()), ), AliceStatsRow( - 'Bytes received:', + context.i18n(AliceTranslationKey.statsBytesReceived), AliceConversionHelper.formatBytes(_getBytesReceived()), ), AliceStatsRow( - 'Average request time:', + context.i18n(AliceTranslationKey.statsAverageRequestTime), AliceConversionHelper.formatTime(_getAverageRequestTime()), ), AliceStatsRow( - 'Max request time:', + context.i18n(AliceTranslationKey.statsMaxRequestTime), AliceConversionHelper.formatTime(_getMaxRequestTime()), ), AliceStatsRow( - 'Min request time:', + context.i18n(AliceTranslationKey.statsMinRequestTime), AliceConversionHelper.formatTime(_getMinRequestTime()), ), - AliceStatsRow('Get requests:', '${_getRequests('GET')} '), - AliceStatsRow('Post requests:', '${_getRequests('POST')} '), - AliceStatsRow('Delete requests:', '${_getRequests('DELETE')} '), - AliceStatsRow('Put requests:', '${_getRequests('PUT')} '), - AliceStatsRow('Patch requests:', '${_getRequests('PATCH')} '), - AliceStatsRow('Secured requests:', '${_getSecuredRequests()}'), + AliceStatsRow(context.i18n(AliceTranslationKey.statsGetRequests), + '${_getRequests('GET')} '), + AliceStatsRow(context.i18n(AliceTranslationKey.statsPostRequests), + '${_getRequests('POST')} '), + AliceStatsRow( + context.i18n(AliceTranslationKey.statsDeleteRequests), + '${_getRequests('DELETE')} '), + AliceStatsRow(context.i18n(AliceTranslationKey.statsPutRequests), + '${_getRequests('PUT')} '), + AliceStatsRow( + context.i18n(AliceTranslationKey.statsPatchRequests), + '${_getRequests('PATCH')} '), + AliceStatsRow( + context.i18n(AliceTranslationKey.statsSecuredRequests), + '${_getSecuredRequests()}'), AliceStatsRow( - 'Unsecured requests:', '${_getUnsecuredRequests()}'), + context.i18n(AliceTranslationKey.statsUnsecuredRequests), + '${_getUnsecuredRequests()}'), ], ), ), From b9bb3871af099cacd9e4d327c7956911bf474bc8 Mon Sep 17 00:00:00 2001 From: Jakub Homlala Date: Thu, 27 Jun 2024 11:10:44 +0200 Subject: [PATCH 07/16] feat: added translations --- packages/alice/lib/core/alice_core.dart | 39 ++++++++++++++++--- .../common => core}/alice_translations.dart | 5 +++ .../alice/lib/model/alice_translation.dart | 6 ++- .../calls_list/widget/alice_sort_dialog.dart | 7 ++-- .../lib/ui/common/alice_context_ext.dart | 2 +- 5 files changed, 48 insertions(+), 11 deletions(-) rename packages/alice/lib/{ui/common => core}/alice_translations.dart (95%) diff --git a/packages/alice/lib/core/alice_core.dart b/packages/alice/lib/core/alice_core.dart index 12c88eee..0a895915 100644 --- a/packages/alice/lib/core/alice_core.dart +++ b/packages/alice/lib/core/alice_core.dart @@ -2,12 +2,15 @@ import 'dart:async' show StreamSubscription; import 'dart:io' show Platform; import 'package:alice/core/alice_logger.dart'; +import 'package:alice/core/alice_translations.dart'; import 'package:alice/core/alice_utils.dart'; import 'package:alice/helper/alice_save_helper.dart'; import 'package:alice/model/alice_http_call.dart'; import 'package:alice/model/alice_http_error.dart'; import 'package:alice/model/alice_http_response.dart'; import 'package:alice/model/alice_log.dart'; +import 'package:alice/model/alice_translation.dart'; +import 'package:alice/ui/common/alice_context_ext.dart'; import 'package:alice/ui/common/alice_navigation.dart'; import 'package:alice/utils/num_comparison.dart'; import 'package:alice/utils/shake_detector.dart'; @@ -119,7 +122,6 @@ class AliceCore { Future _onDidReceiveNotificationResponse( NotificationResponse response, ) async { - assert(response.payload != null, "payload can't be null"); navigateToCallListScreen(); } @@ -145,6 +147,22 @@ class AliceCore { BuildContext? getContext() => navigatorKey?.currentState?.overlay?.context; String _getNotificationMessage() { + final context = getContext(); + var loadingText = AliceTranslations.get( + languageCode: "en", key: AliceTranslationKey.notificationLoading); + var successText = AliceTranslations.get( + languageCode: "en", key: AliceTranslationKey.notificationSuccess); + var redirectText = AliceTranslations.get( + languageCode: "en", key: AliceTranslationKey.notificationRedirect); + var errorText = AliceTranslations.get( + languageCode: "en", key: AliceTranslationKey.notificationError); + if (context != null) { + loadingText = context.i18n(AliceTranslationKey.notificationLoading); + successText = context.i18n(AliceTranslationKey.notificationSuccess); + redirectText = context.i18n(AliceTranslationKey.notificationRedirect); + errorText = context.i18n(AliceTranslationKey.notificationError); + } + final List calls = callsSubject.value; final int successCalls = calls .where( @@ -177,24 +195,24 @@ class AliceCore { final StringBuffer notificationsMessage = StringBuffer(); if (loadingCalls > 0) { notificationsMessage.writeAll([ - 'Loading: $loadingCalls', + '$loadingText $loadingCalls', ' | ', ]); } if (successCalls > 0) { notificationsMessage.writeAll([ - 'Success: $successCalls', + '$successText $successCalls', ' | ', ]); } if (redirectCalls > 0) { notificationsMessage.writeAll([ - 'Redirect: $redirectCalls', + '$redirectText $redirectCalls', ' | ', ]); } if (errorCalls > 0) { - notificationsMessage.write('Error: $errorCalls'); + notificationsMessage.write('$errorText $errorCalls'); } String notificationMessageString = notificationsMessage.toString(); if (notificationMessageString.endsWith(' | ')) { @@ -256,9 +274,18 @@ class AliceCore { iOS: iOSPlatformChannelSpecifics, ); final String? message = _notificationMessage; + final context = getContext(); + var title = AliceTranslations.get( + languageCode: "en", key: AliceTranslationKey.notificationTotalRequests); + if (context != null) { + title = context + .i18n(AliceTranslationKey.notificationTotalRequests) + .replaceAll("[requestCount]", callsSubject.value.length.toString()); + } + await _flutterLocalNotificationsPlugin.show( 0, - 'Alice (total: ${callsSubject.value.length} requests)', + title, message, platformChannelSpecifics, payload: '', diff --git a/packages/alice/lib/ui/common/alice_translations.dart b/packages/alice/lib/core/alice_translations.dart similarity index 95% rename from packages/alice/lib/ui/common/alice_translations.dart rename to packages/alice/lib/core/alice_translations.dart index 46a29011..354e5639 100644 --- a/packages/alice/lib/ui/common/alice_translations.dart +++ b/packages/alice/lib/core/alice_translations.dart @@ -115,6 +115,11 @@ class AliceTranslations { AliceTranslationKey.statsPatchRequests: "PATCH requests:", AliceTranslationKey.statsSecuredRequests: "Secured requests:", AliceTranslationKey.statsUnsecuredRequests: "Unsecured requests:", + AliceTranslationKey.notificationLoading: "Loading:", + AliceTranslationKey.notificationSuccess: "Success:", + AliceTranslationKey.notificationRedirect: "Redirect:", + AliceTranslationKey.notificationError: "Error:", + AliceTranslationKey.notificationTotalRequests:"Alice (total [requestCount] requests)" }); } diff --git a/packages/alice/lib/model/alice_translation.dart b/packages/alice/lib/model/alice_translation.dart index 341834f7..19fbd70d 100644 --- a/packages/alice/lib/model/alice_translation.dart +++ b/packages/alice/lib/model/alice_translation.dart @@ -106,6 +106,10 @@ enum AliceTranslationKey { statsPatchRequests, statsSecuredRequests, statsUnsecuredRequests, - + notificationLoading, + notificationSuccess, + notificationRedirect, + notificationError, + notificationTotalRequests, } diff --git a/packages/alice/lib/ui/calls_list/widget/alice_sort_dialog.dart b/packages/alice/lib/ui/calls_list/widget/alice_sort_dialog.dart index e3ddf1b1..9614dc3a 100644 --- a/packages/alice/lib/ui/calls_list/widget/alice_sort_dialog.dart +++ b/packages/alice/lib/ui/calls_list/widget/alice_sort_dialog.dart @@ -102,9 +102,10 @@ class AliceSortDialog extends StatelessWidget { } /// Get sort option name based on [option]. - String _getName( - {required BuildContext context, - required AliceCallsListSortOption option}) { + String _getName({ + required BuildContext context, + required AliceCallsListSortOption option, + }) { return switch (option) { AliceCallsListSortOption.time => context.i18n(AliceTranslationKey.sortDialogTime), diff --git a/packages/alice/lib/ui/common/alice_context_ext.dart b/packages/alice/lib/ui/common/alice_context_ext.dart index ce270159..e451d9b5 100644 --- a/packages/alice/lib/ui/common/alice_context_ext.dart +++ b/packages/alice/lib/ui/common/alice_context_ext.dart @@ -1,5 +1,5 @@ import 'package:alice/model/alice_translation.dart'; -import 'package:alice/ui/common/alice_translations.dart'; +import 'package:alice/core/alice_translations.dart'; import 'package:flutter/material.dart'; extension AliceContextExt on BuildContext{ From 7b36553d8705e7a27816ebb3cf90b02491788da4 Mon Sep 17 00:00:00 2001 From: Jakub Homlala Date: Thu, 27 Jun 2024 13:16:33 +0200 Subject: [PATCH 08/16] feat: added translations --- .../alice/lib/core/alice_translations.dart | 45 ++++++- .../alice/lib/helper/alice_save_helper.dart | 120 ++++++++++-------- .../alice/lib/model/alice_translation.dart | 43 ++++++- .../page/alice_call_details_page.dart | 2 +- .../alice/lib/ui/common/alice_dialog.dart | 9 +- 5 files changed, 164 insertions(+), 55 deletions(-) diff --git a/packages/alice/lib/core/alice_translations.dart b/packages/alice/lib/core/alice_translations.dart index 354e5639..4573c94d 100644 --- a/packages/alice/lib/core/alice_translations.dart +++ b/packages/alice/lib/core/alice_translations.dart @@ -119,7 +119,50 @@ class AliceTranslations { AliceTranslationKey.notificationSuccess: "Success:", AliceTranslationKey.notificationRedirect: "Redirect:", AliceTranslationKey.notificationError: "Error:", - AliceTranslationKey.notificationTotalRequests:"Alice (total [requestCount] requests)" + AliceTranslationKey.notificationTotalRequests:"Alice (total [requestCount] requests)", + AliceTranslationKey.saveDialogPermissionErrorTitle :"Permission error", + AliceTranslationKey.saveDialogPermissionErrorDescription:"Permission not granted. Couldn't save logs.", + AliceTranslationKey.saveDialogEmptyErrorTitle:"Call history empty", + AliceTranslationKey.saveDialogEmptyErrorDescription:"There are no calls to save.", + AliceTranslationKey.saveDialogFileSaveErrorTitle:"Save error", + AliceTranslationKey.saveDialogFileSaveErrorDescription:"Failed to save http calls to fil", + AliceTranslationKey.saveSuccessTitle:"Logs saved", + AliceTranslationKey.saveSuccessDescription:"Successfully saved logs in [path].", + AliceTranslationKey.saveSuccessView:"View file", + AliceTranslationKey.saveHeaderTitle:"Alice - HTTP Inspector", + AliceTranslationKey.saveHeaderAppName:"App name:", + AliceTranslationKey.saveHeaderPackage:"Package:", + AliceTranslationKey.saveHeaderVersion:"Version:", + AliceTranslationKey.saveHeaderBuildNumber:"Build number:", + AliceTranslationKey.saveHeaderGenerated:"Generated:", + AliceTranslationKey.saveLogId:"Id:", + AliceTranslationKey.saveLogGeneralData:"General data", + AliceTranslationKey.saveLogServer:"Server:", + AliceTranslationKey.saveLogMethod:"Method:", + AliceTranslationKey.saveLogEndpoint:"Endpoint:", + AliceTranslationKey.saveLogClient:"Client:", + AliceTranslationKey.saveLogDuration:"Duration:", + AliceTranslationKey.saveLogSecured:"Secured connection:", + AliceTranslationKey.saveLogCompleted:"Completed:", + AliceTranslationKey.saveLogRequest:"Request", + AliceTranslationKey.saveLogRequestTime:"Request time:", + AliceTranslationKey.saveLogRequestContentType:"Request content type:", + AliceTranslationKey.saveLogRequestCookies:"Request cookies:", + AliceTranslationKey.saveLogRequestHeaders:"Request headers:", + AliceTranslationKey.saveLogRequestQueryParams:"Request query params:", + AliceTranslationKey.saveLogRequestSize:"Request size:", + AliceTranslationKey.saveLogRequestBody:"Request body:", + AliceTranslationKey.saveLogResponse:"Response", + AliceTranslationKey.saveLogResponseTime:"Response time:", + AliceTranslationKey.saveLogResponseStatus:"Response status:", + AliceTranslationKey.saveLogResponseSize:"Response size:", + AliceTranslationKey.saveLogResponseHeaders:"Response headers:", + AliceTranslationKey.saveLogResponseBody:"Response body:", + AliceTranslationKey.saveLogError:"Error", + AliceTranslationKey.saveLogStackTrace:"Stack trace", + AliceTranslationKey.saveLogCurl:"Curl", + AliceTranslationKey.accept:"Accept", + }); } diff --git a/packages/alice/lib/helper/alice_save_helper.dart b/packages/alice/lib/helper/alice_save_helper.dart index 23026f72..0b3716fe 100644 --- a/packages/alice/lib/helper/alice_save_helper.dart +++ b/packages/alice/lib/helper/alice_save_helper.dart @@ -5,8 +5,11 @@ import 'package:alice/core/alice_utils.dart'; import 'package:alice/helper/alice_conversion_helper.dart'; import 'package:alice/helper/operating_system.dart'; import 'package:alice/model/alice_http_call.dart'; +import 'package:alice/model/alice_translation.dart'; +import 'package:alice/ui/common/alice_context_ext.dart'; import 'package:alice/ui/common/alice_dialog.dart'; import 'package:alice/utils/alice_parser.dart'; +import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:open_filex/open_filex.dart'; import 'package:package_info_plus/package_info_plus.dart'; @@ -60,8 +63,10 @@ class AliceSaveHelper { } else { AliceGeneralDialog.show( context: context, - title: 'Permission error', - description: "Permission not granted. Couldn't save logs.", + title: + context.i18n(AliceTranslationKey.saveDialogPermissionErrorTitle), + description: context + .i18n(AliceTranslationKey.saveDialogPermissionErrorDescription), ); } } @@ -75,8 +80,9 @@ class AliceSaveHelper { if (calls.isEmpty) { AliceGeneralDialog.show( context: context, - title: 'Error', - description: 'There are no logs to save', + title: context.i18n(AliceTranslationKey.saveDialogEmptyErrorTitle), + description: + context.i18n(AliceTranslationKey.saveDialogEmptyErrorDescription), ); return ''; } @@ -92,9 +98,9 @@ class AliceSaveHelper { 'alice_log_${DateTime.now().millisecondsSinceEpoch}.txt'; final File file = File('${externalDir.path}/$fileName')..createSync(); final IOSink sink = file.openWrite(mode: FileMode.append) - ..write(await _buildAliceLog()); + ..write(await _buildAliceLog(context: context)); for (final AliceHttpCall call in calls) { - sink.write(_buildCallLog(call)); + sink.write(_buildCallLog(context: context, call: call)); } await sink.flush(); await sink.close(); @@ -102,9 +108,13 @@ class AliceSaveHelper { if (context.mounted) { AliceGeneralDialog.show( context: context, - title: 'Success', - description: 'Successfully saved logs in ${file.path}', - secondButtonTitle: Platform.isAndroid ? 'View file' : null, + title: context.i18n(AliceTranslationKey.saveSuccessTitle), + description: context + .i18n(AliceTranslationKey.saveSuccessDescription) + .replaceAll("[path]", file.path), + secondButtonTitle: Platform.isAndroid + ? context.i18n(AliceTranslationKey.saveSuccessView) + : null, secondButtonAction: () => Platform.isAndroid ? OpenFilex.open(file.path) : null, ); @@ -115,8 +125,10 @@ class AliceSaveHelper { if (context.mounted) { AliceGeneralDialog.show( context: context, - title: 'Error', - description: 'Failed to save http calls to file', + title: + context.i18n(AliceTranslationKey.saveDialogFileSaveErrorTitle), + description: context + .i18n(AliceTranslationKey.saveDialogFileSaveErrorDescription), ); } } @@ -124,8 +136,9 @@ class AliceSaveHelper { if (context.mounted) { AliceGeneralDialog.show( context: context, - title: 'Error', - description: 'Failed to save http calls to file', + title: context.i18n(AliceTranslationKey.saveDialogFileSaveErrorTitle), + description: context + .i18n(AliceTranslationKey.saveDialogFileSaveErrorDescription), ); AliceUtils.log(exception.toString()); } @@ -134,78 +147,80 @@ class AliceSaveHelper { return ''; } - static Future _buildAliceLog() async { + static Future _buildAliceLog({required BuildContext context}) async { final PackageInfo packageInfo = await PackageInfo.fromPlatform(); - return 'Alice - HTTP Inspector\n' - 'App name: ${packageInfo.appName}\n' - 'Package: ${packageInfo.packageName}\n' - 'Version: ${packageInfo.version}\n' - 'Build number: ${packageInfo.buildNumber}\n' - 'Generated: ${DateTime.now().toIso8601String()}\n' + return '${context.i18n(AliceTranslationKey.saveHeaderTitle)}\n' + '${context.i18n(AliceTranslationKey.saveHeaderAppName)} ${packageInfo.appName}\n' + '${context.i18n(AliceTranslationKey.saveHeaderPackage)} ${packageInfo.packageName}\n' + '${context.i18n(AliceTranslationKey.saveHeaderTitle)} ${packageInfo.version}\n' + '${context.i18n(AliceTranslationKey.saveHeaderBuildNumber)} ${packageInfo.buildNumber}\n' + '${context.i18n(AliceTranslationKey.saveHeaderGenerated)} ${DateTime.now().toIso8601String()}\n' '\n'; } - static String _buildCallLog(AliceHttpCall call) { + static String _buildCallLog( + {required BuildContext context, required AliceHttpCall call}) { final StringBuffer stringBuffer = StringBuffer() ..writeAll([ '===========================================\n', - 'Id: ${call.id}\n', + '${context.i18n(AliceTranslationKey.saveLogId)} ${call.id}\n', '============================================\n', '--------------------------------------------\n', - 'General data\n', + '${context.i18n(AliceTranslationKey.saveLogGeneralData)}\n', '--------------------------------------------\n', - 'Server: ${call.server} \n', - 'Method: ${call.method} \n', - 'Endpoint: ${call.endpoint} \n', - 'Client: ${call.client} \n', - 'Duration ${AliceConversionHelper.formatTime(call.duration)}\n', - 'Secured connection: ${call.secure}\n', - 'Completed: ${!call.loading} \n', + '${context.i18n(AliceTranslationKey.saveLogServer)} ${call.server} \n', + '${context.i18n(AliceTranslationKey.saveLogMethod)} ${call.method} \n', + '${context.i18n(AliceTranslationKey.saveLogEndpoint)} ${call.endpoint} \n', + '${context.i18n(AliceTranslationKey.saveLogClient)} ${call.client} \n', + '${context.i18n(AliceTranslationKey.saveLogDuration)} ${AliceConversionHelper.formatTime(call.duration)}\n', + '${context.i18n(AliceTranslationKey.saveLogSecured)} ${call.secure}\n', + '${context.i18n(AliceTranslationKey.saveLogCompleted)}: ${!call.loading} \n', '--------------------------------------------\n', - 'Request\n', + '${context.i18n(AliceTranslationKey.saveLogRequest)}\n', '--------------------------------------------\n', - 'Request time: ${call.request?.time}\n', - 'Request content type: ${call.request?.contentType}\n', - 'Request cookies: ${_encoder.convert(call.request?.cookies)}\n', - 'Request headers: ${_encoder.convert(call.request?.headers)}\n', + '${context.i18n(AliceTranslationKey.saveLogRequestTime)} ${call.request?.time}\n', + '${context.i18n(AliceTranslationKey.saveLogRequestContentType)}: ${call.request?.contentType}\n', + '${context.i18n(AliceTranslationKey.saveLogRequestCookies)} ${_encoder.convert(call.request?.cookies)}\n', + '${context.i18n(AliceTranslationKey.saveLogRequestHeaders)} ${_encoder.convert(call.request?.headers)}\n', ]); if (call.request?.queryParameters.isNotEmpty ?? false) { stringBuffer.write( - 'Request query params: ${_encoder.convert(call.request?.queryParameters)}\n', + '${context.i18n(AliceTranslationKey.saveLogRequestQueryParams)} ${_encoder.convert(call.request?.queryParameters)}\n', ); } stringBuffer.writeAll([ - 'Request size: ${AliceConversionHelper.formatBytes(call.request?.size ?? 0)}\n', - 'Request body: ${AliceBodyParser.formatBody(call.request?.body, call.request?.contentType)}\n', + '${context.i18n(AliceTranslationKey.saveLogRequestSize)} ${AliceConversionHelper.formatBytes(call.request?.size ?? 0)}\n', + '${context.i18n(AliceTranslationKey.saveLogRequestBody)} ${AliceBodyParser.formatBody(call.request?.body, call.request?.contentType)}\n', '--------------------------------------------\n', - 'Response\n', + '${context.i18n(AliceTranslationKey.saveLogResponse)}\n', '--------------------------------------------\n', - 'Response time: ${call.response?.time}\n', - 'Response status: ${call.response?.status}\n', - 'Response size: ${AliceConversionHelper.formatBytes(call.response?.size ?? 0)}\n', - 'Response headers: ${_encoder.convert(call.response?.headers)}\n', - 'Response body: ${AliceBodyParser.formatBody(call.response?.body, AliceBodyParser.getContentType(call.response?.headers))}\n', + '${context.i18n(AliceTranslationKey.saveLogResponseTime)} ${call.response?.time}\n', + '${context.i18n(AliceTranslationKey.saveLogResponseStatus)} ${call.response?.status}\n', + '${context.i18n(AliceTranslationKey.saveLogResponseSize)} ${AliceConversionHelper.formatBytes(call.response?.size ?? 0)}\n', + '${context.i18n(AliceTranslationKey.saveLogResponseHeaders)} ${_encoder.convert(call.response?.headers)}\n', + '${context.i18n(AliceTranslationKey.saveLogResponseBody)} ${AliceBodyParser.formatBody(call.response?.body, AliceBodyParser.getContentType(call.response?.headers))}\n', ]); if (call.error != null) { stringBuffer.writeAll([ '--------------------------------------------\n', - 'Error\n', + '${context.i18n(AliceTranslationKey.saveLogError)}\n', '--------------------------------------------\n', - 'Error: ${call.error?.error}\n', + '${context.i18n(AliceTranslationKey.saveLogError)}: ${call.error?.error}\n', ]); if (call.error?.stackTrace != null) { - stringBuffer.write('Error stacktrace: ${call.error?.stackTrace}\n'); + stringBuffer.write( + '${context.i18n(AliceTranslationKey.saveLogStackTrace)}: ${call.error?.stackTrace}\n'); } } stringBuffer.writeAll([ '--------------------------------------------\n', - 'Curl\n', + '${context.i18n(AliceTranslationKey.saveLogCurl)}\n', '--------------------------------------------\n', call.getCurlCommand(), '\n', @@ -216,9 +231,14 @@ class AliceSaveHelper { return stringBuffer.toString(); } - static Future buildCallLog(AliceHttpCall call) async { + static Future buildCallLog( + {required BuildContext context, required AliceHttpCall call}) async { try { - return await _buildAliceLog() + _buildCallLog(call); + return await _buildAliceLog(context: context) + + _buildCallLog( + call: call, + context: context, + ); } catch (exception) { return 'Failed to generate call log'; } diff --git a/packages/alice/lib/model/alice_translation.dart b/packages/alice/lib/model/alice_translation.dart index 19fbd70d..82b7882c 100644 --- a/packages/alice/lib/model/alice_translation.dart +++ b/packages/alice/lib/model/alice_translation.dart @@ -111,5 +111,46 @@ enum AliceTranslationKey { notificationRedirect, notificationError, notificationTotalRequests, - + saveDialogPermissionErrorTitle, + saveDialogPermissionErrorDescription, + saveDialogEmptyErrorTitle, + saveDialogEmptyErrorDescription, + saveDialogFileSaveErrorTitle, + saveDialogFileSaveErrorDescription, + saveSuccessTitle, + saveSuccessDescription, + saveSuccessView, + saveHeaderTitle, + saveHeaderAppName, + saveHeaderPackage, + saveHeaderVersion, + saveHeaderBuildNumber, + saveHeaderGenerated, + saveLogId, + saveLogGeneralData, + saveLogServer, + saveLogMethod, + saveLogEndpoint, + saveLogClient, + saveLogDuration, + saveLogSecured, + saveLogCompleted, + saveLogRequest, + saveLogRequestTime, + saveLogRequestContentType, + saveLogRequestCookies, + saveLogRequestHeaders, + saveLogRequestQueryParams, + saveLogRequestSize, + saveLogRequestBody, + saveLogResponse, + saveLogResponseTime, + saveLogResponseStatus, + saveLogResponseSize, + saveLogResponseHeaders, + saveLogResponseBody, + saveLogError, + saveLogStackTrace, + saveLogCurl, + accept, } diff --git a/packages/alice/lib/ui/call_details/page/alice_call_details_page.dart b/packages/alice/lib/ui/call_details/page/alice_call_details_page.dart index ae95973a..7f724bd5 100644 --- a/packages/alice/lib/ui/call_details/page/alice_call_details_page.dart +++ b/packages/alice/lib/ui/call_details/page/alice_call_details_page.dart @@ -103,7 +103,7 @@ class _AliceCallDetailsPageState extends State void _saveCallsToFile() async { await Share.share( - await AliceSaveHelper.buildCallLog(widget.call), + await AliceSaveHelper.buildCallLog(call: widget.call, context: context), subject: context.i18n(AliceTranslationKey.emailSubject), ); } diff --git a/packages/alice/lib/ui/common/alice_dialog.dart b/packages/alice/lib/ui/common/alice_dialog.dart index fa286045..3c0be6c6 100644 --- a/packages/alice/lib/ui/common/alice_dialog.dart +++ b/packages/alice/lib/ui/common/alice_dialog.dart @@ -1,3 +1,5 @@ +import 'package:alice/model/alice_translation.dart'; +import 'package:alice/ui/common/alice_context_ext.dart'; import 'package:alice/ui/common/alice_theme.dart'; import 'package:flutter/material.dart'; @@ -8,7 +10,7 @@ class AliceGeneralDialog { required BuildContext context, required String title, required String description, - String firstButtonTitle = 'Accept', + String? firstButtonTitle, String? secondButtonTitle, Function? firstButtonAction, Function? secondButtonAction, @@ -28,7 +30,10 @@ class AliceGeneralDialog { firstButtonAction?.call(); Navigator.of(context).pop(); }, - child: Text(firstButtonTitle), + child: Text( + firstButtonTitle ?? + context.i18n(AliceTranslationKey.accept), + ), ), if (secondButtonTitle != null) TextButton( From a87999b191e7c3d5eed39ee5abbf09dd153ad802 Mon Sep 17 00:00:00 2001 From: Jakub Homlala Date: Fri, 28 Jun 2024 14:55:48 +0200 Subject: [PATCH 09/16] feat: updated translations --- .../alice/lib/core/alice_translations.dart | 258 ++++++++++++++---- .../lib/ui/common/alice_context_ext.dart | 9 +- 2 files changed, 218 insertions(+), 49 deletions(-) diff --git a/packages/alice/lib/core/alice_translations.dart b/packages/alice/lib/core/alice_translations.dart index 4573c94d..0526e6ed 100644 --- a/packages/alice/lib/core/alice_translations.dart +++ b/packages/alice/lib/core/alice_translations.dart @@ -6,6 +6,7 @@ class AliceTranslations { static List _initialise() { List translations = []; translations.add(_buildEnTranslations()); + translations.add(_buildPlTranslations()); return translations; } @@ -48,7 +49,7 @@ class AliceTranslations { AliceTranslationKey.callResponseWaitingForResponse: "Awaiting response...", AliceTranslationKey.callResponseError: "Error", - AliceTranslationKey.callResponseReceived: "Received", + AliceTranslationKey.callResponseReceived: "Received:", AliceTranslationKey.callResponseBytesReceived: "Bytes received:", AliceTranslationKey.callResponseStatus: "Status:", AliceTranslationKey.callResponseHeaders: "Headers:", @@ -77,8 +78,8 @@ class AliceTranslations { AliceTranslationKey.callsListNo: "No", AliceTranslationKey.callsListDeleteCallsDialogTitle: "Delete calls", AliceTranslationKey.callsListDeleteCallsDialogDescription: - "Do you want to delete http calls?", - AliceTranslationKey.callsListSearchHint: "Search http request...", + "Do you want to delete HTTP calls?", + AliceTranslationKey.callsListSearchHint: "Search HTTP call...", AliceTranslationKey.callsListSort: "Sort", AliceTranslationKey.callsListDelete: "Delete", AliceTranslationKey.callsListStats: "Stats", @@ -119,50 +120,215 @@ class AliceTranslations { AliceTranslationKey.notificationSuccess: "Success:", AliceTranslationKey.notificationRedirect: "Redirect:", AliceTranslationKey.notificationError: "Error:", - AliceTranslationKey.notificationTotalRequests:"Alice (total [requestCount] requests)", - AliceTranslationKey.saveDialogPermissionErrorTitle :"Permission error", - AliceTranslationKey.saveDialogPermissionErrorDescription:"Permission not granted. Couldn't save logs.", - AliceTranslationKey.saveDialogEmptyErrorTitle:"Call history empty", - AliceTranslationKey.saveDialogEmptyErrorDescription:"There are no calls to save.", - AliceTranslationKey.saveDialogFileSaveErrorTitle:"Save error", - AliceTranslationKey.saveDialogFileSaveErrorDescription:"Failed to save http calls to fil", - AliceTranslationKey.saveSuccessTitle:"Logs saved", - AliceTranslationKey.saveSuccessDescription:"Successfully saved logs in [path].", - AliceTranslationKey.saveSuccessView:"View file", - AliceTranslationKey.saveHeaderTitle:"Alice - HTTP Inspector", - AliceTranslationKey.saveHeaderAppName:"App name:", - AliceTranslationKey.saveHeaderPackage:"Package:", - AliceTranslationKey.saveHeaderVersion:"Version:", - AliceTranslationKey.saveHeaderBuildNumber:"Build number:", - AliceTranslationKey.saveHeaderGenerated:"Generated:", - AliceTranslationKey.saveLogId:"Id:", - AliceTranslationKey.saveLogGeneralData:"General data", - AliceTranslationKey.saveLogServer:"Server:", - AliceTranslationKey.saveLogMethod:"Method:", - AliceTranslationKey.saveLogEndpoint:"Endpoint:", - AliceTranslationKey.saveLogClient:"Client:", - AliceTranslationKey.saveLogDuration:"Duration:", - AliceTranslationKey.saveLogSecured:"Secured connection:", - AliceTranslationKey.saveLogCompleted:"Completed:", - AliceTranslationKey.saveLogRequest:"Request", - AliceTranslationKey.saveLogRequestTime:"Request time:", - AliceTranslationKey.saveLogRequestContentType:"Request content type:", - AliceTranslationKey.saveLogRequestCookies:"Request cookies:", - AliceTranslationKey.saveLogRequestHeaders:"Request headers:", - AliceTranslationKey.saveLogRequestQueryParams:"Request query params:", - AliceTranslationKey.saveLogRequestSize:"Request size:", - AliceTranslationKey.saveLogRequestBody:"Request body:", - AliceTranslationKey.saveLogResponse:"Response", - AliceTranslationKey.saveLogResponseTime:"Response time:", - AliceTranslationKey.saveLogResponseStatus:"Response status:", - AliceTranslationKey.saveLogResponseSize:"Response size:", - AliceTranslationKey.saveLogResponseHeaders:"Response headers:", - AliceTranslationKey.saveLogResponseBody:"Response body:", - AliceTranslationKey.saveLogError:"Error", - AliceTranslationKey.saveLogStackTrace:"Stack trace", - AliceTranslationKey.saveLogCurl:"Curl", - AliceTranslationKey.accept:"Accept", + AliceTranslationKey.notificationTotalRequests: + "Alice (total [requestCount] requests)", + AliceTranslationKey.saveDialogPermissionErrorTitle: "Permission error", + AliceTranslationKey.saveDialogPermissionErrorDescription: + "Permission not granted. Couldn't save logs.", + AliceTranslationKey.saveDialogEmptyErrorTitle: "Call history empty", + AliceTranslationKey.saveDialogEmptyErrorDescription: + "There are no calls to save.", + AliceTranslationKey.saveDialogFileSaveErrorTitle: "Save error", + AliceTranslationKey.saveDialogFileSaveErrorDescription: + "Failed to save http calls to file.", + AliceTranslationKey.saveSuccessTitle: "Logs saved", + AliceTranslationKey.saveSuccessDescription: + "Successfully saved logs in [path].", + AliceTranslationKey.saveSuccessView: "View file", + AliceTranslationKey.saveHeaderTitle: "Alice - HTTP Inspector", + AliceTranslationKey.saveHeaderAppName: "App name:", + AliceTranslationKey.saveHeaderPackage: "Package:", + AliceTranslationKey.saveHeaderVersion: "Version:", + AliceTranslationKey.saveHeaderBuildNumber: "Build number:", + AliceTranslationKey.saveHeaderGenerated: "Generated:", + AliceTranslationKey.saveLogId: "Id:", + AliceTranslationKey.saveLogGeneralData: "General data", + AliceTranslationKey.saveLogServer: "Server:", + AliceTranslationKey.saveLogMethod: "Method:", + AliceTranslationKey.saveLogEndpoint: "Endpoint:", + AliceTranslationKey.saveLogClient: "Client:", + AliceTranslationKey.saveLogDuration: "Duration:", + AliceTranslationKey.saveLogSecured: "Secured connection:", + AliceTranslationKey.saveLogCompleted: "Completed:", + AliceTranslationKey.saveLogRequest: "Request", + AliceTranslationKey.saveLogRequestTime: "Request time:", + AliceTranslationKey.saveLogRequestContentType: "Request content type:", + AliceTranslationKey.saveLogRequestCookies: "Request cookies:", + AliceTranslationKey.saveLogRequestHeaders: "Request headers:", + AliceTranslationKey.saveLogRequestQueryParams: "Request query params:", + AliceTranslationKey.saveLogRequestSize: "Request size:", + AliceTranslationKey.saveLogRequestBody: "Request body:", + AliceTranslationKey.saveLogResponse: "Response", + AliceTranslationKey.saveLogResponseTime: "Response time:", + AliceTranslationKey.saveLogResponseStatus: "Response status:", + AliceTranslationKey.saveLogResponseSize: "Response size:", + AliceTranslationKey.saveLogResponseHeaders: "Response headers:", + AliceTranslationKey.saveLogResponseBody: "Response body:", + AliceTranslationKey.saveLogError: "Error", + AliceTranslationKey.saveLogStackTrace: "Stack trace", + AliceTranslationKey.saveLogCurl: "Curl", + AliceTranslationKey.accept: "Accept", + }); + } + static AliceTranslationData _buildPlTranslations() { + return AliceTranslationData(languageCode: "pl", values: { + AliceTranslationKey.alice: "Alice", + AliceTranslationKey.callDetails: "Połączenie HTTP - detale", + AliceTranslationKey.emailSubject: "Raport ALice", + AliceTranslationKey.callDetailsRequest: "Żądanie", + AliceTranslationKey.callDetailsResponse: "Odpowiedź", + AliceTranslationKey.callDetailsOverview: "Przegląd", + AliceTranslationKey.callDetailsError: "Błąd", + AliceTranslationKey.callDetailsEmpty: "Błąd ładowania danych", + AliceTranslationKey.callErrorScreenErrorEmpty: "Brak błędów", + AliceTranslationKey.callErrorScreenError: "Błąd:", + AliceTranslationKey.callErrorScreenStacktrace: "Ślad stosu:", + AliceTranslationKey.callErrorScreenEmpty: "Brak danych do wyświetlenia", + AliceTranslationKey.callOverviewMethod: "Metoda:", + AliceTranslationKey.callOverviewServer: "Serwer:", + AliceTranslationKey.callOverviewEndpoint: "Endpoint:", + AliceTranslationKey.callOverviewStarted: "Rozpoczęto:", + AliceTranslationKey.callOverviewFinished: "Zakończono:", + AliceTranslationKey.callOverviewDuration: "Czas trwania:", + AliceTranslationKey.callOverviewBytesSent: "Bajty wysłane:", + AliceTranslationKey.callOverviewBytesReceived: "Bajty odebrane:", + AliceTranslationKey.callOverviewClient: "Klient:", + AliceTranslationKey.callOverviewSecure: "Połączenie zabezpieczone:", + AliceTranslationKey.callRequestStarted: "Ropoczęto:", + AliceTranslationKey.callRequestBytesSent: "Bajty wysłane:", + AliceTranslationKey.callRequestContentType: "Typ zawartości:", + AliceTranslationKey.callRequestBody: "Body:", + AliceTranslationKey.callRequestBodyEmpty: "Body jest puste", + AliceTranslationKey.callRequestFormDataFields: "Pola forumlarza:", + AliceTranslationKey.callRequestFormDataFiles: "Pliki formularza:", + AliceTranslationKey.callRequestHeaders: "Headery:", + AliceTranslationKey.callRequestHeadersEmpty: "Headery są puste", + AliceTranslationKey.callRequestQueryParameters: "Parametry query", + AliceTranslationKey.callRequestQueryParametersEmpty: + "Parametry query są puste", + AliceTranslationKey.callResponseWaitingForResponse: + "Oczekiwanie na odpowiedź...", + AliceTranslationKey.callResponseError: "Błąd", + AliceTranslationKey.callResponseReceived: "Otrzymano:", + AliceTranslationKey.callResponseBytesReceived: "Bajty odebrane:", + AliceTranslationKey.callResponseStatus: "Status:", + AliceTranslationKey.callResponseHeaders: "Headery:", + AliceTranslationKey.callResponseHeadersEmpty: "Headery są puste", + AliceTranslationKey.callResponseBodyImage: "Body: Obraz", + AliceTranslationKey.callResponseBody: "Body:", + AliceTranslationKey.callResponseTooLargeToShow: "Za duże aby pokazać", + AliceTranslationKey.callResponseBodyShow: "Pokaż body", + AliceTranslationKey.callResponseLargeBodyShowWarning: + 'Uwaga! Może zająć trochę czasu, zanim uda się wyrenderować output.', + AliceTranslationKey.callResponseBodyVideo: 'Body: Video', + AliceTranslationKey.callResponseBodyVideoWebBrowser: + 'Otwórz video w przeglądarce', + AliceTranslationKey.callResponseHeadersUnknown: "Nieznane", + AliceTranslationKey.callResponseBodyUnknown: 'Nieznane body. Alice' + ' może renderować video/image/text. Odpowiedź ma typ zawartości:' + "[contentType], który nie może być obsłużony.Jeżeli chcesz, możesz " + "spróbować wyrenderować body jako tekst, ale może to się nie udać.", + AliceTranslationKey.callResponseBodyUnknownShow: "Pokaż nieobsługiwane body", + AliceTranslationKey.callsListInspector: "Inspektor", + AliceTranslationKey.callsListLogger: "Logger", + AliceTranslationKey.callsListDeleteLogsDialogTitle: "Usuń logi", + AliceTranslationKey.callsListDeleteLogsDialogDescription: + "Czy chcesz usunąc logi?", + AliceTranslationKey.callsListYes: "Tak", + AliceTranslationKey.callsListNo: "Nie", + AliceTranslationKey.callsListDeleteCallsDialogTitle: "Usuń połączenia", + AliceTranslationKey.callsListDeleteCallsDialogDescription: + "Czy chcesz usunąć zapisane połaczenia HTTP?", + AliceTranslationKey.callsListSearchHint: "Szukaj połączenia HTTP...", + AliceTranslationKey.callsListSort: "Sortuj", + AliceTranslationKey.callsListDelete: "Usuń", + AliceTranslationKey.callsListStats: "Statystyki", + AliceTranslationKey.callsListSave: "Zapis", + AliceTranslationKey.logsEmpty: "Nie ma logów do pokazania", + AliceTranslationKey.logsItemError: "Błąd:", + AliceTranslationKey.logsItemStackTrace: "Ślad stosu:", + AliceTranslationKey.logsCopied: "Skopiowano do schowka.", + AliceTranslationKey.sortDialogTitle: "Wybierz filtr", + AliceTranslationKey.sortDialogAscending: 'Rosnąco', + AliceTranslationKey.sortDialogDescending: "Malejąco", + AliceTranslationKey.sortDialogAccept: "Akceptuj", + AliceTranslationKey.sortDialogCancel: "Anuluj", + AliceTranslationKey.sortDialogTime: "Czas utworzenia (domyślnie)", + AliceTranslationKey.sortDialogResponseTime: "Czas odpowiedzi", + AliceTranslationKey.sortDialogResponseCode: "Status odpowiedzi", + AliceTranslationKey.sortDialogResponseSize: "Rozmiar odpowiedzi", + AliceTranslationKey.sortDialogEndpoint: "Endpoint", + AliceTranslationKey.statsTitle: "Statystyki", + AliceTranslationKey.statsTotalRequests: "Razem żądań:", + AliceTranslationKey.statsPendingRequests: "Oczekujące żądania:", + AliceTranslationKey.statsSuccessRequests: "Poprawne żądania:", + AliceTranslationKey.statsRedirectionRequests: "Żądania przekierowania:", + AliceTranslationKey.statsErrorRequests: "Błędne żądania:", + AliceTranslationKey.statsBytesSent: "Bajty wysłane:", + AliceTranslationKey.statsBytesReceived: "Bajty otrzymane:", + AliceTranslationKey.statsAverageRequestTime: "Średni czas żądania:", + AliceTranslationKey.statsMaxRequestTime: "Maksymalny czas żądania:", + AliceTranslationKey.statsMinRequestTime: "Minimalny czas żądania:", + AliceTranslationKey.statsGetRequests: "Żądania GET:", + AliceTranslationKey.statsPostRequests: "Żądania POST:", + AliceTranslationKey.statsDeleteRequests: "Żądania DELETE:", + AliceTranslationKey.statsPutRequests: "Żądania PUT:", + AliceTranslationKey.statsPatchRequests: "Żądania PATCH:", + AliceTranslationKey.statsSecuredRequests: "Żądania zabezpieczone:", + AliceTranslationKey.statsUnsecuredRequests: "Żądania niezabezpieczone:", + AliceTranslationKey.notificationLoading: "Oczekiwanie:", + AliceTranslationKey.notificationSuccess: "Poprawne:", + AliceTranslationKey.notificationRedirect: "Przekierowanie:", + AliceTranslationKey.notificationError: "Błąd:", + AliceTranslationKey.notificationTotalRequests: + "Alice (razem [requestCount] żądań)", + AliceTranslationKey.saveDialogPermissionErrorTitle: "Błąd pozwolenia", + AliceTranslationKey.saveDialogPermissionErrorDescription: + "Pozwolenie nieprzyznane. Nie można zapisać logów.", + AliceTranslationKey.saveDialogEmptyErrorTitle: "Pusta historia połaczeń", + AliceTranslationKey.saveDialogEmptyErrorDescription: + "Nie ma połączeń do zapisania.", + AliceTranslationKey.saveDialogFileSaveErrorTitle: "Błąd zapisu", + AliceTranslationKey.saveDialogFileSaveErrorDescription: + "Nie można zapisać danych do pliku.", + AliceTranslationKey.saveSuccessTitle: "Logi zapisane", + AliceTranslationKey.saveSuccessDescription: + "Zapisano logi w [path].", + AliceTranslationKey.saveSuccessView: "Otwórz plik", + AliceTranslationKey.saveHeaderTitle: "Alice - Inspektor HTTP", + AliceTranslationKey.saveHeaderAppName: "Nazwa aplikacji:", + AliceTranslationKey.saveHeaderPackage: "Paczka:", + AliceTranslationKey.saveHeaderVersion: "Wersja:", + AliceTranslationKey.saveHeaderBuildNumber: "Numer buildu:", + AliceTranslationKey.saveHeaderGenerated: "Wygenerowano:", + AliceTranslationKey.saveLogId: "Id:", + AliceTranslationKey.saveLogGeneralData: "Ogólne informacje", + AliceTranslationKey.saveLogServer: "Serwer:", + AliceTranslationKey.saveLogMethod: "Metoda:", + AliceTranslationKey.saveLogEndpoint: "Endpoint:", + AliceTranslationKey.saveLogClient: "Klient:", + AliceTranslationKey.saveLogDuration: "Czas trwania:", + AliceTranslationKey.saveLogSecured: "Połączenie zabezpieczone:", + AliceTranslationKey.saveLogCompleted: "Zakończono:", + AliceTranslationKey.saveLogRequest: "Żądanie", + AliceTranslationKey.saveLogRequestTime: "Czas żądania:", + AliceTranslationKey.saveLogRequestContentType: "Typ zawartości żądania:", + AliceTranslationKey.saveLogRequestCookies: "Ciasteczka żądania:", + AliceTranslationKey.saveLogRequestHeaders: "Heady żądania", + AliceTranslationKey.saveLogRequestQueryParams: "Parametry query żądania", + AliceTranslationKey.saveLogRequestSize: "Rozmiar żądania:", + AliceTranslationKey.saveLogRequestBody: "Body żądania:", + AliceTranslationKey.saveLogResponse: "Odpowiedź", + AliceTranslationKey.saveLogResponseTime: "Czas odpowiedzi:", + AliceTranslationKey.saveLogResponseStatus: "Status odpowiedzi:", + AliceTranslationKey.saveLogResponseSize: "Rozmiar odpowiedzi:", + AliceTranslationKey.saveLogResponseHeaders: "Headery odpowiedzi:", + AliceTranslationKey.saveLogResponseBody: "Body odpowiedzi:", + AliceTranslationKey.saveLogError: "Błąd", + AliceTranslationKey.saveLogStackTrace: "Ślad stosu", + AliceTranslationKey.saveLogCurl: "Curl", + AliceTranslationKey.accept: "Akceptuj", }); } diff --git a/packages/alice/lib/ui/common/alice_context_ext.dart b/packages/alice/lib/ui/common/alice_context_ext.dart index e451d9b5..05e5de4f 100644 --- a/packages/alice/lib/ui/common/alice_context_ext.dart +++ b/packages/alice/lib/ui/common/alice_context_ext.dart @@ -1,12 +1,15 @@ - import 'package:alice/model/alice_translation.dart'; + import 'dart:io'; + +import 'package:alice/model/alice_translation.dart'; import 'package:alice/core/alice_translations.dart'; import 'package:flutter/material.dart'; extension AliceContextExt on BuildContext{ String i18n(AliceTranslationKey key){ try{ - final locale = Localizations.localeOf(this); - final languageCode = locale.languageCode; + final locale =Platform.localeName; + + final languageCode = locale.split("_").first; return AliceTranslations.get(languageCode: languageCode, key: key); } catch (error){ From b77bb325d90546dfe37a5b784c77150eae92604b Mon Sep 17 00:00:00 2001 From: Jakub Homlala Date: Fri, 28 Jun 2024 18:09:46 +0200 Subject: [PATCH 10/16] feat: added missing translations --- .../alice/lib/core/alice_translations.dart | 6 +++++ .../alice/lib/helper/alice_save_helper.dart | 6 +++-- .../alice/lib/model/alice_translation.dart | 8 +++++- .../page/alice_call_details_page.dart | 2 ++ .../widget/alice_call_request_screen.dart | 9 +++++-- .../widget/alice_call_response_screen.dart | 20 +++++++++++---- packages/alice/lib/utils/alice_parser.dart | 25 ++++++++++++------- 7 files changed, 57 insertions(+), 19 deletions(-) diff --git a/packages/alice/lib/core/alice_translations.dart b/packages/alice/lib/core/alice_translations.dart index 0526e6ed..57715eec 100644 --- a/packages/alice/lib/core/alice_translations.dart +++ b/packages/alice/lib/core/alice_translations.dart @@ -168,6 +168,8 @@ class AliceTranslations { AliceTranslationKey.saveLogStackTrace: "Stack trace", AliceTranslationKey.saveLogCurl: "Curl", AliceTranslationKey.accept: "Accept", + AliceTranslationKey.parserFailed:"Failed to parse: ", + AliceTranslationKey.unknown:"Unknown", }); } @@ -329,9 +331,13 @@ class AliceTranslations { AliceTranslationKey.saveLogStackTrace: "Ślad stosu", AliceTranslationKey.saveLogCurl: "Curl", AliceTranslationKey.accept: "Akceptuj", + AliceTranslationKey.parserFailed:"Problem z parsowaniem: ", + AliceTranslationKey.unknown:"Nieznane" }); } + /// Returns localized value for specific [languageCode] and [key]. If value + /// can't be selected then [key] will be returned. static String get({ required String languageCode, required AliceTranslationKey key, diff --git a/packages/alice/lib/helper/alice_save_helper.dart b/packages/alice/lib/helper/alice_save_helper.dart index 0b3716fe..8a96ac89 100644 --- a/packages/alice/lib/helper/alice_save_helper.dart +++ b/packages/alice/lib/helper/alice_save_helper.dart @@ -1,3 +1,5 @@ +// ignore_for_file: use_build_context_synchronously + import 'dart:convert' show JsonEncoder; import 'dart:io' show Directory, File, FileMode, IOSink, Platform; @@ -193,7 +195,7 @@ class AliceSaveHelper { stringBuffer.writeAll([ '${context.i18n(AliceTranslationKey.saveLogRequestSize)} ${AliceConversionHelper.formatBytes(call.request?.size ?? 0)}\n', - '${context.i18n(AliceTranslationKey.saveLogRequestBody)} ${AliceBodyParser.formatBody(call.request?.body, call.request?.contentType)}\n', + '${context.i18n(AliceTranslationKey.saveLogRequestBody)} ${AliceBodyParser.formatBody(context: context, body: call.request?.body, contentType: call.request?.contentType)}\n', '--------------------------------------------\n', '${context.i18n(AliceTranslationKey.saveLogResponse)}\n', '--------------------------------------------\n', @@ -201,7 +203,7 @@ class AliceSaveHelper { '${context.i18n(AliceTranslationKey.saveLogResponseStatus)} ${call.response?.status}\n', '${context.i18n(AliceTranslationKey.saveLogResponseSize)} ${AliceConversionHelper.formatBytes(call.response?.size ?? 0)}\n', '${context.i18n(AliceTranslationKey.saveLogResponseHeaders)} ${_encoder.convert(call.response?.headers)}\n', - '${context.i18n(AliceTranslationKey.saveLogResponseBody)} ${AliceBodyParser.formatBody(call.response?.body, AliceBodyParser.getContentType(call.response?.headers))}\n', + '${context.i18n(AliceTranslationKey.saveLogResponseBody)} ${AliceBodyParser.formatBody(context: context, body: call.response?.body, contentType: AliceBodyParser.getContentType(context: context, headers: call.response?.headers))}\n', ]); if (call.error != null) { diff --git a/packages/alice/lib/model/alice_translation.dart b/packages/alice/lib/model/alice_translation.dart index 82b7882c..a07f996e 100644 --- a/packages/alice/lib/model/alice_translation.dart +++ b/packages/alice/lib/model/alice_translation.dart @@ -1,6 +1,10 @@ /// Definition of translations for specific locale class AliceTranslationData { + + /// Language code of locale, i.e (en_US) => en. final String languageCode; + + /// Translation values for language final Map values; AliceTranslationData({ @@ -9,7 +13,7 @@ class AliceTranslationData { }); } -/// Translation keys +/// Definition of all available translation keys. enum AliceTranslationKey { alice, callDetails, @@ -153,4 +157,6 @@ enum AliceTranslationKey { saveLogStackTrace, saveLogCurl, accept, + parserFailed, + unknown } diff --git a/packages/alice/lib/ui/call_details/page/alice_call_details_page.dart b/packages/alice/lib/ui/call_details/page/alice_call_details_page.dart index 7f724bd5..d5ad8b90 100644 --- a/packages/alice/lib/ui/call_details/page/alice_call_details_page.dart +++ b/packages/alice/lib/ui/call_details/page/alice_call_details_page.dart @@ -1,3 +1,5 @@ +// ignore_for_file: use_build_context_synchronously + import 'package:alice/core/alice_core.dart'; import 'package:alice/helper/alice_save_helper.dart'; import 'package:alice/model/alice_http_call.dart'; diff --git a/packages/alice/lib/ui/call_details/widget/alice_call_request_screen.dart b/packages/alice/lib/ui/call_details/widget/alice_call_request_screen.dart index d034a222..2e5416d0 100644 --- a/packages/alice/lib/ui/call_details/widget/alice_call_request_screen.dart +++ b/packages/alice/lib/ui/call_details/widget/alice_call_request_screen.dart @@ -28,7 +28,8 @@ class AliceCallRequestScreen extends StatelessWidget { value: AliceConversionHelper.formatBytes(call.request?.size ?? 0)), AliceCallListRow( name: context.i18n(AliceTranslationKey.callRequestContentType), - value: AliceBodyParser.getContentType(call.request?.headers)), + value: AliceBodyParser.getContentType( + context: context, headers: call.request?.headers)), ]; rows.add(AliceCallListRow( @@ -105,7 +106,11 @@ class AliceCallRequestScreen extends StatelessWidget { final dynamic body = call.request?.body; return body != null ? AliceBodyParser.formatBody( - body, AliceBodyParser.getContentType(call.request?.headers)) + context: context, + body: body, + contentType: AliceBodyParser.getContentType( + context: context, headers: call.request?.headers), + ) : context.i18n(AliceTranslationKey.callRequestBodyEmpty); } } diff --git a/packages/alice/lib/ui/call_details/widget/alice_call_response_screen.dart b/packages/alice/lib/ui/call_details/widget/alice_call_response_screen.dart index 3ccb79d8..e8790dc9 100644 --- a/packages/alice/lib/ui/call_details/widget/alice_call_response_screen.dart +++ b/packages/alice/lib/ui/call_details/widget/alice_call_response_screen.dart @@ -170,7 +170,8 @@ class _BodyDataColumnState extends State<_BodyDataColumn> { } String? _getContentTypeOfResponse() { - return AliceBodyParser.getContentType(call.response?.headers); + return AliceBodyParser.getContentType( + context: context, headers: call.response?.headers); } bool _isLargeResponseBody() => @@ -301,7 +302,11 @@ class _TextBody extends StatelessWidget { Widget build(BuildContext context) { final Map? headers = call.response?.headers; final String bodyContent = AliceBodyParser.formatBody( - call.response?.body, AliceBodyParser.getContentType(headers)); + context: context, + body: call.response?.body, + contentType: + AliceBodyParser.getContentType(context: context, headers: headers), + ); return AliceCallListRow( name: context.i18n(AliceTranslationKey.callResponseBody), value: bodyContent); @@ -352,12 +357,17 @@ class _UnknownBody extends StatelessWidget { @override Widget build(BuildContext context) { final Map? headers = call.response?.headers; - final String contentType = AliceBodyParser.getContentType(headers) ?? - context.i18n(AliceTranslationKey.callResponseHeadersUnknown); + final String contentType = + AliceBodyParser.getContentType(context: context, headers: headers) ?? + context.i18n(AliceTranslationKey.callResponseHeadersUnknown); if (showUnsupportedBody) { final bodyContent = AliceBodyParser.formatBody( - call.response?.body, AliceBodyParser.getContentType(headers)); + context: context, + body: call.response?.body, + contentType: + AliceBodyParser.getContentType(context: context, headers: headers), + ); return AliceCallListRow( name: context.i18n(AliceTranslationKey.callResponseBody), value: bodyContent); diff --git a/packages/alice/lib/utils/alice_parser.dart b/packages/alice/lib/utils/alice_parser.dart index 08e2ab15..f7432c20 100644 --- a/packages/alice/lib/utils/alice_parser.dart +++ b/packages/alice/lib/utils/alice_parser.dart @@ -1,14 +1,15 @@ import 'dart:convert'; +import 'package:alice/model/alice_translation.dart'; +import 'package:alice/ui/common/alice_context_ext.dart'; +import 'package:flutter/material.dart'; + /// Body parser helper used to parsing body data. class AliceBodyParser { - static const String _emptyBody = 'Body is empty'; - static const String _unknownContentType = 'Unknown'; static const String _jsonContentTypeSmall = 'content-type'; static const String _jsonContentTypeBig = 'Content-Type'; static const String _stream = 'Stream'; static const String _applicationJson = 'application/json'; - static const String _parseFailedText = 'Failed to parse '; static const JsonEncoder encoder = JsonEncoder.withIndent(' '); /// Tries to parse json. If it fails, it will return the json itself. @@ -32,13 +33,18 @@ class AliceBodyParser { /// Formats body based on [contentType]. If body is null it will return /// [_emptyBody]. Otherwise if body type is json - it will try to format it. /// - static String formatBody(dynamic body, String? contentType) { + static String formatBody({ + required BuildContext context, + required dynamic body, + String? contentType, + }) { try { if (body == null) { - return _emptyBody; + return context.i18n(AliceTranslationKey.callRequestBodyEmpty); } - String bodyContent = _emptyBody; + String bodyContent = + context.i18n(AliceTranslationKey.callRequestBodyEmpty); if (contentType == null || !contentType.toLowerCase().contains(_applicationJson)) { @@ -67,13 +73,14 @@ class AliceBodyParser { return bodyContent; } catch (_) { - return _parseFailedText + body.toString(); + return context.i18n(AliceTranslationKey.parserFailed) + body.toString(); } } /// Get content type from [headers]. It looks for json and if it can't find /// it, it will return unknown content type. - static String? getContentType(Map? headers) { + static String? getContentType( + {required BuildContext context, Map? headers}) { if (headers != null) { if (headers.containsKey(_jsonContentTypeSmall)) { return headers[_jsonContentTypeSmall] as String?; @@ -82,6 +89,6 @@ class AliceBodyParser { return headers[_jsonContentTypeBig] as String?; } } - return _unknownContentType; + return context.i18n(AliceTranslationKey.unknown); } } From 8a9b7e78e224842e6a1add8a1576442a1c41aca6 Mon Sep 17 00:00:00 2001 From: Jakub Homlala Date: Fri, 28 Jun 2024 18:10:42 +0200 Subject: [PATCH 11/16] feat: dart format --- packages/alice/lib/core/alice_translations.dart | 14 +++++++------- packages/alice/lib/model/alice_translation.dart | 1 - .../ui/calls_list/page/alice_calls_list_page.dart | 4 ++-- .../alice/lib/ui/common/alice_context_ext.dart | 15 +++++++-------- 4 files changed, 16 insertions(+), 18 deletions(-) diff --git a/packages/alice/lib/core/alice_translations.dart b/packages/alice/lib/core/alice_translations.dart index 57715eec..218f10ce 100644 --- a/packages/alice/lib/core/alice_translations.dart +++ b/packages/alice/lib/core/alice_translations.dart @@ -168,8 +168,8 @@ class AliceTranslations { AliceTranslationKey.saveLogStackTrace: "Stack trace", AliceTranslationKey.saveLogCurl: "Curl", AliceTranslationKey.accept: "Accept", - AliceTranslationKey.parserFailed:"Failed to parse: ", - AliceTranslationKey.unknown:"Unknown", + AliceTranslationKey.parserFailed: "Failed to parse: ", + AliceTranslationKey.unknown: "Unknown", }); } @@ -231,7 +231,8 @@ class AliceTranslations { ' może renderować video/image/text. Odpowiedź ma typ zawartości:' "[contentType], który nie może być obsłużony.Jeżeli chcesz, możesz " "spróbować wyrenderować body jako tekst, ale może to się nie udać.", - AliceTranslationKey.callResponseBodyUnknownShow: "Pokaż nieobsługiwane body", + AliceTranslationKey.callResponseBodyUnknownShow: + "Pokaż nieobsługiwane body", AliceTranslationKey.callsListInspector: "Inspektor", AliceTranslationKey.callsListLogger: "Logger", AliceTranslationKey.callsListDeleteLogsDialogTitle: "Usuń logi", @@ -295,8 +296,7 @@ class AliceTranslations { AliceTranslationKey.saveDialogFileSaveErrorDescription: "Nie można zapisać danych do pliku.", AliceTranslationKey.saveSuccessTitle: "Logi zapisane", - AliceTranslationKey.saveSuccessDescription: - "Zapisano logi w [path].", + AliceTranslationKey.saveSuccessDescription: "Zapisano logi w [path].", AliceTranslationKey.saveSuccessView: "Otwórz plik", AliceTranslationKey.saveHeaderTitle: "Alice - Inspektor HTTP", AliceTranslationKey.saveHeaderAppName: "Nazwa aplikacji:", @@ -331,8 +331,8 @@ class AliceTranslations { AliceTranslationKey.saveLogStackTrace: "Ślad stosu", AliceTranslationKey.saveLogCurl: "Curl", AliceTranslationKey.accept: "Akceptuj", - AliceTranslationKey.parserFailed:"Problem z parsowaniem: ", - AliceTranslationKey.unknown:"Nieznane" + AliceTranslationKey.parserFailed: "Problem z parsowaniem: ", + AliceTranslationKey.unknown: "Nieznane" }); } diff --git a/packages/alice/lib/model/alice_translation.dart b/packages/alice/lib/model/alice_translation.dart index a07f996e..477ecf7f 100644 --- a/packages/alice/lib/model/alice_translation.dart +++ b/packages/alice/lib/model/alice_translation.dart @@ -1,6 +1,5 @@ /// Definition of translations for specific locale class AliceTranslationData { - /// Language code of locale, i.e (en_US) => en. final String languageCode; diff --git a/packages/alice/lib/ui/calls_list/page/alice_calls_list_page.dart b/packages/alice/lib/ui/calls_list/page/alice_calls_list_page.dart index ef7bec8e..2ac083b1 100644 --- a/packages/alice/lib/ui/calls_list/page/alice_calls_list_page.dart +++ b/packages/alice/lib/ui/calls_list/page/alice_calls_list_page.dart @@ -171,9 +171,9 @@ class _AliceCallsListPageState extends State String _getTabName({required AliceCallsListTabItem item}) { switch (item) { case AliceCallsListTabItem.inspector: - return context.i18n(AliceTranslationKey.callsListInspector); + return context.i18n(AliceTranslationKey.callsListInspector); case AliceCallsListTabItem.logger: - return context.i18n(AliceTranslationKey.callsListLogger); + return context.i18n(AliceTranslationKey.callsListLogger); } } diff --git a/packages/alice/lib/ui/common/alice_context_ext.dart b/packages/alice/lib/ui/common/alice_context_ext.dart index 05e5de4f..e47e23c0 100644 --- a/packages/alice/lib/ui/common/alice_context_ext.dart +++ b/packages/alice/lib/ui/common/alice_context_ext.dart @@ -1,19 +1,18 @@ - import 'dart:io'; +import 'dart:io'; import 'package:alice/model/alice_translation.dart'; import 'package:alice/core/alice_translations.dart'; import 'package:flutter/material.dart'; -extension AliceContextExt on BuildContext{ - String i18n(AliceTranslationKey key){ - try{ - final locale =Platform.localeName; +extension AliceContextExt on BuildContext { + String i18n(AliceTranslationKey key) { + try { + final locale = Platform.localeName; final languageCode = locale.split("_").first; return AliceTranslations.get(languageCode: languageCode, key: key); - - } catch (error){ + } catch (error) { return key.toString(); } } -} \ No newline at end of file +} From 77486003b6f11be0e6cc225086d61e89e73d2bdf Mon Sep 17 00:00:00 2001 From: Jakub Homlala Date: Fri, 28 Jun 2024 18:17:36 +0200 Subject: [PATCH 12/16] feat: added tests --- packages/alice/pubspec.yaml | 1 + .../test/core/alice_translations_test.dart | 43 +++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 packages/alice/test/core/alice_translations_test.dart diff --git a/packages/alice/pubspec.yaml b/packages/alice/pubspec.yaml index 377d8122..e5855279 100644 --- a/packages/alice/pubspec.yaml +++ b/packages/alice/pubspec.yaml @@ -26,3 +26,4 @@ dependencies: dev_dependencies: flutter_lints: ^4.0.0 lints: ^4.0.0 + test: ^1.25.2 diff --git a/packages/alice/test/core/alice_translations_test.dart b/packages/alice/test/core/alice_translations_test.dart new file mode 100644 index 00000000..791421f5 --- /dev/null +++ b/packages/alice/test/core/alice_translations_test.dart @@ -0,0 +1,43 @@ +import 'package:alice/core/alice_translations.dart'; +import 'package:alice/model/alice_translation.dart'; +import 'package:test/test.dart'; + +void main() { + group("AliceTranslations", () { + test("should return translated key", () { + expect( + AliceTranslations.get( + languageCode: "en", + key: AliceTranslationKey.saveLogId, + ), + "Id:", + ); + + expect( + AliceTranslations.get( + languageCode: "en", + key: AliceTranslationKey.logsEmpty, + ), + "There are no logs to show", + ); + }); + + test("should return key when there's no translation found", () { + expect( + AliceTranslations.get( + languageCode: "xx", + key: AliceTranslationKey.saveLogId, + ), + AliceTranslationKey.saveLogId.toString(), + ); + + expect( + AliceTranslations.get( + languageCode: "xx", + key: AliceTranslationKey.logsEmpty, + ), + AliceTranslationKey.logsEmpty.toString(), + ); + }); + }); +} From 643b2f5b95205cf10b6099c3061a8132cf580319 Mon Sep 17 00:00:00 2001 From: Jakub Homlala Date: Fri, 28 Jun 2024 19:38:41 +0200 Subject: [PATCH 13/16] feat: fixed default behavior, added tests --- .../alice/lib/core/alice_translations.dart | 8 +++--- .../test/core/alice_translations_test.dart | 27 ++++++++++++++++--- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/packages/alice/lib/core/alice_translations.dart b/packages/alice/lib/core/alice_translations.dart index 218f10ce..d30275d5 100644 --- a/packages/alice/lib/core/alice_translations.dart +++ b/packages/alice/lib/core/alice_translations.dart @@ -248,7 +248,7 @@ class AliceTranslations { AliceTranslationKey.callsListDelete: "Usuń", AliceTranslationKey.callsListStats: "Statystyki", AliceTranslationKey.callsListSave: "Zapis", - AliceTranslationKey.logsEmpty: "Nie ma logów do pokazania", + AliceTranslationKey.logsEmpty: "Brak rezultatów", AliceTranslationKey.logsItemError: "Błąd:", AliceTranslationKey.logsItemStackTrace: "Ślad stosu:", AliceTranslationKey.logsCopied: "Skopiowano do schowka.", @@ -343,8 +343,10 @@ class AliceTranslations { required AliceTranslationKey key, }) { try { - final data = _translations - .firstWhere((element) => element.languageCode == languageCode); + final data = _translations.firstWhere( + (element) => element.languageCode == languageCode, + orElse: () => _translations.first, + ); final value = data.values[key] ?? key.toString(); return value; } catch (error) { diff --git a/packages/alice/test/core/alice_translations_test.dart b/packages/alice/test/core/alice_translations_test.dart index 791421f5..4561a78c 100644 --- a/packages/alice/test/core/alice_translations_test.dart +++ b/packages/alice/test/core/alice_translations_test.dart @@ -4,7 +4,7 @@ import 'package:test/test.dart'; void main() { group("AliceTranslations", () { - test("should return translated key", () { + test("should return translated value", () { expect( AliceTranslations.get( languageCode: "en", @@ -22,13 +22,14 @@ void main() { ); }); - test("should return key when there's no translation found", () { + test("should return english translation when there's no translation found", + () { expect( AliceTranslations.get( languageCode: "xx", key: AliceTranslationKey.saveLogId, ), - AliceTranslationKey.saveLogId.toString(), + "Id:", ); expect( @@ -36,7 +37,25 @@ void main() { languageCode: "xx", key: AliceTranslationKey.logsEmpty, ), - AliceTranslationKey.logsEmpty.toString(), + "There are no logs to show", + ); + }); + + test("should return translated key for other languages", () { + expect( + AliceTranslations.get( + languageCode: "pl", + key: AliceTranslationKey.logsEmpty, + ), + "Brak rezultatów", + ); + + expect( + AliceTranslations.get( + languageCode: "pl", + key: AliceTranslationKey.saveLogRequest, + ), + "Żądanie", ); }); }); From b3673ce499803f5d521139424713c2b9b818c128 Mon Sep 17 00:00:00 2001 From: Jakub Homlala Date: Fri, 28 Jun 2024 21:58:30 +0200 Subject: [PATCH 14/16] feat: fixes after merge --- packages/alice/lib/core/alice_core.dart | 17 +++++++++++------ packages/alice/lib/core/alice_translations.dart | 2 +- .../alice/lib/ui/common/alice_context_ext.dart | 8 ++------ 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/packages/alice/lib/core/alice_core.dart b/packages/alice/lib/core/alice_core.dart index d92b0279..ae191238 100644 --- a/packages/alice/lib/core/alice_core.dart +++ b/packages/alice/lib/core/alice_core.dart @@ -2,7 +2,6 @@ import 'dart:async' show StreamSubscription; import 'dart:io' show Platform; import 'package:alice/core/alice_logger.dart'; -import 'package:alice/core/alice_translations.dart'; import 'package:alice/core/alice_storage.dart'; import 'package:alice/core/alice_utils.dart'; import 'package:alice/helper/alice_save_helper.dart'; @@ -167,10 +166,14 @@ class AliceCore { BuildContext? getContext() => navigatorKey?.currentState?.overlay?.context; String _getNotificationMessage(AliceStats stats) => [ - if (stats.loading > 0) 'Loading: ${stats.loading}', - if (stats.successes > 0) 'Success: ${stats.successes}', - if (stats.redirects > 0) 'Redirect: ${stats.redirects}', - if (stats.errors > 0) 'Error: ${stats.errors}', + if (stats.loading > 0) + '${getContext()?.i18n(AliceTranslationKey.notificationLoading)} ${stats.loading}', + if (stats.successes > 0) + '${getContext()?.i18n(AliceTranslationKey.notificationSuccess)} ${stats.successes}', + if (stats.redirects > 0) + '${getContext()?.i18n(AliceTranslationKey.notificationRedirect)} ${stats.redirects}', + if (stats.errors > 0) + '${getContext()?.i18n(AliceTranslationKey.notificationError)} ${stats.errors}', ].join(' | '); Future _requestNotificationPermissions() async { @@ -209,7 +212,9 @@ class AliceCore { await _flutterLocalNotificationsPlugin?.show( 0, - 'Alice (total: ${stats.total} requests)', + getContext() + ?.i18n(AliceTranslationKey.notificationTotalRequests) + .replaceAll("[requestCount]", stats.total.toString()), message, _notificationDetails, payload: '', diff --git a/packages/alice/lib/core/alice_translations.dart b/packages/alice/lib/core/alice_translations.dart index d30275d5..9b585146 100644 --- a/packages/alice/lib/core/alice_translations.dart +++ b/packages/alice/lib/core/alice_translations.dart @@ -280,7 +280,7 @@ class AliceTranslations { AliceTranslationKey.statsPatchRequests: "Żądania PATCH:", AliceTranslationKey.statsSecuredRequests: "Żądania zabezpieczone:", AliceTranslationKey.statsUnsecuredRequests: "Żądania niezabezpieczone:", - AliceTranslationKey.notificationLoading: "Oczekiwanie:", + AliceTranslationKey.notificationLoading: "Oczekujące:", AliceTranslationKey.notificationSuccess: "Poprawne:", AliceTranslationKey.notificationRedirect: "Przekierowanie:", AliceTranslationKey.notificationError: "Błąd:", diff --git a/packages/alice/lib/ui/common/alice_context_ext.dart b/packages/alice/lib/ui/common/alice_context_ext.dart index e47e23c0..30022cd6 100644 --- a/packages/alice/lib/ui/common/alice_context_ext.dart +++ b/packages/alice/lib/ui/common/alice_context_ext.dart @@ -1,5 +1,3 @@ -import 'dart:io'; - import 'package:alice/model/alice_translation.dart'; import 'package:alice/core/alice_translations.dart'; import 'package:flutter/material.dart'; @@ -7,10 +5,8 @@ import 'package:flutter/material.dart'; extension AliceContextExt on BuildContext { String i18n(AliceTranslationKey key) { try { - final locale = Platform.localeName; - - final languageCode = locale.split("_").first; - return AliceTranslations.get(languageCode: languageCode, key: key); + final locale = Localizations.localeOf(this); + return AliceTranslations.get(languageCode: locale.languageCode, key: key); } catch (error) { return key.toString(); } From 3031a761d2fd10578060fc0e1d2c44539675c0d2 Mon Sep 17 00:00:00 2001 From: Jakub Homlala Date: Fri, 28 Jun 2024 22:03:56 +0200 Subject: [PATCH 15/16] feat: updated metadata --- docs/install.md | 2 +- packages/alice/CHANGELOG.md | 5 +++++ packages/alice/pubspec.yaml | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/docs/install.md b/docs/install.md index f177b3d3..a691d6a3 100644 --- a/docs/install.md +++ b/docs/install.md @@ -4,7 +4,7 @@ ```yaml dependencies: - alice: ^1.0.0-dev7 + alice: ^1.0.0-dev8 ``` 2. Choose adapter based on your HTTP client. **pubspec.yaml** file: diff --git a/packages/alice/CHANGELOG.md b/packages/alice/CHANGELOG.md index bd21970d..d777bef6 100644 --- a/packages/alice/CHANGELOG.md +++ b/packages/alice/CHANGELOG.md @@ -1,3 +1,8 @@ +# 1.0.0-dev.8 +* Added storage abstractions (by Klemen Tusar https://github.com/techouse). +* Added in memory storage implementation (by Klemen Tusar https://github.com/techouse). +* Added translations. + # 1.0.0-dev.7 * Refactored UI code. diff --git a/packages/alice/pubspec.yaml b/packages/alice/pubspec.yaml index e5855279..6c82b106 100644 --- a/packages/alice/pubspec.yaml +++ b/packages/alice/pubspec.yaml @@ -1,6 +1,6 @@ name: alice description: Alice is an HTTP Inspector tool which helps debugging http requests. It catches and stores http requests and responses, which can be viewed via simple UI. -version: 1.0.0-dev.7 +version: 1.0.0-dev.8 homepage: https://github.com/jhomlala/alice repository: https://github.com/jhomlala/alice From ed732179662e1b8feac1aa499f5c2ccd6ca5de8d Mon Sep 17 00:00:00 2001 From: Jakub Homlala Date: Fri, 28 Jun 2024 22:05:47 +0200 Subject: [PATCH 16/16] feat: updated metadata --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 45f09e20..18812b8a 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ [![pub package](https://img.shields.io/pub/v/alice_chopper.svg)](https://pub.dartlang.org/packages/alice_chopper) [![pub package](https://img.shields.io/pub/v/alice_http.svg)](https://pub.dartlang.org/packages/alice_http) [![pub package](https://img.shields.io/pub/v/alice_http_client.svg)](https://pub.dartlang.org/packages/alice_http_client) +[![pub package](https://img.shields.io/pub/v/alice_objectbox.svg)](https://pub.dartlang.org/packages/alice_objectbox) [![pub package](https://img.shields.io/badge/platform-flutter-blue.svg)](https://github.com/jhomlala/alice) [![melos](https://img.shields.io/badge/maintained%20with-melos-f700ff.svg?style=flat-square)](https://github.com/invertase/melos)