Better error message for mismatched parameter names between message and translation

BUG=
R=cbracken@google.com

Review URL: https://codereview.chromium.org//720903003

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart/pkg/intl@41701 260f80e4-7a28-3924-810f-c04153c831b5
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b1ba358..ca7920e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -3,6 +3,10 @@
     is DateFormat.parseUtc, but the parseUTC variant is still retained
     for backward-compatibility.
 
+  * Provide a better error message when generating translated versions
+    and the name of a variable substitution in the message doesn't
+    match the name in the translation.
+
 ## 0.11.9
   * Fix bug with per-mille parsing (only divided by 100, not 1000)
   
diff --git a/lib/src/intl_message.dart b/lib/src/intl_message.dart
index 97eb48e..8bb9fdb 100644
--- a/lib/src/intl_message.dart
+++ b/lib/src/intl_message.dart
@@ -69,6 +69,11 @@
    */
   get examples => parent == null ? const [] : parent.examples;
 
+  /**
+   * The name of the top-level [MainMessage].
+   */
+  String get name => parent == null ? '<unnamed>' : parent.name;
+
   String checkValidity(MethodInvocation node, List arguments,
                        String outerName, FormalParameterList outerArgs) {
     var hasArgs = arguments.any(
@@ -274,6 +279,12 @@
     // case-insensitive.
     _index = arguments.map((x) => x.toUpperCase()).toList()
         .indexOf(_variableNameUpper);
+    if (_index == -1) {
+      throw new ArgumentError(
+          "Cannot find parameter named '$_variableNameUpper' in "
+          "message named '$name'. Available "
+          "parameters are $arguments");
+    }
     return _index;
   }
 
diff --git a/pubspec.yaml b/pubspec.yaml
index b87c445..1f7f06d 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,5 +1,5 @@
 name: intl
-version: 0.11.9
+version: 0.11.10
 author: Dart Team <misc@dartlang.org>
 description: Contains code to deal with internationalized/localized messages, date and number formatting and parsing, bi-directional text, and other internationalization issues.
 homepage: https://www.dartlang.org