From 33d0d97e114f7503182cf7599b18a3893ef2a743 Mon Sep 17 00:00:00 2001 From: Moritz Date: Mon, 19 Aug 2024 15:17:47 +0200 Subject: [PATCH 1/4] Throw if the main argument in plurals does not match the argument list. --- .../lib/visitors/plural_gender_visitor.dart | 7 +++++++ 1 file changed, 7 insertions(+) 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; } } From ff4c9cbdb9418fc8d29e0c66267b98fefc827b89 Mon Sep 17 00:00:00 2001 From: Moritz Date: Mon, 19 Aug 2024 15:18:29 +0200 Subject: [PATCH 2/4] Add changelog --- pkgs/intl_translation/CHANGELOG.md | 3 ++- pkgs/intl_translation/pubspec.yaml | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) 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/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 From 2a2f55f120341f4bf703bb08d5b40eb557a2bd8f Mon Sep 17 00:00:00 2001 From: Moritz Date: Mon, 19 Aug 2024 15:21:15 +0200 Subject: [PATCH 3/4] Add throw --- .../lib/src/messages/submessages/submessage.dart | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pkgs/intl_translation/lib/src/messages/submessages/submessage.dart b/pkgs/intl_translation/lib/src/messages/submessages/submessage.dart index 8391804f..18353295 100644 --- a/pkgs/intl_translation/lib/src/messages/submessages/submessage.dart +++ b/pkgs/intl_translation/lib/src/messages/submessages/submessage.dart @@ -94,7 +94,12 @@ 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) { + throw ArgumentError('The argument `$mainArgument` could not be found in ' + '`$arguments`.'); + } + json.add(indexOf); for (var arg in codeAttributeNames) { json.add(this[arg]?.toJson()); } From b4b303119b476172f78284b6b73c1a91a0db666e Mon Sep 17 00:00:00 2001 From: Moritz Date: Mon, 19 Aug 2024 15:22:33 +0200 Subject: [PATCH 4/4] Add comment --- .../lib/src/messages/submessages/submessage.dart | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkgs/intl_translation/lib/src/messages/submessages/submessage.dart b/pkgs/intl_translation/lib/src/messages/submessages/submessage.dart index 18353295..7136e5ed 100644 --- a/pkgs/intl_translation/lib/src/messages/submessages/submessage.dart +++ b/pkgs/intl_translation/lib/src/messages/submessages/submessage.dart @@ -96,6 +96,8 @@ abstract class SubMessage extends ComplexMessage { json.add(dartMessageName); 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`.'); }