| 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 * For things that require locale or other data, there are multiple different | 10 * For things that require locale or other data, there are multiple different |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 * [message_function] that takes no parameters. The [message_function] can be | 225 * [message_function] that takes no parameters. The [message_function] can be |
| 226 * a simple message function that just returns the result of `Intl.message()` | 226 * a simple message function that just returns the result of `Intl.message()` |
| 227 * it can be a wrapper around a message function that takes arguments, or it | 227 * it can be a wrapper around a message function that takes arguments, or it |
| 228 * can be something more complex that manipulates multiple message | 228 * can be something more complex that manipulates multiple message |
| 229 * functions. | 229 * functions. |
| 230 * | 230 * |
| 231 * In either case, the purpose of this is to delay calling [message_function] | 231 * In either case, the purpose of this is to delay calling [message_function] |
| 232 * until the proper locale has been set. This returns the result of calling | 232 * until the proper locale has been set. This returns the result of calling |
| 233 * [msg_function], which could be of an arbitrary type. | 233 * [msg_function], which could be of an arbitrary type. |
| 234 */ | 234 */ |
| 235 static dynamic withLocale(String locale, Function message_function) { | 235 static withLocale(String locale, Function message_function) { |
| 236 // We have to do this silliness because Locale is not known at compile time, | 236 // We have to do this silliness because Locale is not known at compile time, |
| 237 // but must be a static variable in order to be visible to the Intl.message | 237 // but must be a static variable in order to be visible to the Intl.message |
| 238 // invocation. | 238 // invocation. |
| 239 if (_defaultLocale == null) _defaultLocale = systemLocale; | 239 if (_defaultLocale == null) _defaultLocale = systemLocale; |
| 240 var oldLocale = _defaultLocale; | 240 var oldLocale = _defaultLocale; |
| 241 _defaultLocale = locale; | 241 _defaultLocale = locale; |
| 242 var result = message_function(); | 242 var result = message_function(); |
| 243 _defaultLocale = oldLocale; | 243 _defaultLocale = oldLocale; |
| 244 return result; | 244 return result; |
| 245 } | 245 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 261 /** | 261 /** |
| 262 * Accessor for the current locale. This should always == the default locale, | 262 * Accessor for the current locale. This should always == the default locale, |
| 263 * unless for some reason this gets called inside a message that resets the | 263 * unless for some reason this gets called inside a message that resets the |
| 264 * locale. | 264 * locale. |
| 265 */ | 265 */ |
| 266 static String getCurrentLocale() { | 266 static String getCurrentLocale() { |
| 267 if (_defaultLocale == null) _defaultLocale = systemLocale; | 267 if (_defaultLocale == null) _defaultLocale = systemLocale; |
| 268 return _defaultLocale; | 268 return _defaultLocale; |
| 269 } | 269 } |
| 270 } | 270 } |
| OLD | NEW |