From 5c056797a0a9d6384cbd7731f23b1fa2f44e4dfd Mon Sep 17 00:00:00 2001 From: MaD Date: Tue, 17 Dec 2024 00:09:10 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BB=D0=BE=D0=BA=D0=B0=D0=BB=D0=B8=D0=B7?= =?UTF-8?q?=D0=B0=D1=86=D0=B8=D1=8F=203?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- l10n/app_en.arb | 3 + l10n/app_ru.arb | 3 + lib/Components/locale/l10n/app_locale.dart | 84 +++++++++++++++++-- lib/Components/locale/l10n/app_locale_en.dart | 9 +- lib/Components/locale/l10n/app_locale_ru.dart | 11 ++- 5 files changed, 94 insertions(+), 16 deletions(-) diff --git a/l10n/app_en.arb b/l10n/app_en.arb index adeccaa..7807fb4 100644 --- a/l10n/app_en.arb +++ b/l10n/app_en.arb @@ -4,6 +4,9 @@ "search": "Search", "liked": "liked!", "disliked": "disliked :<", + "heroDetailsTitle": "Hero Details", + "heroNoImage": "No image available", + "heroNoDescription": "No description available", "arbEnding": "ЗАПЯТАЯ" } \ No newline at end of file diff --git a/l10n/app_ru.arb b/l10n/app_ru.arb index 7dede04..c327bfb 100644 --- a/l10n/app_ru.arb +++ b/l10n/app_ru.arb @@ -4,6 +4,9 @@ "search": "Поиск", "liked": "нравится!", "disliked": "не нравится :<", + "heroDetailsTitle": "Детали героя", + "heroNoImage": "Изображение недоступно", + "heroNoDescription": "Описание отсутствует", "arbEnding": "ЗАПЯТАЯ" } \ No newline at end of file diff --git a/lib/Components/locale/l10n/app_locale.dart b/lib/Components/locale/l10n/app_locale.dart index 0dd0f4f..7a48806 100644 --- a/lib/Components/locale/l10n/app_locale.dart +++ b/lib/Components/locale/l10n/app_locale.dart @@ -72,6 +72,16 @@ abstract class AppLocale { static const LocalizationsDelegate delegate = _AppLocaleDelegate(); + /// A list of this localizations delegate along with the default localizations + /// delegates. + /// + /// Returns a list of localizations delegates containing this delegate along with + /// GlobalMaterialLocalizations.delegate, GlobalCupertinoLocalizations.delegate, + /// and GlobalWidgetsLocalizations.delegate. + /// + /// Additional delegates can be added by appending to this list in + /// MaterialApp. This list does not have to be used at all if a custom list + /// of delegates is preferred or required. static const List> localizationsDelegates = >[ delegate, GlobalMaterialLocalizations.delegate, @@ -79,19 +89,83 @@ abstract class AppLocale { GlobalWidgetsLocalizations.delegate, ]; + /// A list of this localizations delegate's supported locales. static const List supportedLocales = [ Locale('en'), Locale('ru') ]; - // Существующие строки + /// No description provided for @search. + /// + /// In ru, this message translates to: + /// **'Поиск'** String get search; - String get liked; - String get disliked; - String get arbEnding; - // Новые строки для HeroDetailScreen + /// No description provided for @liked. + /// + /// In ru, this message translates to: + /// **'нравится!'** + String get liked; + + /// No description provided for @disliked. + /// + /// In ru, this message translates to: + /// **'не нравится :<'** + String get disliked; + + /// No description provided for @heroDetailsTitle. + /// + /// In ru, this message translates to: + /// **'Детали героя'** String get heroDetailsTitle; + + /// No description provided for @heroNoImage. + /// + /// In ru, this message translates to: + /// **'Изображение недоступно'** String get heroNoImage; + + /// No description provided for @heroNoDescription. + /// + /// In ru, this message translates to: + /// **'Описание отсутствует'** String get heroNoDescription; + + /// No description provided for @arbEnding. + /// + /// In ru, this message translates to: + /// **'ЗАПЯТАЯ'** + String get arbEnding; +} + +class _AppLocaleDelegate extends LocalizationsDelegate { + const _AppLocaleDelegate(); + + @override + Future load(Locale locale) { + return SynchronousFuture(lookupAppLocale(locale)); + } + + @override + bool isSupported(Locale locale) => ['en', 'ru'].contains(locale.languageCode); + + @override + bool shouldReload(_AppLocaleDelegate old) => false; +} + +AppLocale lookupAppLocale(Locale locale) { + + + // Lookup logic when only language code is specified. + switch (locale.languageCode) { + case 'en': return AppLocaleEn(); + case 'ru': return AppLocaleRu(); + } + + throw FlutterError( + 'AppLocale.delegate failed to load unsupported locale "$locale". This is likely ' + 'an issue with the localizations generation tool. Please file an issue ' + 'on GitHub with a reproducible sample app and the gen-l10n configuration ' + 'that was used.' + ); } diff --git a/lib/Components/locale/l10n/app_locale_en.dart b/lib/Components/locale/l10n/app_locale_en.dart index 0482233..76c31d2 100644 --- a/lib/Components/locale/l10n/app_locale_en.dart +++ b/lib/Components/locale/l10n/app_locale_en.dart @@ -15,10 +15,6 @@ class AppLocaleEn extends AppLocale { @override String get disliked => 'disliked :<'; - @override - String get arbEnding => 'COMMA'; - - // Добавленные строки @override String get heroDetailsTitle => 'Hero Details'; @@ -27,4 +23,7 @@ class AppLocaleEn extends AppLocale { @override String get heroNoDescription => 'No description available'; -} \ No newline at end of file + + @override + String get arbEnding => 'ЗАПЯТАЯ'; +} diff --git a/lib/Components/locale/l10n/app_locale_ru.dart b/lib/Components/locale/l10n/app_locale_ru.dart index 1a0e8ef..b86b145 100644 --- a/lib/Components/locale/l10n/app_locale_ru.dart +++ b/lib/Components/locale/l10n/app_locale_ru.dart @@ -15,16 +15,15 @@ class AppLocaleRu extends AppLocale { @override String get disliked => 'не нравится :<'; - @override - String get arbEnding => 'ЗАПЯТАЯ'; - - // Добавленные строки @override String get heroDetailsTitle => 'Детали героя'; @override - String get heroNoImage => 'Изображение отсутствует'; + String get heroNoImage => 'Изображение недоступно'; @override String get heroNoDescription => 'Описание отсутствует'; -} \ No newline at end of file + + @override + String get arbEnding => 'ЗАПЯТАЯ'; +}