| 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 defines a class for loading locale data incrementally from | 6 * This defines a class for loading locale data incrementally from |
| 7 * an external source as JSON. The external sources expected are either | 7 * an external source as JSON. The external sources expected are either |
| 8 * local files or via HTTP request. | 8 * local files or via HTTP request. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 library lazy_locale_data; | 11 library lazy_locale_data; |
| 12 import 'dart:async'; |
| 12 import 'dart:uri'; | 13 import 'dart:uri'; |
| 13 import 'intl_helpers.dart'; | 14 import 'intl_helpers.dart'; |
| 14 import 'dart:json'; | 15 import 'dart:json' as json; |
| 15 | 16 |
| 16 /** | 17 /** |
| 17 * This implements the very basic map-type operations which are used | 18 * This implements the very basic map-type operations which are used |
| 18 * in locale lookup, and looks them up based on a URL that defines | 19 * in locale lookup, and looks them up based on a URL that defines |
| 19 * the external source. | 20 * the external source. |
| 20 */ | 21 */ |
| 21 class LazyLocaleData { | 22 class LazyLocaleData { |
| 22 /// This holds the data we have loaded. | 23 /// This holds the data we have loaded. |
| 23 Map map; | 24 Map map; |
| 24 | 25 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 */ | 93 */ |
| 93 unsupportedLocale(localeName) { throw new LocaleDataException( | 94 unsupportedLocale(localeName) { throw new LocaleDataException( |
| 94 'Locale $localeName has no data available');} | 95 'Locale $localeName has no data available');} |
| 95 | 96 |
| 96 /** | 97 /** |
| 97 * Initialize for locale. Internal use only. As a user, call | 98 * Initialize for locale. Internal use only. As a user, call |
| 98 * initializeDateFormatting instead. | 99 * initializeDateFormatting instead. |
| 99 */ | 100 */ |
| 100 Future initLocale(String localeName) { | 101 Future initLocale(String localeName) { |
| 101 var data = _reader.read(localeName); | 102 var data = _reader.read(localeName); |
| 102 return jsonData(data).transform( (input) { | 103 return jsonData(data).then( (input) { |
| 103 map[localeName] = _creationFunction(input);}); | 104 map[localeName] = _creationFunction(input);}); |
| 104 } | 105 } |
| 105 | 106 |
| 106 /** | 107 /** |
| 107 * Given a Future [input] whose value is expected to be a string in JSON form, | 108 * Given a Future [input] whose value is expected to be a string in JSON form, |
| 108 * return another future that parses the JSON into a usable format. | 109 * return another future that parses the JSON into a usable format. |
| 109 */ | 110 */ |
| 110 Future jsonData(Future input) { | 111 Future jsonData(Future input) { |
| 111 return input.transform( (response) => JSON.parse(response)); | 112 return input.then( (response) => json.parse(response)); |
| 112 } | 113 } |
| 113 } | 114 } |
| OLD | NEW |