Skip to content

Commit

Permalink
904: Use built in flutter localization
Browse files Browse the repository at this point in the history
  • Loading branch information
steffenkleinle committed Oct 16, 2023
1 parent 27ef680 commit 2353756
Show file tree
Hide file tree
Showing 43 changed files with 414 additions and 308 deletions.
130 changes: 0 additions & 130 deletions frontend/assets/bayern/translations/de.json

This file was deleted.

3 changes: 3 additions & 0 deletions frontend/l10n.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
arb-dir: lib/l10n
template-arb-file: app_en.arb
output-localization-file: app_localizations.dart
27 changes: 13 additions & 14 deletions frontend/lib/about/about_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import 'package:ehrenamtskarte/build_config/build_config.dart' show buildConfig;
import 'package:ehrenamtskarte/configuration/configuration.dart';
import 'package:ehrenamtskarte/routing.dart';
import 'package:flutter/material.dart';
import 'package:flutter_i18n/flutter_i18n.dart';
import 'package:package_info_plus/package_info_plus.dart';
import 'package:url_launcher/url_launcher_string.dart';

import '../util/i18n.dart';

class AboutPage extends StatefulWidget {
final countToEnableSwitch = 10;

const AboutPage({super.key});

@override
Expand Down Expand Up @@ -70,29 +70,28 @@ class AboutPageState extends State<AboutPage> {
child: Column(
children: [
Center(
child: I18nText('publisher', child: Text('', style: Theme.of(context).textTheme.titleSmall)),
child: Text(t(context).about_publisher, style: Theme.of(context).textTheme.titleSmall),
),
Padding(
padding: const EdgeInsets.only(left: 10, right: 10, top: 16, bottom: 16),
child: Text(buildConfig.publisherAddress, style: Theme.of(context).textTheme.bodyLarge),
),
I18nText(
'moreInformation',
child: Text('',
Text(
t(context).about_moreInformation,
style: Theme.of(context)
.textTheme
.bodyMedium
?.merge(TextStyle(color: Theme.of(context).colorScheme.secondary)),
),
),
],
),
),
onTap: () {
Navigator.push(
context,
AppRoute(
builder: (context) => ContentPage(title: t(context, 'publisher'), children: getPublisherText(context)),
builder: (context) =>
ContentPage(title: t(context).about_publisher, children: getPublisherText(context)),
),
);
},
Expand All @@ -102,20 +101,20 @@ class AboutPageState extends State<AboutPage> {
thickness: 1,
),
const SizedBox(height: 20),
ContentTile(icon: Icons.copyright, title: t(context, 'license'), children: getCopyrightText(context)),
ContentTile(icon: Icons.copyright, title: t(context).about_license, children: getCopyrightText(context)),
ListTile(
leading: const Icon(Icons.privacy_tip_outlined),
title: I18nText('privacyDeclaration'),
title: Text(t(context).about_privacyDeclaration),
onTap: () => launchUrlString(buildConfig.dataPrivacyPolicyUrl, mode: LaunchMode.externalApplication),
),
ContentTile(
icon: Icons.info_outline,
title: t(context, 'disclaimer'),
title: t(context).about_disclaimer,
children: getDisclaimerText(context),
),
ListTile(
leading: const Icon(Icons.book_outlined),
title: I18nText('dependencies'),
title: Text(t(context).about_dependencies),
onTap: () {
Navigator.push(
context,
Expand All @@ -127,7 +126,7 @@ class AboutPageState extends State<AboutPage> {
),
ListTile(
leading: const Icon(Icons.code_outlined),
title: I18nText('sourceCode'),
title: Text(t(context).about_sourceCode),
onTap: () {
launchUrlString(
'https://github.com/digitalfabrik/entitlementcard',
Expand All @@ -138,11 +137,11 @@ class AboutPageState extends State<AboutPage> {
if (config.showDevSettings)
ListTile(
leading: const Icon(Icons.build),
title: I18nText('developmentOptions'),
title: Text(t(context).about_developmentOptions),
onTap: () => showDialog(
context: context,
builder: (context) =>
SimpleDialog(title: I18nText('developmentOptions'), children: [DevSettingsView()]),
SimpleDialog(title: Text(t(context).about_developmentOptions), children: [DevSettingsView()]),
),
)
];
Expand Down
5 changes: 2 additions & 3 deletions frontend/lib/about/license_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import 'package:ehrenamtskarte/widgets/error_message.dart';
import 'package:ehrenamtskarte/widgets/top_loading_spinner.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_i18n/flutter_i18n.dart';

import '../util/i18n.dart';

Expand Down Expand Up @@ -54,15 +53,15 @@ class CustomLicensePage extends StatelessWidget {

return CustomScrollView(
slivers: <Widget>[
CustomSliverAppBar(title: t(context, 'licenses')),
CustomSliverAppBar(title: t(context).about_licenses),
SliverList(
delegate: SliverChildBuilderDelegate(
(BuildContext context, int index) {
final license = result[index];
final paragraphs = license.licenseParagraphs;
return ListTile(
title: Text(license.packageName),
subtitle: I18nPlural('numberLicenses', paragraphs.length),
subtitle: Text(t(context).about_numberLicenses(paragraphs.length)),
onTap: () {
Navigator.push(
context,
Expand Down
8 changes: 2 additions & 6 deletions frontend/lib/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import 'package:ehrenamtskarte/intro_slides/intro_screen.dart';
import 'package:ehrenamtskarte/themes.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_i18n/flutter_i18n.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:provider/provider.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';

import 'home/home_page.dart';

Expand Down Expand Up @@ -68,11 +68,7 @@ class App extends StatelessWidget {
themeMode: ThemeMode.system,
debugShowCheckedModeBanner: false,
localizationsDelegates: [
FlutterI18nDelegate(
translationLoader: FileTranslationLoader(useCountryCode: false, fallbackFile: 'de', basePath: 'assets/bayern/translations'),
missingTranslationHandler: (key, locale) =>
print('--- Missing Key: $key, languageCode: ${locale?.languageCode}'),
),
AppLocalizations.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
Expand Down
9 changes: 5 additions & 4 deletions frontend/lib/home/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,24 @@ class HomePageState extends State<HomePage> {
selectAcceptingStore: (id) => setState(() => selectedAcceptingStoreId = id),
),
Icons.map_outlined,
t(context, 'card'),
t(context).map_title,
GlobalKey<NavigatorState>(debugLabel: 'Map tab key'),
),
AppFlow(
const SearchPage(),
Icons.search_outlined,
t(context, 'search'),
t(context).search_title,
GlobalKey<NavigatorState>(debugLabel: 'Search tab key'),
),
if (buildConfig.featureFlags.verification)
AppFlow(
IdentificationPage(),
Icons.remove_red_eye_outlined,
t(context, 'authentication'),
t(context).identification_title,
GlobalKey<NavigatorState>(debugLabel: 'Auth tab key'),
),
AppFlow(const AboutPage(), Icons.info_outline, t(context, 'about'), GlobalKey<NavigatorState>(debugLabel: 'About tab key')),
AppFlow(const AboutPage(), Icons.info_outline, t(context).about_title,
GlobalKey<NavigatorState>(debugLabel: 'About tab key')),
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,25 +53,19 @@ class ActivationCodeScannerPage extends StatelessWidget {

await _activateCode(context, activationCode);
} on ActivationDidNotOverwriteExisting catch (_) {
await showError(t(context, 'cardAlreadyActivated'), null);
await showError(t(context).identification_cardAlreadyActivated, null);
} on QrCodeFieldMissingException catch (e) {
await showError(t(context, 'codeInvalidMissing', translationParams: { 'missing': e.missingFieldName }));
await showError(t(context).identification_codeInvalidMissing(e.missingFieldName), null);
} on QrCodeWrongTypeException catch (_) {
await showError(t(context, 'codeSavingFailed'));
await showError(t(context).identification_codeSavingFailed, null);
} on CardExpiredException catch (e) {
final expirationDate = DateFormat('dd.MM.yyyy').format(e.expiry);
await showError(t(context, 'codeExpired', translationParams: { 'expirationDate': expirationDate }));
} on ServerCardActivationException catch (e, stackTrace) {
String errorMessage = 'Der eingescannte Code konnte nicht aktiviert '
'werden, da die Kommunikation mit dem Server fehlschlug. '
'Bitte prüfen Sie Ihre Internetverbindung.';
await ConnectionFailedDialog.show(
context,
t(context, 'codeVerificationFailedConnection')
);
await showError(t(context).identification_codeExpired(expirationDate), null);
} on ServerCardActivationException catch (_) {
await ConnectionFailedDialog.show(context, t(context).identification_codeVerificationFailedConnection);
} on Exception catch (e, stacktrace) {
debugPrintStack(stackTrace: stacktrace, label: e.toString());
await showError(t(context, 'codeUnknownError'));
await showError(t(context).identification_codeUnknownError, null);
}
}

Expand Down Expand Up @@ -116,7 +110,7 @@ class ActivationCodeScannerPage extends StatelessWidget {
case ActivationState.failed:
await QrParsingErrorDialog.showErrorDialog(
context,
t(context, 'codeInvalid'),
t(context).identification_codeInvalid,
);
break;
case ActivationState.didNotOverwriteExisting:
Expand All @@ -130,7 +124,7 @@ class ActivationCodeScannerPage extends StatelessWidget {
}
break;
default:
throw ServerCardActivationException(t(context, 'activationInvalidState'));
throw ServerCardActivationException(t(context).identification_activationInvalidState);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:flutter/material.dart';
import 'package:flutter_i18n/flutter_i18n.dart';

import '../../util/i18n.dart';

Expand All @@ -9,23 +8,23 @@ class ActivationOverwriteExistingDialog extends StatelessWidget {
@override
Widget build(BuildContext context) {
return AlertDialog(
title: Text(t(context, 'activateCardCurrentDevice'), style: TextStyle(fontSize: 18)),
title: Text(t(context).identification_activateCardCurrentDevice, style: TextStyle(fontSize: 18)),
content: SingleChildScrollView(
child: ListBody(
children: <Widget>[
I18nText('activateCardCurrentDeviceRationale'),
Text(t(context).identification_activateCardCurrentDeviceRationale),
],
),
),
actions: <Widget>[
TextButton(
child: I18nText('cancel'),
child: Text(t(context).common_cancel),
onPressed: () {
Navigator.of(context).pop(false);
},
),
TextButton(
child: I18nText('activate'),
child: Text(t(context).identification_activate),
onPressed: () {
Navigator.of(context).pop(true);
},
Expand Down
Loading

0 comments on commit 2353756

Please sign in to comment.