From 143f553dc0fab1d59e6b682bf110aeaddac299ce Mon Sep 17 00:00:00 2001 From: Vri <109021367+vrifox@users.noreply.github.com> Date: Sat, 13 Aug 2022 12:59:53 +0200 Subject: [PATCH] add localization and translation to German (#6) * add localization dependency * add localization import * update MaterialApp w/ localization * add dependency 'intl' * enable generate flag Enabled the generate flag for localization. * add localization config * add initial translation files * l10n: update black background * l10n: convert strings Added more strings to localization. * l10n: translated german Translated all (so far) missing strings into german. --- l10n.yaml | 3 +++ lib/l10n/app_de.arb | 12 ++++++++++++ lib/l10n/app_en.arb | 12 ++++++++++++ lib/main.dart | 32 ++++++++++++++++++++++---------- pubspec.yaml | 6 ++++++ 5 files changed, 55 insertions(+), 10 deletions(-) create mode 100644 l10n.yaml create mode 100644 lib/l10n/app_de.arb create mode 100644 lib/l10n/app_en.arb diff --git a/l10n.yaml b/l10n.yaml new file mode 100644 index 0000000..4e6692e --- /dev/null +++ b/l10n.yaml @@ -0,0 +1,3 @@ +arb-dir: lib/l10n +template-arb-file: app_en.arb +output-localization-file: app_localizations.dart \ No newline at end of file diff --git a/lib/l10n/app_de.arb b/lib/l10n/app_de.arb new file mode 100644 index 0000000..fb41b20 --- /dev/null +++ b/lib/l10n/app_de.arb @@ -0,0 +1,12 @@ +{ + "settings": "Einstellungen", + "theme": "Theme", + "themeSystem": "System", + "themeLight": "Hell", + "themeDark": "Dunkel", + "darkThemeBlackBackground": "Schwarzer Hintergrund im dunklen Theme", + "darkThemeBlackBackgroundSubtitle": "Hauptsächlich für OLED-Bildschirme gedacht", + "restart": "Neustart", + "restartSubtitle": "Gedrückt halten um Fortschritt zurückzusetzen", + "moreInfo": "Mehr Informationen unter " +} diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb new file mode 100644 index 0000000..f7cf253 --- /dev/null +++ b/lib/l10n/app_en.arb @@ -0,0 +1,12 @@ +{ + "settings": "Settings", + "theme": "Theme", + "themeSystem": "system", + "themeLight": "light", + "themeDark": "dark", + "darkThemeBlackBackground": "Black background in dark theme", + "darkThemeBlackBackgroundSubtitle": "Mainly intended for OLED screens", + "restart": "Restart", + "restartSubtitle": "Long press to reset the progress", + "moreInfo": "More information at " +} diff --git a/lib/main.dart b/lib/main.dart index 9eaac01..db10a3f 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -4,6 +4,8 @@ import 'dart:math'; import 'package:flutter/material.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/services.dart'; +import 'package:flutter_localizations/flutter_localizations.dart'; +import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:provider/provider.dart'; import 'package:path/path.dart'; import 'package:sqflite/sqflite.dart'; @@ -374,9 +376,9 @@ class SettingsScreen extends StatelessWidget { return ListView( padding: listPadding, children: [ - const ListTile( - leading: Icon(Icons.settings_brightness), - title: Text('Theme'), + ListTile( + leading: const Icon(Icons.settings_brightness), + title: Text(AppLocalizations.of(context)!.theme), ), Consumer2(builder: (context, world, game, child) => Column( @@ -393,8 +395,8 @@ class SettingsScreen extends StatelessWidget { ), )), SwitchListTile( - title: const Text("Use pure black background in dark theme"), - subtitle: const Text("Mainly intended for OLED screens"), + title: Text(AppLocalizations.of(context)!.darkThemeBlackBackground), + subtitle: Text(AppLocalizations.of(context)!.darkThemeBlackBackgroundSubtitle), value: world.pureBlack, onChanged: (bool value) async { world.switchTheme(pureBlack: value); @@ -408,8 +410,8 @@ class SettingsScreen extends StatelessWidget { Consumer2(builder: (context, world, game, child) => ListTile( leading: const Icon(Icons.restore), - title: const Text('Restart'), - subtitle: const Text('Long press to reset the progress.'), + title: Text(AppLocalizations.of(context)!.restart), + subtitle: Text(AppLocalizations.of(context)!.restartSubtitle), onLongPress: () async { await game.resetProgress(); world.resetWorld(); @@ -424,7 +426,7 @@ class SettingsScreen extends StatelessWidget { SelectableText.rich( TextSpan( children: [ - TextSpan(style: textStyle, text: 'More info at '), + TextSpan(style: textStyle, text: AppLocalizations.of(context)!.moreInfo), TextSpan( style: textStyle.copyWith(color: theme.colorScheme.primary), text: 'https://mwageringel.github.io/everest/'), // TODO make hyperlink clickable or copy to clipboard @@ -509,7 +511,7 @@ class ExamsScreen extends StatelessWidget { builder: (context) { return Scaffold( appBar: AppBar( - title: const Text('Settings'), + title: Text(AppLocalizations.of(context)!.settings), ), body: const SettingsScreen(), ); @@ -526,7 +528,7 @@ class ExamsScreen extends StatelessWidget { IconButton( icon: const Icon(Icons.menu), onPressed: () => _pushSettings(context), - tooltip: 'Settings', + tooltip: AppLocalizations.of(context)!.settings, ), ], child: ListView.builder( @@ -656,6 +658,16 @@ class MyApp extends StatelessWidget { visualDensity: FlexColorScheme.comfortablePlatformDensity, darkIsTrueBlack: world.pureBlack, ), + localizationsDelegates: const [ + AppLocalizations.delegate, + GlobalMaterialLocalizations.delegate, + GlobalWidgetsLocalizations.delegate, + GlobalCupertinoLocalizations.delegate, + ], + supportedLocales: const [ + Locale('en', ''), // English, no country code + Locale('de', ''), // German, no country code + ], home: const ExamsScreen(), ), ); diff --git a/pubspec.yaml b/pubspec.yaml index 1ac417f..7103901 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -29,6 +29,9 @@ environment: dependencies: flutter: sdk: flutter + flutter_localizations: + sdk: flutter + intl: ^0.17.0 sqflite: path: @@ -59,6 +62,9 @@ dev_dependencies: # The following section is specific to Flutter. flutter: + # Enabled for flutter_localizations, for more information see https://docs.flutter.dev/development/accessibility-and-localization/internationalization + generate: true + # The following line ensures that the Material Icons font is # included with your application, so that you can use the icons in # the material Icons class.