Skip to content

9. Internationalization #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: go_router
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
135 changes: 70 additions & 65 deletions ios/Runner/Info.plist
Original file line number Diff line number Diff line change
@@ -1,68 +1,73 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleDisplayName</key>
<string>Counter Workshop</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>counter_workshop</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>$(FLUTTER_BUILD_NAME)</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>$(FLUTTER_BUILD_NUMBER)</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
<string>Main</string>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<key>CADisableMinimumFrameDurationOnPhone</key>
<true/>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
<!-- Add this array for Deep Links -->
<key>FlutterDeepLinkingEnabled</key>
<true/>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLName</key>
<string>counter.de</string>
<key>CFBundleURLSchemes</key>
<array>
<string>de.coodoo.counter</string>
<string>counter</string>
</array>
</dict>
</array>
</dict>
</plist>
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleDisplayName</key>
<string>Counter Workshop</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>counter_workshop</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>$(FLUTTER_BUILD_NAME)</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>$(FLUTTER_BUILD_NUMBER)</string>
<key>LSRequiresIPhoneOS</key>
<true />
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
<string>Main</string>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false />
<key>CADisableMinimumFrameDurationOnPhone</key>
<true />
<key>UIApplicationSupportsIndirectInputEvents</key>
<true />
<!-- Add this array for Deep Links -->
<key>FlutterDeepLinkingEnabled</key>
<true />
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLName</key>
<string>counter.de</string>
<key>CFBundleURLSchemes</key>
<array>
<string>de.coodoo.counter</string>
<string>counter</string>
</array>
<key>CFBundleLocalizations</key>
<array>
<string>en</string>
<string>de</string>
</array>
</dict>
</array>
</dict>
</plist>
4 changes: 4 additions & 0 deletions l10n.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
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
5 changes: 4 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> main() async {
Intl.systemLocale = await findSystemLocale();
final CounterRepository counterRepository = CounterRepository(counterApi: CounterFakeApi());
runApp(
App(
Expand Down
3 changes: 3 additions & 0 deletions lib/src/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ 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_gen/gen_l10n/app_localizations.dart';

class App extends StatefulWidget {
const App({required this.counterRepository, super.key});
Expand Down Expand Up @@ -53,6 +54,8 @@ class AppView extends StatelessWidget {
routeInformationProvider: router.routeInformationProvider,
routeInformationParser: router.routeInformationParser,
routerDelegate: router.routerDelegate,
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
);
}
}
6 changes: 6 additions & 0 deletions lib/src/core/extensions/localization.extension.dart
Original file line number Diff line number Diff line change
@@ -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);
}
4 changes: 4 additions & 0 deletions lib/src/core/localization/app_de.arb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"@@locale": "de",
"appTitle": "Zähler"
}
7 changes: 7 additions & 0 deletions lib/src/core/localization/app_en.arb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"@@locale": "en",
"appTitle": "Counter",
"@appTitle": {
"description": "Name of the app"
}
}
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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<DashboardBloc, DashboardState>(
builder: (context, state) {
Expand Down
12 changes: 12 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
9 changes: 6 additions & 3 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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
- assets/launcher_icon/ # App icon image to generate from