From 6aa6933f2938b7d8f80d68ea250c910ef81e4a9a Mon Sep 17 00:00:00 2001 From: Guillaume LE MARTRET Date: Fri, 2 Feb 2024 22:20:52 +0100 Subject: [PATCH] feat: add i18nHook --- lib/src/localization/i18n_hook.dart | 14 ++++++++++++++ pubspec.yaml | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 lib/src/localization/i18n_hook.dart diff --git a/lib/src/localization/i18n_hook.dart b/lib/src/localization/i18n_hook.dart new file mode 100644 index 0000000..266710d --- /dev/null +++ b/lib/src/localization/i18n_hook.dart @@ -0,0 +1,14 @@ +import 'package:flutter/widgets.dart'; +import 'package:flutter_hooks/flutter_hooks.dart'; +import 'package:i18n_extension/i18n_widget.dart'; + +void useI18n() { + final context = useContext(); + final deviceLocale = + Localizations.maybeLocaleOf(context) ?? const Locale('en'); + + Future(() { + I18n.of(context).locale = deviceLocale; + }); + return; +} diff --git a/pubspec.yaml b/pubspec.yaml index ec4de56..3935034 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -4,7 +4,7 @@ description: "A new Flutter project." # Prevent accidental publishing to pub.dev. publish_to: 'none' -version: 1.0.0+5 +version: 1.0.0+6 environment: sdk: '>=3.2.0 <4.0.0'