diff --git a/pkgs/intl_translation/CHANGELOG.md b/pkgs/intl_translation/CHANGELOG.md index da255682..7f1b3590 100644 --- a/pkgs/intl_translation/CHANGELOG.md +++ b/pkgs/intl_translation/CHANGELOG.md @@ -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`. diff --git a/pkgs/intl_translation/lib/src/messages/submessages/submessage.dart b/pkgs/intl_translation/lib/src/messages/submessages/submessage.dart index 8391804f..7136e5ed 100644 --- a/pkgs/intl_translation/lib/src/messages/submessages/submessage.dart +++ b/pkgs/intl_translation/lib/src/messages/submessages/submessage.dart @@ -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()); } diff --git a/pkgs/intl_translation/lib/visitors/plural_gender_visitor.dart b/pkgs/intl_translation/lib/visitors/plural_gender_visitor.dart index be2f88d9..0ee70a5f 100644 --- a/pkgs/intl_translation/lib/visitors/plural_gender_visitor.dart +++ b/pkgs/intl_translation/lib/visitors/plural_gender_visitor.dart @@ -137,6 +137,13 @@ class PluralAndGenderVisitor extends SimpleAstVisitor { 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; } } diff --git a/pkgs/intl_translation/pubspec.yaml b/pkgs/intl_translation/pubspec.yaml index 6dd4cb0b..13352314 100644 --- a/pkgs/intl_translation/pubspec.yaml +++ b/pkgs/intl_translation/pubspec.yaml @@ -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