diff --git a/assets/translations/en.json b/assets/translations/en.json new file mode 100644 index 0000000..15afb25 --- /dev/null +++ b/assets/translations/en.json @@ -0,0 +1,3 @@ +{ + "msg": "hello {} there !" +} \ No newline at end of file diff --git a/assets/translations/fr.json b/assets/translations/fr.json new file mode 100644 index 0000000..475a3fa --- /dev/null +++ b/assets/translations/fr.json @@ -0,0 +1,3 @@ +{ + "msg": "Salut ici !" +} \ No newline at end of file diff --git a/lib/main.dart b/lib/main.dart index 01d339c..b484616 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -45,11 +45,14 @@ import 'package:shared_preferences/shared_preferences.dart'; import 'package:sentry_flutter/sentry_flutter.dart'; import 'package:window_size/window_size.dart'; import 'package:graphql_flutter/graphql_flutter.dart'; +import 'package:flutter_localizations/flutter_localizations.dart'; +import 'package:easy_localization/easy_localization.dart'; const bool enableSentry = true; Future main() async { WidgetsFlutterBinding.ensureInitialized(); + await EasyLocalization.ensureInitialized(); if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) { setWindowTitle('Ğecko'); setWindowMinSize(const Size(400, 700)); @@ -97,10 +100,21 @@ Future main() async { // // ]); // Catcher(rootWidget: Gecko(endPointGVA, _store), debugConfig: debugOptions); - await SentryFlutter.init((options) { - options.dsn = - 'https://c09587b46eaa42e8b9fda28d838ed180@o496840.ingest.sentry.io/5572110'; - }, appRunner: () => runApp(Gecko(indexerEndpoint))); + await SentryFlutter.init( + (options) { + options.dsn = + 'https://c09587b46eaa42e8b9fda28d838ed180@o496840.ingest.sentry.io/5572110'; + }, + appRunner: () => runApp( + EasyLocalization( + supportedLocales: const [Locale('en'), Locale('fr')], + path: + 'assets/translations', // <-- change the path of the translation files + fallbackLocale: const Locale('fr'), + child: Gecko(indexerEndpoint), + ), + ), + ); // runZoned>( // () async { @@ -117,7 +131,15 @@ Future main() async { } else { print('Debug mode enabled: No sentry alerte'); - runApp(Gecko(indexerEndpoint)); + runApp( + EasyLocalization( + supportedLocales: const [Locale('en'), Locale('fr')], + path: + 'assets/translations', // <-- change the path of the translation files + fallbackLocale: const Locale('fr'), + child: Gecko(indexerEndpoint), + ), + ); } } @@ -145,6 +167,9 @@ class Gecko extends StatelessWidget { ChangeNotifierProvider(create: (_) => DuniterIndexer()) ], child: MaterialApp( + localizationsDelegates: context.localizationDelegates, + supportedLocales: context.supportedLocales, + locale: context.locale, builder: (context, widget) => ResponsiveWrapper.builder( BouncingScrollWrapper.builder(context, widget!), maxWidth: 1200, diff --git a/lib/screens/home.dart b/lib/screens/home.dart index 899c14a..c9899be 100644 --- a/lib/screens/home.dart +++ b/lib/screens/home.dart @@ -1,5 +1,6 @@ import 'package:bubble/bubble.dart'; import 'package:connectivity_plus/connectivity_plus.dart'; +import 'package:easy_localization/easy_localization.dart'; import 'package:gecko/globals.dart'; import 'package:gecko/models/stateful_wrapper.dart'; import 'package:gecko/providers/chest_provider.dart'; @@ -301,6 +302,7 @@ Widget geckHome(context) { ), ), const SizedBox(height: 12), + const Text('msg').tr(args: [currencyName]), Text( "Rechercher un\nportefeuille", textAlign: TextAlign.center, diff --git a/lib/screens/myWallets/wallet_options.dart b/lib/screens/myWallets/wallet_options.dart index 0f41e31..8e0465e 100644 --- a/lib/screens/myWallets/wallet_options.dart +++ b/lib/screens/myWallets/wallet_options.dart @@ -351,7 +351,7 @@ class WalletOptions extends StatelessWidget { height: 45, ), const SizedBox(width: 22), - const Text('Activité', + const Text("Voir l'activité", style: TextStyle(fontSize: 20, fontWeight: FontWeight.w500)), ]), ), diff --git a/pubspec.lock b/pubspec.lock index 60bf6e8..85ce7e4 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -316,6 +316,20 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.1.6" + easy_localization: + dependency: "direct main" + description: + name: easy_localization + url: "https://pub.dartlang.org" + source: hosted + version: "3.0.1" + easy_logger: + dependency: transitive + description: + name: easy_logger + url: "https://pub.dartlang.org" + source: hosted + version: "0.0.2" fake_async: dependency: transitive description: @@ -389,6 +403,11 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.0.4" + flutter_localizations: + dependency: transitive + description: flutter + source: sdk + version: "0.0.0" flutter_logs: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index 3ca445c..b6077d7 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -72,6 +72,7 @@ dependencies: web_socket_channel: ^2.2.0 connectivity_plus: ^2.3.3 image_cropper: ^2.0.3 + easy_localization: ^3.0.1 dev_dependencies: # flutter_launcher_icons: ^0.9.2 @@ -99,6 +100,7 @@ flutter: assets: - config/ - assets/ + - assets/translations/ - assets/home/ - assets/avatars/ - assets/chests/