From 829cb0ea9945404f0dd57a34a3df25190be77239 Mon Sep 17 00:00:00 2001 From: Hjort Date: Thu, 30 Nov 2023 18:15:52 +0100 Subject: [PATCH] Setup Internationalization --- l10n.yaml | 4 ++++ lib/l10n/app_en.arb | 10 ++++++++++ lib/main.dart | 20 ++++++++++++-------- lib/screens/terms_and_conditions/screen.dart | 20 ++++++++++---------- pubspec.lock | 13 +++++++++++++ pubspec.yaml | 4 ++++ 6 files changed, 53 insertions(+), 18 deletions(-) create mode 100644 l10n.yaml create mode 100644 lib/l10n/app_en.arb diff --git a/l10n.yaml b/l10n.yaml new file mode 100644 index 0000000..c114495 --- /dev/null +++ b/l10n.yaml @@ -0,0 +1,4 @@ +arb-dir: lib/l10n +template-arb-file: app_en.arb +output-localization-file: app_localizations.dart +nullable-getter: false \ No newline at end of file diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb new file mode 100644 index 0000000..ac40a87 --- /dev/null +++ b/lib/l10n/app_en.arb @@ -0,0 +1,10 @@ +{ + "initializing": "Initializing...", + "cont": "Continue", + "before_you_begin": "Before you begin", + "intro_text0": "Before you start using the Concordium Mobile Wallet, you have to set up a passcode and optionally biometrics.", + "intro_text1": "It is very important that you keep your passcode safe, because it is the only way to access your accounts. Concordium is not able to change your passcode or help you unlock your wallet if you lose your passcode.", + "read_and_agree": "I have read and agree to the ", + "terms_and_conditions": "Terms and Conditions v{v}", + "previously_accepted": " (you previously accepted v{v})." +} diff --git a/lib/main.dart b/lib/main.dart index 239c8d3..e6bf1bd 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -11,6 +11,7 @@ import 'package:concordium_wallet/theme.dart'; import 'package:concordium_wallet/types/future_value.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:flutter_gen/gen_l10n/app_localizations.dart'; void main() { runApp(const App()); @@ -55,10 +56,13 @@ class App extends StatelessWidget { child: _WithSelectedNetwork( initialNetwork: initialNetwork, child: _WithTermsAndConditionAcceptance( - child: MaterialApp( - routes: appRoutes, - theme: concordiumTheme(), - )), + child: MaterialApp( + localizationsDelegates: AppLocalizations.localizationsDelegates, + supportedLocales: AppLocalizations.supportedLocales, + routes: appRoutes, + theme: concordiumTheme(), + ), + ), ), ); } @@ -196,14 +200,14 @@ class _Initializing extends StatelessWidget { @override Widget build(BuildContext context) { - return const Column( + return Column( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center, children: [ - CircularProgressIndicator(), - SizedBox(height: 16), + const CircularProgressIndicator(), + const SizedBox(height: 16), // Setting text direction is required because we're outside 'MaterialApp' widget. - Text('Initializing...', textDirection: TextDirection.ltr), + Text(AppLocalizations.of(context).initializing, textDirection: TextDirection.ltr), ], ); } diff --git a/lib/screens/terms_and_conditions/screen.dart b/lib/screens/terms_and_conditions/screen.dart index 302b342..3325a0d 100644 --- a/lib/screens/terms_and_conditions/screen.dart +++ b/lib/screens/terms_and_conditions/screen.dart @@ -5,6 +5,7 @@ import 'package:concordium_wallet/state/terms_and_conditions.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_svg/flutter_svg.dart'; +import 'package:flutter_gen/gen_l10n/app_localizations.dart'; class TermsAndConditionsScreen extends StatefulWidget { final TermsAndConditions validTermsAndConditions; @@ -53,18 +54,17 @@ class _TermsAndConditionsScreenState extends State { const SizedBox(height: 24), Center( child: Text( - 'Before you begin', + AppLocalizations.of(context).before_you_begin, style: Theme.of(context).textTheme.displaySmall, ), ), Container( padding: const EdgeInsets.all(16), - child: const Column( + child: Column( children: [ - Text('Before you start using the Concordium Mobile Wallet, you have to set up a passcode and optionally biometrics.'), - SizedBox(height: 9), - Text( - 'It is very important that you keep your passcode safe, because it is the only way to access your accounts. Concordium is not able to change your passcode or help you unlock your wallet if you lose your passcode.'), + Text(AppLocalizations.of(context).intro_text0), + const SizedBox(height: 9), + Text(AppLocalizations.of(context).intro_text1), ], ), ), @@ -84,9 +84,9 @@ class _TermsAndConditionsScreenState extends State { text: TextSpan( style: Theme.of(context).textTheme.bodySmall, children: [ - const TextSpan(text: 'I have read and agree to the '), + TextSpan(text: AppLocalizations.of(context).read_and_agree), TextSpan( - text: 'Terms and Conditions v${widget.validTermsAndConditions.version}', + text: AppLocalizations.of(context).terms_and_conditions(widget.validTermsAndConditions.version), style: const TextStyle( color: Colors.indigo, fontWeight: FontWeight.bold, @@ -95,7 +95,7 @@ class _TermsAndConditionsScreenState extends State { switch (widget.acceptedTermsAndConditionsVersion) { null => const TextSpan(text: '.'), String v => TextSpan( - text: ' (you previously accepted v$v).', + text: AppLocalizations.of(context).previously_accepted(v), style: Theme.of(context).textTheme.bodySmall, ), }, @@ -113,7 +113,7 @@ class _TermsAndConditionsScreenState extends State { const SizedBox(height: 9), ElevatedButton( onPressed: _onAcceptButtonPressed(context), - child: const Text('Continue'), + child: Text(AppLocalizations.of(context).cont), ), ], ), diff --git a/pubspec.lock b/pubspec.lock index e4eae57..62993ea 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -294,6 +294,11 @@ packages: url: "https://pub.dev" source: hosted version: "2.0.3" + flutter_localizations: + dependency: "direct main" + description: flutter + source: sdk + version: "0.0.0" flutter_svg: dependency: "direct main" description: @@ -392,6 +397,14 @@ packages: url: "https://pub.dev" source: hosted version: "4.0.2" + intl: + dependency: "direct main" + description: + name: intl + sha256: "3bc132a9dbce73a7e4a21a17d06e1878839ffbf975568bc875c60537824b0c4d" + url: "https://pub.dev" + source: hosted + version: "0.18.1" io: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 1edc948..121d726 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -44,6 +44,9 @@ dependencies: package_info_plus: ^4.2.0 hive: ^2.2.3 hive_flutter: ^1.1.0 + flutter_localizations: + sdk: flutter + intl: ^0.18.1 dev_dependencies: flutter_test: @@ -66,6 +69,7 @@ dev_dependencies: # The following section is specific to Flutter packages. flutter: + generate: true # The following line ensures that the Material Icons font is # included with your application, so that you can use the icons in