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

Add a fallback for pluralRules #566

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
8 changes: 5 additions & 3 deletions lib/src/localization.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ class Localization {
Localization();

static Localization? _instance;

static Localization get instance => _instance ?? (_instance = Localization());

static Localization? of(BuildContext context) =>
Localizations.of<Localization>(context, Localization);

Expand Down Expand Up @@ -108,9 +110,9 @@ class Localization {
return res;
}

static PluralRule? _pluralRule(String? locale, num howMany) {
static PluralRule _pluralRule(String? locale, num howMany) {
startRuleEvaluation(howMany);
return pluralRules[locale];
return pluralRules[locale] ?? () => PluralCase.OTHER;
}

String plural(
Expand All @@ -135,7 +137,7 @@ class Localization {
pluralCase = PluralCase.TWO;
break;
default:
pluralCase = pluralRule!();
pluralCase = pluralRule();
}
switch (pluralCase) {
case PluralCase.ZERO:
Expand Down
12 changes: 6 additions & 6 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ issue_tracker: https://github.com/aissat/easy_localization/issues
version: 3.0.2-dev.5

environment:
sdk: '>=2.12.0 <3.0.0'
sdk: '>=3.0.0 <4.0.0'

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


dev_dependencies:
Expand Down