Skip to content
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

Static type for EasyLocalization.assetLoader (#524) #598

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

### [4.0.0]

- **BREAKING:** `EasyLocalization.assetLoader` is now `AssetLoader` (was dynamic).

### [3.0.2]

- support intl 18
Expand Down
27 changes: 17 additions & 10 deletions lib/src/easy_localization_app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ class EasyLocalization extends StatefulWidget {
/// Class loader for localization files.
/// You can use custom loaders from [Easy Localization Loader](https://github.com/aissat/easy_localization_loader) or create your own class.
/// @Default value `const RootBundleAssetLoader()`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this still correct?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

  1. One can use the loaders from that package, after Delete local AssetLoader class, update dependencies (#46) easy_localization_loader#50 is merged and published.
  2. One can still create their own class.
  3. The default is still const RootBundleAssetLoader().

// ignore: prefer_typing_uninitialized_variables
final assetLoader;
final AssetLoader assetLoader;

/// Save locale in device storage.
/// @Default value true
Expand Down Expand Up @@ -195,9 +194,12 @@ class _EasyLocalizationProvider extends InheritedWidget {

// _EasyLocalizationDelegate get delegate => parent.delegate;

_EasyLocalizationProvider(this.parent, this._localeState,
{Key? key, required this.delegate})
: currentLocale = _localeState.locale,
_EasyLocalizationProvider(
this.parent,
this._localeState, {
Key? key,
required this.delegate,
}) : currentLocale = _localeState.locale,
super(key: key, child: parent.child) {
EasyLocalization.logger.debug('Init provider');
}
Expand Down Expand Up @@ -245,8 +247,10 @@ class _EasyLocalizationDelegate extends LocalizationsDelegate<Localization> {
/// * use only the lang code to generate i18n file path like en.json or ar.json
// final bool useOnlyLangCode;

_EasyLocalizationDelegate(
{this.localizationController, this.supportedLocales}) {
_EasyLocalizationDelegate({
this.localizationController,
this.supportedLocales,
}) {
EasyLocalization.logger.debug('Init Localization Delegate');
}

Expand All @@ -260,9 +264,12 @@ class _EasyLocalizationDelegate extends LocalizationsDelegate<Localization> {
await localizationController!.loadTranslations();
}

Localization.load(value,
translations: localizationController!.translations,
fallbackTranslations: localizationController!.fallbackTranslations);
Localization.load(
value,
translations: localizationController!.translations,
fallbackTranslations: localizationController!.fallbackTranslations,
);

return Future.value(Localization.instance);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/src/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Locale localeFromString(String localeString) {
}

/// Convert [locale] to Srting with custom [separator]
@Deprecated('Deprecated on Easy Localization 3.0')
@Deprecated('Deprecated on Easy Localization 3.0, use Locale.toStringWithSeparator extension method.')
String localeToString(Locale locale, {String separator = '_'}) {
return locale.toString().split('_').join(separator);
}
Expand Down
21 changes: 8 additions & 13 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,28 +1,23 @@
name: easy_localization
description: Easy and Fast internationalizing and localization your Flutter Apps, this package simplify the internationalizing process .
description: Easy and fast internationalizing and localization your Flutter Apps, this package simplifies the internationalizing process.
# author: AISSAT abdelwahab <[email protected]>
homepage: https://github.com/aissat/easy_localization
issue_tracker: https://github.com/aissat/easy_localization/issues
# publish_to: none

version: 3.0.2
version: 4.0.0-dev

environment:
sdk: '>=2.12.0 <4.0.0'

dependencies:
flutter:
sdk: flutter
shared_preferences: '>=2.0.0 <3.0.0'
intl: '>=0.17.0-0 <=0.18.1'
args: ^2.3.1
path: ^1.8.1
easy_logger: ^0.0.2
flutter_localizations:
sdk: flutter

flutter: { sdk: flutter }
flutter_localizations: { sdk: flutter }
intl: '>=0.17.0-0 <=0.18.1'
path: ^1.8.1
shared_preferences: '>=2.0.0 <3.0.0'

dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^2.0.1
flutter_test: { sdk: flutter }