Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(73)

Unified Diff: pkg/intl/lib/intl.dart

Issue 22286013: Add support for Intl.select (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: pkg/intl/lib/intl.dart
diff --git a/pkg/intl/lib/intl.dart b/pkg/intl/lib/intl.dart
index 00edd6f6c5b2cf5a2c065f73129a7df8df6757e4..7b642b423f8df83bbb57b25c71a67c782967b13a 100644
--- a/pkg/intl/lib/intl.dart
+++ b/pkg/intl/lib/intl.dart
@@ -302,6 +302,33 @@ class Intl {
}
/**
+ * Format a message differently depending on [choice]. We look up the value
+ * of [choice] in [cases] and return the result, or an empty string if
+ * it is not found. Normally used as part
+ * of an Intl.message message that is to be translated.
+ */
+ static String select(String choice, Map<String, String> cases,
+ {String desc, Map examples, String locale, String name,
+ List<String>args}) {
+ // If we are passed a name and arguments, then we are operating as a
+ // top-level message, so look up our translation by calling Intl.message
+ // with ourselves as an argument.
+ if (name != null) {
+ return Intl.message(
+ Intl.select(choice, cases),
Emily Fortuna 2013/08/08 23:49:55 indent this stuff +2 more spaces.
Alan Knight 2013/08/09 17:09:16 Done.
+ name: name,
+ args: args,
+ locale: locale);
+ }
+ var exact = cases[choice];
+ if (exact != null) return exact;
+ var other = cases["other"];
+ if (other == null)
+ throw new ArgumentError("The 'other' case must be specified");
+ return other;
+ }
+
+ /**
* Format the given function with a specific [locale], given a
* [message_function] that takes no parameters. The [message_function] can be
* a simple message function that just returns the result of `Intl.message()`
@@ -325,17 +352,6 @@ class Intl {
}
/**
- * Support method for message formatting. Select the correct exact (gender,
- * usually) form from [cases] given the user [choice].
- */
- static String select(String choice, Map cases) {
- var exact = cases[choice];
- if (exact != null) return exact;
- var other = cases["other"];
- return (other == null) ? '' : other;
- }
-
- /**
* Accessor for the current locale. This should always == the default locale,
* unless for some reason this gets called inside a message that resets the
* locale.

Powered by Google App Engine
This is Rietveld 408576698