From 3106eda7a214476d32a762924f8159d46cb8b144 Mon Sep 17 00:00:00 2001 From: Jan Marsh Date: Thu, 15 Sep 2022 12:49:23 +0200 Subject: [PATCH 1/6] adding translations --- l10n.yaml | 4 ++++ lib/main.dart | 5 ++++- lib/src/app.dart | 8 ++++++++ lib/src/core/extensions/localization.extension.dart | 6 ++++++ lib/src/core/localization/app_de.arb | 4 ++++ lib/src/core/localization/app_en.arb | 7 +++++++ .../presentation/dashboard/view/dashboard.page.dart | 3 ++- pubspec.lock | 12 ++++++++++++ pubspec.yaml | 9 ++++++--- 9 files changed, 53 insertions(+), 5 deletions(-) create mode 100644 l10n.yaml create mode 100644 lib/src/core/extensions/localization.extension.dart create mode 100644 lib/src/core/localization/app_de.arb create mode 100644 lib/src/core/localization/app_en.arb diff --git a/l10n.yaml b/l10n.yaml new file mode 100644 index 0000000..1b9efff --- /dev/null +++ b/l10n.yaml @@ -0,0 +1,4 @@ +arb-dir: lib/src/core/localization +template-arb-file: app_en.arb +output-localization-file: app_localizations.dart +nullable-getter: false diff --git a/lib/main.dart b/lib/main.dart index 847b865..9274c45 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -2,8 +2,11 @@ import 'package:counter_workshop/src/app.dart'; import 'package:counter_workshop/src/features/counter/data/datasources/remote/src/mock/counter_fake.api.dart'; import 'package:counter_workshop/src/features/counter/data/repositories/counter.repository.dart'; import 'package:flutter/material.dart'; +import 'package:intl/intl.dart'; +import 'package:intl/intl_standalone.dart' if (dart.library.html) 'package:intl/intl_browser.dart'; -void main() { +Future main() async { + Intl.systemLocale = await findSystemLocale(); final CounterRepository counterRepository = CounterRepository(counterApi: CounterFakeApi()); runApp( App( diff --git a/lib/src/app.dart b/lib/src/app.dart index a494fd0..e0923fd 100644 --- a/lib/src/app.dart +++ b/lib/src/app.dart @@ -5,6 +5,8 @@ import 'package:counter_workshop/src/features/counter/presentation/dashboard/blo import 'package:counter_workshop/src/features/counter/presentation/dashboard/bloc/dashboard.event.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:flutter_localizations/flutter_localizations.dart'; +import 'package:flutter_gen/gen_l10n/app_localizations.dart'; class App extends StatefulWidget { const App({required this.counterRepository, super.key}); @@ -53,6 +55,12 @@ class AppView extends StatelessWidget { routeInformationProvider: router.routeInformationProvider, routeInformationParser: router.routeInformationParser, routerDelegate: router.routerDelegate, + localizationsDelegates: const [ + AppLocalizations.delegate, + GlobalMaterialLocalizations.delegate, + GlobalWidgetsLocalizations.delegate, + GlobalCupertinoLocalizations.delegate, + ], ); } } diff --git a/lib/src/core/extensions/localization.extension.dart b/lib/src/core/extensions/localization.extension.dart new file mode 100644 index 0000000..02ab7f8 --- /dev/null +++ b/lib/src/core/extensions/localization.extension.dart @@ -0,0 +1,6 @@ +import 'package:flutter/widgets.dart'; +import 'package:flutter_gen/gen_l10n/app_localizations.dart'; + +extension LocalizationExtension on BuildContext { + AppLocalizations get loc => AppLocalizations.of(this); +} diff --git a/lib/src/core/localization/app_de.arb b/lib/src/core/localization/app_de.arb new file mode 100644 index 0000000..0d88e03 --- /dev/null +++ b/lib/src/core/localization/app_de.arb @@ -0,0 +1,4 @@ +{ + "@@locale": "de", + "appTitle": "Zähler" +} diff --git a/lib/src/core/localization/app_en.arb b/lib/src/core/localization/app_en.arb new file mode 100644 index 0000000..42ec6f6 --- /dev/null +++ b/lib/src/core/localization/app_en.arb @@ -0,0 +1,7 @@ +{ + "@@locale": "en", + "appTitle": "Counter", + "@appTitle": { + "description": "Name of the app" + } +} diff --git a/lib/src/features/counter/presentation/dashboard/view/dashboard.page.dart b/lib/src/features/counter/presentation/dashboard/view/dashboard.page.dart index 0e3d57a..9433ae0 100644 --- a/lib/src/features/counter/presentation/dashboard/view/dashboard.page.dart +++ b/lib/src/features/counter/presentation/dashboard/view/dashboard.page.dart @@ -1,3 +1,4 @@ +import 'package:counter_workshop/src/core/extensions/localization.extension.dart'; import 'package:counter_workshop/src/core/widgets/error_message.widget.dart'; import 'package:counter_workshop/src/features/counter/presentation/dashboard/bloc/dashboard.bloc.dart'; import 'package:counter_workshop/src/features/counter/presentation/dashboard/bloc/dashboard.state.dart'; @@ -15,7 +16,7 @@ class DashboardPage extends StatelessWidget { return Scaffold( extendBodyBehindAppBar: true, appBar: AppBar( - title: const Text('Counter Page'), + title: Text(context.loc.appTitle), ), body: BlocBuilder( builder: (context, state) { diff --git a/pubspec.lock b/pubspec.lock index a72db10..9112bda 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -209,6 +209,11 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.0.1" + flutter_localizations: + dependency: "direct main" + description: flutter + source: sdk + version: "0.0.0" flutter_test: dependency: "direct dev" description: flutter @@ -268,6 +273,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "4.0.1" + intl: + dependency: "direct main" + description: + name: intl + url: "https://pub.dartlang.org" + source: hosted + version: "0.17.0" io: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 43377bb..a998cab 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -11,7 +11,9 @@ environment: dependencies: flutter: sdk: flutter - + flutter_localizations: + sdk: flutter + intl: ^0.17.0 cupertino_icons: ^1.0.2 equatable: ^2.0.5 http: ^0.13.5 @@ -27,7 +29,8 @@ dev_dependencies: flutter: uses-material-design: true - + generate: true # Enable generation of localized Strings from arb files + fonts: - family: VarelaRound fonts: @@ -37,4 +40,4 @@ flutter: - assets/images/ # .png/.jpg images - assets/icons/ # .svg icons - assets/fonts/ # Custom Fonts - - assets/launcher_icon/ # App icon image to generate from \ No newline at end of file + - assets/launcher_icon/ # App icon image to generate from From 597b107e80c04b1367c910604a35b911f0f5814a Mon Sep 17 00:00:00 2001 From: Jan Marsh Date: Thu, 15 Sep 2022 12:56:13 +0200 Subject: [PATCH 2/6] adding explaination --- l10n.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/l10n.yaml b/l10n.yaml index 1b9efff..9772ffa 100644 --- a/l10n.yaml +++ b/l10n.yaml @@ -1,4 +1,4 @@ -arb-dir: lib/src/core/localization -template-arb-file: app_en.arb -output-localization-file: app_localizations.dart +arb-dir: lib/src/core/localization # Where to find translation files +template-arb-file: app_en.arb # Which translation is the default/template +output-localization-file: app_localizations.dart # What to call generated dart files nullable-getter: false From b310fe1a29794cdb08404a8b7fea37ba6f5bba50 Mon Sep 17 00:00:00 2001 From: Jan Marsh Date: Thu, 15 Sep 2022 12:59:54 +0200 Subject: [PATCH 3/6] adding missing infop.list for iOS --- ios/Runner/Info.plist | 135 ++++++++++++++++++++++-------------------- 1 file changed, 70 insertions(+), 65 deletions(-) diff --git a/ios/Runner/Info.plist b/ios/Runner/Info.plist index 6c54137..901a21e 100644 --- a/ios/Runner/Info.plist +++ b/ios/Runner/Info.plist @@ -1,68 +1,73 @@ - - CFBundleDevelopmentRegion - $(DEVELOPMENT_LANGUAGE) - CFBundleDisplayName - Counter Workshop - CFBundleExecutable - $(EXECUTABLE_NAME) - CFBundleIdentifier - $(PRODUCT_BUNDLE_IDENTIFIER) - CFBundleInfoDictionaryVersion - 6.0 - CFBundleName - counter_workshop - CFBundlePackageType - APPL - CFBundleShortVersionString - $(FLUTTER_BUILD_NAME) - CFBundleSignature - ???? - CFBundleVersion - $(FLUTTER_BUILD_NUMBER) - LSRequiresIPhoneOS - - UILaunchStoryboardName - LaunchScreen - UIMainStoryboardFile - Main - UISupportedInterfaceOrientations - - UIInterfaceOrientationPortrait - UIInterfaceOrientationLandscapeLeft - UIInterfaceOrientationLandscapeRight - - UISupportedInterfaceOrientations~ipad - - UIInterfaceOrientationPortrait - UIInterfaceOrientationPortraitUpsideDown - UIInterfaceOrientationLandscapeLeft - UIInterfaceOrientationLandscapeRight - - UIViewControllerBasedStatusBarAppearance - - CADisableMinimumFrameDurationOnPhone - - UIApplicationSupportsIndirectInputEvents - - - FlutterDeepLinkingEnabled - - CFBundleURLTypes - - - CFBundleTypeRole - Editor - CFBundleURLName - counter.de - CFBundleURLSchemes - - de.coodoo.counter - counter - - - - - + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleDisplayName + Counter Workshop + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + counter_workshop + CFBundlePackageType + APPL + CFBundleShortVersionString + $(FLUTTER_BUILD_NAME) + CFBundleSignature + ???? + CFBundleVersion + $(FLUTTER_BUILD_NUMBER) + LSRequiresIPhoneOS + + UILaunchStoryboardName + LaunchScreen + UIMainStoryboardFile + Main + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UIViewControllerBasedStatusBarAppearance + + CADisableMinimumFrameDurationOnPhone + + UIApplicationSupportsIndirectInputEvents + + + FlutterDeepLinkingEnabled + + CFBundleURLTypes + + + CFBundleTypeRole + Editor + CFBundleURLName + counter.de + CFBundleURLSchemes + + de.coodoo.counter + counter + + CFBundleLocalizations + + en + de + + + + + \ No newline at end of file From d8f7b63a5e6d0f07482e36f74635e1484a8163d6 Mon Sep 17 00:00:00 2001 From: Jan Marsh Date: Thu, 15 Sep 2022 13:04:41 +0200 Subject: [PATCH 4/6] adding missing supportedLocales --- lib/src/app.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/src/app.dart b/lib/src/app.dart index e0923fd..26cba2f 100644 --- a/lib/src/app.dart +++ b/lib/src/app.dart @@ -61,6 +61,7 @@ class AppView extends StatelessWidget { GlobalWidgetsLocalizations.delegate, GlobalCupertinoLocalizations.delegate, ], + supportedLocales: AppLocalizations.supportedLocales, ); } } From be106e27284800c60a2f17d08175254fe9f29fd7 Mon Sep 17 00:00:00 2001 From: Jan Marsh Date: Thu, 15 Sep 2022 13:24:05 +0200 Subject: [PATCH 5/6] clean up --- lib/src/app.dart | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/lib/src/app.dart b/lib/src/app.dart index 26cba2f..c516011 100644 --- a/lib/src/app.dart +++ b/lib/src/app.dart @@ -55,12 +55,7 @@ class AppView extends StatelessWidget { routeInformationProvider: router.routeInformationProvider, routeInformationParser: router.routeInformationParser, routerDelegate: router.routerDelegate, - localizationsDelegates: const [ - AppLocalizations.delegate, - GlobalMaterialLocalizations.delegate, - GlobalWidgetsLocalizations.delegate, - GlobalCupertinoLocalizations.delegate, - ], + localizationsDelegates: AppLocalizations.localizationsDelegates, supportedLocales: AppLocalizations.supportedLocales, ); } From 973e2810e55f0ccbebb83dab002941859a182505 Mon Sep 17 00:00:00 2001 From: Jan Marsh Date: Thu, 15 Sep 2022 14:58:32 +0200 Subject: [PATCH 6/6] fixing import --- lib/src/app.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/src/app.dart b/lib/src/app.dart index c516011..c76d605 100644 --- a/lib/src/app.dart +++ b/lib/src/app.dart @@ -5,7 +5,6 @@ import 'package:counter_workshop/src/features/counter/presentation/dashboard/blo import 'package:counter_workshop/src/features/counter/presentation/dashboard/bloc/dashboard.event.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:flutter_localizations/flutter_localizations.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; class App extends StatefulWidget {