| OLD | NEW |
| 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 * ## Installing ## | 10 * ## Installing ## |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 // TODO(alanknight): Previously we kept a single verified locale on the Intl | 186 // TODO(alanknight): Previously we kept a single verified locale on the Intl |
| 187 // object, but with different verification for different uses, that's more | 187 // object, but with different verification for different uses, that's more |
| 188 // difficult. As a result, we call this more often. Consider keeping | 188 // difficult. As a result, we call this more often. Consider keeping |
| 189 // verified locales for each purpose if it turns out to be a performance | 189 // verified locales for each purpose if it turns out to be a performance |
| 190 // issue. | 190 // issue. |
| 191 if (newLocale == null) return getCurrentLocale(); | 191 if (newLocale == null) return getCurrentLocale(); |
| 192 if (localeExists(newLocale)) { | 192 if (localeExists(newLocale)) { |
| 193 return newLocale; | 193 return newLocale; |
| 194 } | 194 } |
| 195 for (var each in | 195 for (var each in |
| 196 [canonicalizedLocale(newLocale), _shortLocale(newLocale)]) { | 196 [canonicalizedLocale(newLocale), shortLocale(newLocale)]) { |
| 197 if (localeExists(each)) { | 197 if (localeExists(each)) { |
| 198 return each; | 198 return each; |
| 199 } | 199 } |
| 200 } | 200 } |
| 201 return onFailure(newLocale); | 201 return onFailure(newLocale); |
| 202 } | 202 } |
| 203 | 203 |
| 204 /** | 204 /** |
| 205 * The default action if a locale isn't found in verifiedLocale. Throw | 205 * The default action if a locale isn't found in verifiedLocale. Throw |
| 206 * an exception indicating the locale isn't correct. | 206 * an exception indicating the locale isn't correct. |
| 207 */ | 207 */ |
| 208 static String _throwLocaleError(String localeName) { | 208 static String _throwLocaleError(String localeName) { |
| 209 throw new ArgumentError("Invalid locale '$localeName'"); | 209 throw new ArgumentError("Invalid locale '$localeName'"); |
| 210 } | 210 } |
| 211 | 211 |
| 212 /** Return the short version of a locale name, e.g. 'en_US' => 'en' */ | 212 /** Return the short version of a locale name, e.g. 'en_US' => 'en' */ |
| 213 static String _shortLocale(String aLocale) { | 213 static String shortLocale(String aLocale) { |
| 214 if (aLocale.length < 2) return aLocale; | 214 if (aLocale.length < 2) return aLocale; |
| 215 return aLocale.substring(0, 2).toLowerCase(); | 215 return aLocale.substring(0, 2).toLowerCase(); |
| 216 } | 216 } |
| 217 | 217 |
| 218 /** | 218 /** |
| 219 * Return the name [aLocale] turned into xx_YY where it might possibly be | 219 * Return the name [aLocale] turned into xx_YY where it might possibly be |
| 220 * in the wrong case or with a hyphen instead of an underscore. If | 220 * in the wrong case or with a hyphen instead of an underscore. If |
| 221 * [aLocale] is null, for example, if you tried to get it from IE, | 221 * [aLocale] is null, for example, if you tried to get it from IE, |
| 222 * return the current system locale. | 222 * return the current system locale. |
| 223 */ | 223 */ |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 * unless for some reason this gets called inside a message that resets the | 315 * unless for some reason this gets called inside a message that resets the |
| 316 * locale. | 316 * locale. |
| 317 */ | 317 */ |
| 318 static String getCurrentLocale() { | 318 static String getCurrentLocale() { |
| 319 if (_defaultLocale == null) _defaultLocale = systemLocale; | 319 if (_defaultLocale == null) _defaultLocale = systemLocale; |
| 320 return _defaultLocale; | 320 return _defaultLocale; |
| 321 } | 321 } |
| 322 | 322 |
| 323 toString() => "Intl($locale)"; | 323 toString() => "Intl($locale)"; |
| 324 } | 324 } |
| OLD | NEW |