-
-
Notifications
You must be signed in to change notification settings - Fork 336
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add easy_localization_storage, easy_localization_shared_preferences_storage and easy_localization_helper #719
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -25,6 +25,8 @@ dependencies: | |||||||||||||
cupertino_icons: ^1.0.2 | ||||||||||||||
easy_localization: | ||||||||||||||
path: ../ | ||||||||||||||
easy_localization_storage: | ||||||||||||||
path: ../packages/easy_localization_storage | ||||||||||||||
Comment on lines
+28
to
+29
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing dependency: easy_localization_helper According to the PR objectives and AI summary, this PR introduces both Add the missing dependency: easy_localization_storage:
path: ../packages/easy_localization_storage
+easy_localization_helper:
+ path: ../packages/easy_localization_helper 📝 Committable suggestion
Suggested change
|
||||||||||||||
font_awesome_flutter: 9.0.0-nullsafety | ||||||||||||||
|
||||||||||||||
#custom loaders | ||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,31 @@ | ||
import 'package:easy_localization/easy_localization.dart'; | ||
import 'package:easy_localization_helper/easy_localization_helper.dart'; | ||
import 'package:easy_localization_storage/easy_localization_storage.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:intl/intl_standalone.dart' | ||
if (dart.library.html) 'package:intl/intl_browser.dart'; | ||
import 'package:shared_preferences/shared_preferences.dart'; | ||
|
||
import 'translations.dart'; | ||
|
||
class EasyLocalizationController extends ChangeNotifier { | ||
static Locale? _savedLocale; | ||
static late Locale _deviceLocale; | ||
static EasyLocalizationStorage? _storage; | ||
static EasyLocalizationStorage get storage { | ||
if (_storage == null) { | ||
throw StateError( | ||
'EasyLocalizationController not initialized. Call initEasyLocation first.'); | ||
Comment on lines
+16
to
+17
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct method name from 'initEasyLocation' to 'initEasyLocalization' The method name Apply this diff to correct the method name and error message: - throw StateError(
- 'EasyLocalizationController not initialized. Call initEasyLocation first.');
+ throw StateError(
+ 'EasyLocalizationController not initialized. Call initEasyLocalization first.'); -static Future<void> initEasyLocation(EasyLocalizationStorage storage) async {
+static Future<void> initEasyLocalization(EasyLocalizationStorage storage) async { Update all references to this method accordingly. Also applies to: 219-221 |
||
} | ||
return _storage!; | ||
} | ||
|
||
static set storage(EasyLocalizationStorage storage) { | ||
_storage = storage; | ||
} | ||
|
||
late Locale _locale; | ||
Locale? _fallbackLocale; | ||
List<Locale>? _supportedLocales; | ||
late List<Locale> _supportedLocales; | ||
|
||
final Function(FlutterError e) onLoadError; | ||
final AssetLoader assetLoader; | ||
|
@@ -161,9 +174,11 @@ class EasyLocalizationController extends ChangeNotifier { | |
final result = <String, dynamic>{}; | ||
final loaderFutures = <Future<Map<String, dynamic>?>>[]; | ||
|
||
// need scriptCode, it might be better to use ignoreCountryCode as the variable name of useOnlyLangCode | ||
final Locale desiredLocale = | ||
useOnlyLangCode ? Locale.fromSubtags(languageCode: locale.languageCode, scriptCode: locale.scriptCode) : locale; | ||
// need scriptCode, it might be better to use ignoreCountryCode as the variable name of useOnlyLangCode | ||
final Locale desiredLocale = useOnlyLangCode | ||
? Locale.fromSubtags( | ||
languageCode: locale.languageCode, scriptCode: locale.scriptCode) | ||
: locale; | ||
|
||
List<AssetLoader> loaders = [ | ||
assetLoader, | ||
|
@@ -197,34 +212,33 @@ class EasyLocalizationController extends ChangeNotifier { | |
|
||
Future<void> _saveLocale(Locale? locale) async { | ||
if (!saveLocale) return; | ||
final preferences = await SharedPreferences.getInstance(); | ||
await preferences.setString('locale', locale.toString()); | ||
await storage.setLocale(value: locale); | ||
EasyLocalization.logger('Locale $locale saved'); | ||
} | ||
|
||
static Future<void> initEasyLocation() async { | ||
final preferences = await SharedPreferences.getInstance(); | ||
final strLocale = preferences.getString('locale'); | ||
_savedLocale = strLocale?.toLocale(); | ||
static Future<void> initEasyLocation(EasyLocalizationStorage storage) async { | ||
EasyLocalizationController.storage = storage; | ||
_savedLocale = await storage.getLocale(); | ||
final foundPlatformLocale = await findSystemLocale(); | ||
_deviceLocale = foundPlatformLocale.toLocale(); | ||
EasyLocalization.logger.debug('Localization initialized'); | ||
} | ||
|
||
Future<void> deleteSaveLocale() async { | ||
_savedLocale = null; | ||
final preferences = await SharedPreferences.getInstance(); | ||
await preferences.remove('locale'); | ||
storage.setLocale(); | ||
EasyLocalization.logger('Saved locale deleted'); | ||
} | ||
|
||
Locale get deviceLocale => _deviceLocale; | ||
Locale? get savedLocale => _savedLocale; | ||
|
||
Future<void> resetLocale() async { | ||
final locale = selectLocaleFrom(_supportedLocales!, deviceLocale, fallbackLocale: _fallbackLocale); | ||
final locale = selectLocaleFrom(_supportedLocales, deviceLocale, | ||
fallbackLocale: _fallbackLocale); | ||
|
||
EasyLocalization.logger('Reset locale to $locale while the platform locale is $_deviceLocale and the fallback locale is $_fallbackLocale'); | ||
EasyLocalization.logger( | ||
'Reset locale to $locale while the platform locale is $_deviceLocale and the fallback locale is $_fallbackLocale'); | ||
await setLocale(locale); | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Miscellaneous | ||
*.class | ||
*.log | ||
*.pyc | ||
*.swp | ||
.DS_Store | ||
.atom/ | ||
.buildlog/ | ||
.history | ||
.svn/ | ||
migrate_working_dir/ | ||
|
||
# IntelliJ related | ||
*.iml | ||
*.ipr | ||
*.iws | ||
.idea/ | ||
|
||
# The .vscode folder contains launch configuration and tasks you configure in | ||
# VS Code which you may wish to be included in version control, so this line | ||
# is commented out by default. | ||
#.vscode/ | ||
|
||
# Flutter/Dart/Pub related | ||
# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock. | ||
/pubspec.lock | ||
**/doc/api/ | ||
.dart_tool/ | ||
build/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# This file tracks properties of this Flutter project. | ||
# Used by Flutter tool to assess capabilities and perform upgrades etc. | ||
# | ||
# This file should be version controlled and should not be manually edited. | ||
|
||
version: | ||
revision: "603104015dd692ea3403755b55d07813d5cf8965" | ||
channel: "stable" | ||
|
||
project_type: package |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
## 0.0.1 | ||
|
||
* TODO: Describe initial release. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
TODO: Add your license here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Enhance gender switch accessibility.
The gender switch lacks proper accessibility labels which could make it difficult for screen readers.
Add semantic labels:
📝 Committable suggestion