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

Throw if the main argument in plurals does not match the argument list. #873

Open
wants to merge 4 commits into
base: main
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
3 changes: 2 additions & 1 deletion pkgs/intl_translation/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## 0.20.1-wip
## 0.20.1
* Add topics to `pubspec.yaml`
* Throw if the main argument in plurals and selects does not match the argument list.

## 0.20.0
* Throw if the `Intl.select` `arg` is not in the list of `args`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,14 @@ abstract class SubMessage extends ComplexMessage {
List toJson() {
var json = [];
json.add(dartMessageName);
json.add(arguments.indexOf(mainArgument));
var indexOf = arguments.indexOf(mainArgument);
if (indexOf == -1) {
// This is an error as this should have been checked in
// lib/visitors/plural_gender_visitor.dart already.
throw ArgumentError('The argument `$mainArgument` could not be found in '
'`$arguments`.');
}
json.add(indexOf);
for (var arg in codeAttributeNames) {
json.add(this[arg]?.toJson());
}
Expand Down
7 changes: 7 additions & 0 deletions pkgs/intl_translation/lib/visitors/plural_gender_visitor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,13 @@ class PluralAndGenderVisitor extends SimpleAstVisitor<void> {
extraction.warnings.add(errString);
}

if (!message.arguments.contains(message.mainArgument)) {
throw Exception(
'Argument `${message.mainArgument}` could not be found in '
'${message.arguments} while processing $node. The parent argument '
'name must match the one in the `Intl.` call.');
}

return message;
}
}
2 changes: 1 addition & 1 deletion pkgs/intl_translation/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: intl_translation
version: 0.20.1-wip
version: 0.20.1
description: >-
Contains code to deal with internationalized/localized messages,
date and number formatting and parsing, bi-directional text, and
Expand Down
Loading