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

Side by Side Diff: pkg/intl/lib/intl.dart

Issue 179783004: Verify the default locale in case we're given an invalid one and need to fall back. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Review fixes Created 6 years, 10 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/intl/lib/generate_localized.dart ('k') | pkg/intl/test/intl_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 /** 5 /**
6 * This library provides internationalization and localization. This includes 6 * This library provides internationalization and localization. This includes
7 * message formatting and replacement, date and number formatting and parsing, 7 * message formatting and replacement, date and number formatting and parsing,
8 * and utilities for working with Bidirectional text. 8 * and utilities for working with Bidirectional text.
9 * 9 *
10 * This is part of the [intl package] 10 * This is part of the [intl package]
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 * Note that null is interpreted as meaning the default locale, so if 185 * Note that null is interpreted as meaning the default locale, so if
186 * [newLocale] is null it will be returned. 186 * [newLocale] is null it will be returned.
187 */ 187 */
188 static String verifiedLocale(String newLocale, Function localeExists, 188 static String verifiedLocale(String newLocale, Function localeExists,
189 {Function onFailure: _throwLocaleError}) { 189 {Function onFailure: _throwLocaleError}) {
190 // TODO(alanknight): Previously we kept a single verified locale on the Intl 190 // TODO(alanknight): Previously we kept a single verified locale on the Intl
191 // object, but with different verification for different uses, that's more 191 // object, but with different verification for different uses, that's more
192 // difficult. As a result, we call this more often. Consider keeping 192 // difficult. As a result, we call this more often. Consider keeping
193 // verified locales for each purpose if it turns out to be a performance 193 // verified locales for each purpose if it turns out to be a performance
194 // issue. 194 // issue.
195 if (newLocale == null) return getCurrentLocale(); 195 if (newLocale == null) {
196 return verifiedLocale(getCurrentLocale(), localeExists,
197 onFailure: onFailure);
198 }
196 if (localeExists(newLocale)) { 199 if (localeExists(newLocale)) {
197 return newLocale; 200 return newLocale;
198 } 201 }
199 for (var each in 202 for (var each in
200 [canonicalizedLocale(newLocale), shortLocale(newLocale)]) { 203 [canonicalizedLocale(newLocale), shortLocale(newLocale)]) {
201 if (localeExists(each)) { 204 if (localeExists(each)) {
202 return each; 205 return each;
203 } 206 }
204 } 207 }
205 return onFailure(newLocale); 208 return onFailure(newLocale);
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 * unless for some reason this gets called inside a message that resets the 363 * unless for some reason this gets called inside a message that resets the
361 * locale. 364 * locale.
362 */ 365 */
363 static String getCurrentLocale() { 366 static String getCurrentLocale() {
364 if (defaultLocale == null) defaultLocale = systemLocale; 367 if (defaultLocale == null) defaultLocale = systemLocale;
365 return defaultLocale; 368 return defaultLocale;
366 } 369 }
367 370
368 toString() => "Intl($locale)"; 371 toString() => "Intl($locale)";
369 } 372 }
OLDNEW
« no previous file with comments | « pkg/intl/lib/generate_localized.dart ('k') | pkg/intl/test/intl_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698