From efec0500f33205e7c7eaecd5590a688047c6de4a Mon Sep 17 00:00:00 2001 From: Vishesh Handa Date: Tue, 5 May 2020 17:16:07 +0200 Subject: [PATCH] Add basic scaffolding for translations I still need to go through all the public string and document them. --- assets/langs/en.yaml | 1 + lib/app.dart | 18 +++++++++++++++++- lib/screens/settings_screen.dart | 6 ++++-- pubspec.lock | 30 ++++++++++++++++++++++++++++-- pubspec.yaml | 5 +++++ 5 files changed, 55 insertions(+), 5 deletions(-) create mode 100644 assets/langs/en.yaml diff --git a/assets/langs/en.yaml b/assets/langs/en.yaml new file mode 100644 index 00000000..f68825af --- /dev/null +++ b/assets/langs/en.yaml @@ -0,0 +1 @@ +email: Email diff --git a/lib/app.dart b/lib/app.dart index 91441001..6307429a 100644 --- a/lib/app.dart +++ b/lib/app.dart @@ -11,6 +11,9 @@ import 'package:provider/provider.dart'; import 'package:path/path.dart' as p; import 'package:flutter_runtime_env/flutter_runtime_env.dart' as runtime_env; +import 'package:easy_localization/easy_localization.dart'; +import 'package:easy_localization_loader/easy_localization_loader.dart'; + import 'package:git_bindings/git_bindings.dart'; import 'package:gitjournal/apis/git.dart'; @@ -59,7 +62,7 @@ class JournalApp extends StatelessWidget { appState.save(pref); } - runApp(ChangeNotifierProvider( + var app = ChangeNotifierProvider( create: (_) { return StateContainer(appState); }, @@ -70,6 +73,14 @@ class JournalApp extends StatelessWidget { return appState.notesFolder; }, ), + ); + + runApp(EasyLocalization( + child: app, + supportedLocales: [const Locale('en', 'US')], + path: 'assets/langs', + useOnlyLangCode: true, + assetLoader: YamlAssetLoader(), )); } @@ -135,6 +146,11 @@ class JournalApp extends StatelessWidget { return MaterialApp( key: const ValueKey("App"), title: 'GitJournal', + + localizationsDelegates: EasyLocalization.of(context).delegates, + supportedLocales: EasyLocalization.of(context).supportedLocales, + locale: EasyLocalization.of(context).locale, + theme: themeData, navigatorObservers: [JournalApp.observer], initialRoute: initialRoute, diff --git a/lib/screens/settings_screen.dart b/lib/screens/settings_screen.dart index c82e3a4d..e66c5045 100644 --- a/lib/screens/settings_screen.dart +++ b/lib/screens/settings_screen.dart @@ -1,4 +1,6 @@ import 'package:flutter/material.dart'; +import 'package:easy_localization/easy_localization.dart'; + import 'package:gitjournal/core/notes_folder_fs.dart'; import 'package:gitjournal/screens/settings_editors.dart'; import 'package:gitjournal/settings.dart'; @@ -91,10 +93,10 @@ class SettingsListState extends State { key: gitAuthorEmailKey, style: Theme.of(context).textTheme.title, keyboardType: TextInputType.emailAddress, - decoration: const InputDecoration( + decoration: InputDecoration( icon: Icon(Icons.email), hintText: 'Who should author the changes?', - labelText: 'Email', + labelText: tr('email'), ), validator: (String value) { value = value.trim(); diff --git a/pubspec.lock b/pubspec.lock index eb61987f..99cfc91e 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -141,6 +141,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.16.1" + csv: + dependency: transitive + description: + name: csv + url: "https://pub.dartlang.org" + source: hosted + version: "4.0.3" dart_git: dependency: "direct main" description: @@ -171,6 +178,20 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.0.1" + easy_localization: + dependency: "direct main" + description: + name: easy_localization + url: "https://pub.dartlang.org" + source: hosted + version: "2.2.1" + easy_localization_loader: + dependency: "direct main" + description: + name: easy_localization_loader + url: "https://pub.dartlang.org" + source: hosted + version: "0.0.2" equatable: dependency: "direct main" description: @@ -251,6 +272,11 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.7.4" + flutter_localizations: + dependency: "direct main" + description: flutter + source: sdk + version: "0.0.0" flutter_markdown: dependency: "direct main" description: @@ -687,7 +713,7 @@ packages: name: shared_preferences url: "https://pub.dartlang.org" source: hosted - version: "0.5.6" + version: "0.5.7" shared_preferences_macos: dependency: transitive description: @@ -977,4 +1003,4 @@ packages: version: "0.0.5" sdks: dart: ">=2.7.0 <3.0.0" - flutter: ">=1.12.13+hotfix.4 <2.0.0" + flutter: ">=1.12.13+hotfix.5 <2.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index 51562015..72097892 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -5,6 +5,8 @@ version: 1.50.0+10 dependencies: flutter: sdk: flutter + flutter_localizations: + sdk: flutter intl: "^0.16.0" path: ^1.6.2 uuid: ^2.0.1 @@ -52,6 +54,8 @@ dependencies: flutter_webview_plugin: git: https://github.com/breez/flutter_webview_plugin.git image_picker: ^0.6.6+1 + easy_localization: ^2.2.1 + easy_localization_loader: ^0.0.2 dev_dependencies: flutter_launcher_icons: "^0.7.2" @@ -71,6 +75,7 @@ flutter: - "assets/icon/gitlab-icon.png" - "assets/OnBoardingMarkdown.png" - "assets/OnBoardingGitProviders.png" + - "assets/langs/en.yaml" fonts: - family: Lato fonts: