Skip to content

Commit

Permalink
add localization and translation to German (mwageringel#6)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
vrifox authored Aug 13, 2022
1 parent 9f026a5 commit 143f553
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 10 deletions.
3 changes: 3 additions & 0 deletions 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
12 changes: 12 additions & 0 deletions lib/l10n/app_de.arb
Original file line number Diff line number Diff line change
@@ -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 "
}
12 changes: 12 additions & 0 deletions lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
@@ -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 "
}
32 changes: 22 additions & 10 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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<World, Game>(builder: (context, world, game, child) =>
Column(
Expand All @@ -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);
Expand All @@ -408,8 +410,8 @@ class SettingsScreen extends StatelessWidget {
Consumer2<World, Game>(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();
Expand All @@ -424,7 +426,7 @@ class SettingsScreen extends StatelessWidget {
SelectableText.rich(
TextSpan(
children: <TextSpan>[
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
Expand Down Expand Up @@ -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(),
);
Expand All @@ -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(
Expand Down Expand Up @@ -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(),
),
);
Expand Down
6 changes: 6 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ environment:
dependencies:
flutter:
sdk: flutter
flutter_localizations:
sdk: flutter
intl: ^0.17.0
sqflite:
path:

Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 143f553

Please sign in to comment.