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

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

Issue 11086033: Make verifiedLocale work differently depending on what it's verifying for (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 2 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/message_lookup_local.dart
===================================================================
--- pkg/intl/lib/message_lookup_local.dart (revision 13446)
+++ pkg/intl/lib/message_lookup_local.dart (working copy)
@@ -58,6 +58,15 @@
}
/**
+ * Return true if the locale exists, or if it is null. The null case
+ * is interpreted to mean that we use the default locale.
+ */
+ bool localeExists(localeName) {
+ if (localeName == null) return false;
+ return _libraries['$_sourcePrefix$localeName'] != null;
+ }
+
+ /**
* Return the localized version of a message. We are passed the original
* version of the message, which consists of a
* [message_str] that will be translated, and which may be interpolated
@@ -89,10 +98,16 @@
_lookupInProgress = true;
var result;
try {
- // TODO(alanknight): Look up alternate forms, e.g. en for en_US
var actualLocale = (locale == null) ? Intl.getCurrentLocale() : locale;
+ // For this usage, if the locale doesn't exist for messages, just return
+ // it and we'll fall back to the original version.
+ var verifiedLocale =
+ Intl.verifiedLocale(
+ actualLocale,
+ localeExists,
+ onFailure: (locale)=>locale);
LibraryMirror messagesForThisLocale =
- _libraries['$_sourcePrefix$actualLocale'];
+ _libraries['$_sourcePrefix$verifiedLocale'];
if (messagesForThisLocale == null) return message_str;
MethodMirror localized = messagesForThisLocale.functions[name];
if (localized == null) return message_str;

Powered by Google App Engine
This is Rietveld 408576698