Chromium Code Reviews| 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 * This is part of the [intl package] | 10 * This is part of the [intl package] |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 114 return new DateFormat(pattern, actualLocale); | 114 return new DateFormat(pattern, actualLocale); |
| 115 } | 115 } |
| 116 | 116 |
| 117 /** | 117 /** |
| 118 * Constructor optionally [aLocale] for specifics of the language | 118 * Constructor optionally [aLocale] for specifics of the language |
| 119 * locale to be used, otherwise, we will attempt to infer it (acceptable if | 119 * locale to be used, otherwise, we will attempt to infer it (acceptable if |
| 120 * Dart is running on the client, we can infer from the browser/client | 120 * Dart is running on the client, we can infer from the browser/client |
| 121 * preferences). | 121 * preferences). |
| 122 */ | 122 */ |
| 123 Intl([String aLocale]) { | 123 Intl([String aLocale]) { |
| 124 if (aLocale != null) { | 124 _locale = aLocale != null ? aLocale : getCurrentLocale(); |
| 125 _locale = aLocale; | |
| 126 } else { | |
| 127 _locale = getCurrentLocale(); | |
| 128 } | |
| 129 } | 125 } |
| 130 | 126 |
| 131 /** | 127 /** |
| 132 * Use this for a message that will be translated for different locales. The | 128 * Use this for a message that will be translated for different locales. The |
| 133 * expected usage is that this is inside an enclosing function that only | 129 * expected usage is that this is inside an enclosing function that only |
| 134 * returns the value of this call and provides a scope for the variables that | 130 * returns the value of this call and provides a scope for the variables that |
| 135 * will be substituted in the message. | 131 * will be substituted in the message. |
| 136 * | 132 * |
| 137 * The parameters are a | 133 * The parameters are a |
| 138 * [message_str] to be translated, which may be interpolated | 134 * [message_str] to be translated, which may be interpolated |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 170 /** | 166 /** |
| 171 * Return the locale for this instance. If none was set, the locale will | 167 * Return the locale for this instance. If none was set, the locale will |
| 172 * be the default. | 168 * be the default. |
| 173 */ | 169 */ |
| 174 String get locale => _locale; | 170 String get locale => _locale; |
| 175 | 171 |
| 176 /** | 172 /** |
| 177 * Return true if the locale exists, or if it is null. The null case | 173 * Return true if the locale exists, or if it is null. The null case |
| 178 * is interpreted to mean that we use the default locale. | 174 * is interpreted to mean that we use the default locale. |
| 179 */ | 175 */ |
| 180 static bool _localeExists(localeName) { | 176 static bool _localeExists(localeName) =>DateFormat.localeExists(localeName); |
|
Alan Knight
2014/01/28 01:33:46
Missing a space after the =>
vicb
2014/01/28 07:52:45
fixed
| |
| 181 return DateFormat.localeExists(localeName); | |
| 182 } | |
| 183 | 177 |
| 184 /** | 178 /** |
| 185 * Given [newLocale] return a locale that we have data for that is similar | 179 * Given [newLocale] return a locale that we have data for that is similar |
| 186 * to it, if possible. | 180 * to it, if possible. |
| 187 * If [newLocale] is found directly, return it. If it can't be found, look up | 181 * If [newLocale] is found directly, return it. If it can't be found, look up |
| 188 * based on just the language (e.g. 'en_CA' -> 'en'). Also accepts '-' | 182 * based on just the language (e.g. 'en_CA' -> 'en'). Also accepts '-' |
| 189 * as a separator and changes it into '_' for lookup, and changes the | 183 * as a separator and changes it into '_' for lookup, and changes the |
| 190 * country to uppercase. | 184 * country to uppercase. |
| 191 * 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 |
| 192 * [newLocale] is null it will be returned. | 186 * [newLocale] is null it will be returned. |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 366 * unless for some reason this gets called inside a message that resets the | 360 * unless for some reason this gets called inside a message that resets the |
| 367 * locale. | 361 * locale. |
| 368 */ | 362 */ |
| 369 static String getCurrentLocale() { | 363 static String getCurrentLocale() { |
| 370 if (defaultLocale == null) defaultLocale = systemLocale; | 364 if (defaultLocale == null) defaultLocale = systemLocale; |
| 371 return defaultLocale; | 365 return defaultLocale; |
| 372 } | 366 } |
| 373 | 367 |
| 374 toString() => "Intl($locale)"; | 368 toString() => "Intl($locale)"; |
| 375 } | 369 } |
| OLD | NEW |