Skip to content

Commit

Permalink
add savedLocale get method for context (#675)
Browse files Browse the repository at this point in the history
  • Loading branch information
bbsmartc authored May 4, 2024
1 parent 0150d7e commit 4518a9c
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- add 'useFallbackTranslationsForEmptyResources' to be able to use fallback locales for empty resources.
- add _supportedLocales in EasyLocalizationController; log and check the deviceLocale when resetLocale;
- add scriptCode to desiredLocale if useOnlyLangCode is true. scriptCode is needed sometimes, for example zh-Hans, zh-Hant
- add savedLocale get method for context. if context.savedLocale is null, then language option is `following system`, i can display the option in user selection form.

### [3.0.5]

Expand Down
1 change: 1 addition & 0 deletions lib/src/easy_localization_app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ class _EasyLocalizationProvider extends InheritedWidget {
/// Getting device locale from platform
Locale get deviceLocale => _localeState.deviceLocale;
Locale? get savedLocale => _localeState.savedLocale;
/// Reset locale to platform locale
Future<void> resetLocale() => _localeState.resetLocale();
Expand Down
1 change: 1 addition & 0 deletions lib/src/easy_localization_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ class EasyLocalizationController extends ChangeNotifier {
}

Locale get deviceLocale => _deviceLocale;
Locale? get savedLocale => _savedLocale;

Future<void> resetLocale() async {
final locale = selectLocaleFrom(_supportedLocales!, deviceLocale, fallbackLocale: _fallbackLocale);
Expand Down
1 change: 1 addition & 0 deletions lib/src/public_ext.dart
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ extension BuildContextEasyLocalizationExtension on BuildContext {

/// Getting device locale from platform
Locale get deviceLocale => EasyLocalization.of(this)!.deviceLocale;
Locale? get savedLocale => EasyLocalization.of(this)!.savedLocale;

/// Reset locale to platform locale
Future<void> resetLocale() => EasyLocalization.of(this)!.resetLocale();
Expand Down

0 comments on commit 4518a9c

Please sign in to comment.