From 608016c8ada6e1d3b672b372ba403f18c93066c1 Mon Sep 17 00:00:00 2001 From: alex-chevski Date: Fri, 20 Nov 2026 17:42:03 +0300 Subject: [PATCH] feat(l10n): localize rating place and favorite error messages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - add rating_place and error_try_again_later ARB keys (ru/en) - use S.rating_place in profile screen, plan widget and author card - use S.current.error_try_again_later in profile plans cubit - hide rating badge when rating place is null instead of rendering null-й - initialize localization in profile plans cubit test --- .../presentation/widgets/author_card.dart | 5 +- .../presentation/widgets/plan_widget.dart | 33 +++++---- .../bloc/plans_cubit/plans_cubit.dart | 4 +- .../presentation/pages/profile_screen.dart | 70 ++++++++++--------- lib/generated/intl/messages_en.dart | 5 ++ lib/generated/intl/messages_ru.dart | 5 ++ lib/generated/l10n.dart | 20 ++++++ lib/l10n/intl_en.arb | 9 ++- lib/l10n/intl_ru.arb | 9 ++- .../profile_plans_cubit_like_test.dart | 5 +- 10 files changed, 112 insertions(+), 53 deletions(-) diff --git a/lib/features/diets/presentation/widgets/author_card.dart b/lib/features/diets/presentation/widgets/author_card.dart index 705c717f..71ec57c1 100644 --- a/lib/features/diets/presentation/widgets/author_card.dart +++ b/lib/features/diets/presentation/widgets/author_card.dart @@ -7,6 +7,7 @@ import 'package:eatvio_app/core/utils/url_utils.dart'; import 'package:eatvio_app/core/theme/theme_helper.dart'; import 'package:eatvio_app/features/profile/models/profile_model.dart'; import 'package:eatvio_app/features/user_details/presentation/user_details_screen.dart'; +import 'package:eatvio_app/generated/l10n.dart'; import 'package:material_ui/material_ui.dart'; import 'package:flutter_svg/svg.dart'; import 'package:go_router/go_router.dart'; @@ -107,7 +108,9 @@ class AuthorCard extends StatelessWidget { backgroundColor: appTheme.cardBackground, children: [ Text( - '${author.authorPlaceInRating}-й в рейтинге', + S.of(context).rating_place( + author.authorPlaceInRating!, + ), style: TextStyles.textMMediumAuto.copyWith( color: appTheme.blueA400, ), diff --git a/lib/features/feed/presentation/widgets/plan_widget.dart b/lib/features/feed/presentation/widgets/plan_widget.dart index d6784ead..b5ad3bee 100644 --- a/lib/features/feed/presentation/widgets/plan_widget.dart +++ b/lib/features/feed/presentation/widgets/plan_widget.dart @@ -202,22 +202,25 @@ class _PlanWidgetState extends State { ), subtitle: Row( children: [ - InfoBouble( - radius: 12, - backgroundColor: appTheme.gray50, - padding: const EdgeInsets.symmetric( - vertical: 4, - horizontal: 10, - ), - children: [ - Text( - '${widget.plan.author.authorPlaceInRating}-й в рейтинге', - style: TextStyles.textXSSemibold.copyWith( - color: appTheme.blueA400, - ), + if (widget.plan.author.authorPlaceInRating != null) + InfoBouble( + radius: 12, + backgroundColor: appTheme.gray50, + padding: const EdgeInsets.symmetric( + vertical: 4, + horizontal: 10, ), - ], - ), + children: [ + Text( + s.rating_place( + widget.plan.author.authorPlaceInRating!, + ), + style: TextStyles.textXSSemibold.copyWith( + color: appTheme.blueA400, + ), + ), + ], + ), const Spacer(), Text( '${widget.plan.packetsCount == 1 ? widget.plan.packet1Options?.price : '${s.from} ${widget.plan.minPriceOfOptions.toStringAsFixed(0)}'}₽', diff --git a/lib/features/profile/presentation/bloc/plans_cubit/plans_cubit.dart b/lib/features/profile/presentation/bloc/plans_cubit/plans_cubit.dart index 1d7557ca..ec70775b 100644 --- a/lib/features/profile/presentation/bloc/plans_cubit/plans_cubit.dart +++ b/lib/features/profile/presentation/bloc/plans_cubit/plans_cubit.dart @@ -9,6 +9,7 @@ import 'package:eatvio_app/features/feed/models/plan_pagination_model.dart'; import 'package:eatvio_app/features/plans/repositories/plan_repository.dart'; import 'package:eatvio_app/features/plans/repositories/plans_repository.dart'; import 'package:eatvio_app/features/profile/presentation/bloc/plans_cubit/plans_state.dart'; +import 'package:eatvio_app/generated/l10n.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; class PlansCubit extends Cubit { @@ -16,7 +17,6 @@ class PlansCubit extends Cubit { final PlanRepository planRepository; static const Duration _debounceDuration = Duration(milliseconds: 200); - static const String _favoriteErrorMessage = 'Произошла ошибка. Попробуйте ещё раз через некоторое время'; late final StreamSubscription likesStateSubscription; late final StreamSubscription favoriteStateSubscription; @@ -109,7 +109,7 @@ class PlansCubit extends Cubit { await reportFrom(e, st, this); if (isClosed) return; _updatePlanBySlug(slug, (plan) => plan.copyWith(isFavorite: previousIsFavorite)); - showErrorToast(_favoriteErrorMessage); + showErrorToast(S.current.error_try_again_later); } }); } diff --git a/lib/features/profile/presentation/pages/profile_screen.dart b/lib/features/profile/presentation/pages/profile_screen.dart index f4b30801..d64421f2 100644 --- a/lib/features/profile/presentation/pages/profile_screen.dart +++ b/lib/features/profile/presentation/pages/profile_screen.dart @@ -205,24 +205,27 @@ class _ProfileScreenState extends State { ), ), const SizedBox(width: 12), - Container( - padding: const EdgeInsets.symmetric( - horizontal: 12, - vertical: 8, - ), - decoration: BoxDecoration( - color: const Color(0xFFF6FAFF), - borderRadius: BorderRadius.circular(12), - ), - child: Text( - '${state.consultantInfo!.ratingPlace}-й в рейтинге', - style: TextStyle( - fontSize: 16, - fontWeight: FontWeight.w600, - color: appTheme.blueA400, + if (state.consultantInfo!.ratingPlace != null) + Container( + padding: const EdgeInsets.symmetric( + horizontal: 12, + vertical: 8, + ), + decoration: BoxDecoration( + color: const Color(0xFFF6FAFF), + borderRadius: BorderRadius.circular(12), + ), + child: Text( + S.of(context).rating_place( + state.consultantInfo!.ratingPlace!, + ), + style: TextStyle( + fontSize: 16, + fontWeight: FontWeight.w600, + color: appTheme.blueA400, + ), ), ), - ), ], ), if (state @@ -378,24 +381,27 @@ class _ProfileScreenState extends State { ), ), const SizedBox(width: 12), - Container( - padding: const EdgeInsets.symmetric( - horizontal: 12, - vertical: 8, - ), - decoration: BoxDecoration( - color: const Color(0xFFF6FAFF), - borderRadius: BorderRadius.circular(12), - ), - child: Text( - '${consultantInfo.ratingPlace}-й в рейтинге', - style: TextStyle( - fontSize: 16, - fontWeight: FontWeight.w600, - color: appTheme.blueA400, + if (consultantInfo.ratingPlace != null) + Container( + padding: const EdgeInsets.symmetric( + horizontal: 12, + vertical: 8, + ), + decoration: BoxDecoration( + color: const Color(0xFFF6FAFF), + borderRadius: BorderRadius.circular(12), + ), + child: Text( + S.of(context).rating_place( + consultantInfo.ratingPlace!, + ), + style: TextStyle( + fontSize: 16, + fontWeight: FontWeight.w600, + color: appTheme.blueA400, + ), ), ), - ), ], ), if (consultantInfo.educationModel.hasMedicalEducation == 1) diff --git a/lib/generated/intl/messages_en.dart b/lib/generated/intl/messages_en.dart index a7560f42..fa0b1557 100644 --- a/lib/generated/intl/messages_en.dart +++ b/lib/generated/intl/messages_en.dart @@ -99,6 +99,8 @@ class MessageLookup extends MessageLookupByLibrary { static String m31(planName) => "Вы отменили подписку на план «${planName}»"; + static String m32(place) => "#${place} in the ranking"; + final messages = _notInlinedMessages(_notInlinedMessages); static Map _notInlinedMessages(_) => { "Moscow": MessageLookupByLibrary.simpleMessage("Москва"), @@ -370,6 +372,8 @@ class MessageLookup extends MessageLookupByLibrary { MessageLookupByLibrary.simpleMessage("Enter promo code"), "error_desc": MessageLookupByLibrary.simpleMessage( "Произошла ошибка. Мы уже работаем над её устранением. Попробуйте позже"), + "error_try_again_later": MessageLookupByLibrary.simpleMessage( + "Something went wrong. Please try again later."), "exit": MessageLookupByLibrary.simpleMessage("Выйти"), "expand": MessageLookupByLibrary.simpleMessage("Показать полностью"), "explainResonOfCancelation": @@ -794,6 +798,7 @@ class MessageLookup extends MessageLookupByLibrary { MessageLookupByLibrary.simpleMessage("Рейтинг и статистика"), "rating_history": MessageLookupByLibrary.simpleMessage("Начисление рейтинга"), + "rating_place": m32, "reasonExample": MessageLookupByLibrary.simpleMessage("Заказал по ошибке"), "recipe_author": MessageLookupByLibrary.simpleMessage("Автор рецепта"), diff --git a/lib/generated/intl/messages_ru.dart b/lib/generated/intl/messages_ru.dart index ca52a88e..0729e17d 100644 --- a/lib/generated/intl/messages_ru.dart +++ b/lib/generated/intl/messages_ru.dart @@ -73,6 +73,8 @@ class MessageLookup extends MessageLookupByLibrary { static String m30(percent) => "Скачивание… ${percent}%"; + static String m31(place) => "${place}-й в рейтинге"; + final messages = _notInlinedMessages(_notInlinedMessages); static Map _notInlinedMessages(_) => { "Moscow": MessageLookupByLibrary.simpleMessage("Москва"), @@ -197,6 +199,8 @@ class MessageLookup extends MessageLookupByLibrary { MessageLookupByLibrary.simpleMessage("Введите информацию..."), "enter_promo_code": MessageLookupByLibrary.simpleMessage("Введите промокод"), + "error_try_again_later": MessageLookupByLibrary.simpleMessage( + "Произошла ошибка. Попробуйте ещё раз через некоторое время"), "exit": MessageLookupByLibrary.simpleMessage("Выйти"), "expand": MessageLookupByLibrary.simpleMessage("Показать полностью"), "fats": MessageLookupByLibrary.simpleMessage("Жиры"), @@ -486,6 +490,7 @@ class MessageLookup extends MessageLookupByLibrary { "public_diet_state": MessageLookupByLibrary.simpleMessage("Публичная"), "publish": MessageLookupByLibrary.simpleMessage("Опубликовать"), "published": MessageLookupByLibrary.simpleMessage("Опубликованные"), + "rating_place": m31, "removeFromActive": MessageLookupByLibrary.simpleMessage("Снять с публикации"), "save": MessageLookupByLibrary.simpleMessage("Сохранить"), diff --git a/lib/generated/l10n.dart b/lib/generated/l10n.dart index 76576ed6..a9946216 100644 --- a/lib/generated/l10n.dart +++ b/lib/generated/l10n.dart @@ -6411,6 +6411,26 @@ class S { args: [], ); } + + /// `{place}-й в рейтинге` + String rating_place(int place) { + return Intl.message( + '$place-й в рейтинге', + name: 'rating_place', + desc: '', + args: [place], + ); + } + + /// `Произошла ошибка. Попробуйте ещё раз через некоторое время` + String get error_try_again_later { + return Intl.message( + 'Произошла ошибка. Попробуйте ещё раз через некоторое время', + name: 'error_try_again_later', + desc: '', + args: [], + ); + } } class AppLocalizationDelegate extends LocalizationsDelegate { diff --git a/lib/l10n/intl_en.arb b/lib/l10n/intl_en.arb index 82c7d289..972fc86e 100644 --- a/lib/l10n/intl_en.arb +++ b/lib/l10n/intl_en.arb @@ -837,5 +837,12 @@ "video_call_recordings_period_week": "7 days", "video_call_recordings_period_current_month": "Current month", "video_call_recordings_period_prev_month": "Previous month", - "video_call_recordings_period_all": "All time" + "video_call_recordings_period_all": "All time", + "rating_place": "#{place} in the ranking", + "@rating_place": { + "placeholders": { + "place": {"type": "int"} + } + }, + "error_try_again_later": "Something went wrong. Please try again later." } diff --git a/lib/l10n/intl_ru.arb b/lib/l10n/intl_ru.arb index b6960122..cc469a53 100644 --- a/lib/l10n/intl_ru.arb +++ b/lib/l10n/intl_ru.arb @@ -592,5 +592,12 @@ "video_call_recordings_period_week": "7 дней", "video_call_recordings_period_current_month": "Текущий месяц", "video_call_recordings_period_prev_month": "Прошлый месяц", - "video_call_recordings_period_all": "Всё время" + "video_call_recordings_period_all": "Всё время", + "rating_place": "{place}-й в рейтинге", + "@rating_place": { + "placeholders": { + "place": {"type": "int"} + } + }, + "error_try_again_later": "Произошла ошибка. Попробуйте ещё раз через некоторое время" } diff --git a/test/features/profile/presentation/bloc/plans_cubit/profile_plans_cubit_like_test.dart b/test/features/profile/presentation/bloc/plans_cubit/profile_plans_cubit_like_test.dart index 8af8345d..30bfdefe 100644 --- a/test/features/profile/presentation/bloc/plans_cubit/profile_plans_cubit_like_test.dart +++ b/test/features/profile/presentation/bloc/plans_cubit/profile_plans_cubit_like_test.dart @@ -1,4 +1,5 @@ import 'dart:async'; +import 'dart:ui' show Locale; import 'package:easy_debounce/easy_debounce.dart'; import 'package:eatvio_app/core/error_reporting/error_reporter.dart'; @@ -9,6 +10,7 @@ import 'package:eatvio_app/features/plans/repositories/plan_repository.dart'; import 'package:eatvio_app/features/plans/repositories/plans_repository.dart'; import 'package:eatvio_app/features/profile/presentation/bloc/plans_cubit/plans_cubit.dart'; import 'package:eatvio_app/features/profile/presentation/bloc/plans_cubit/plans_state.dart'; +import 'package:eatvio_app/generated/l10n.dart'; import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:mockito/annotations.dart'; @@ -69,7 +71,8 @@ void main() { ); } - setUpAll(() { + setUpAll(() async { + await S.load(const Locale('ru')); TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger .setMockMethodCallHandler( const MethodChannel('PonnamKarthik/fluttertoast'),