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 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 availableLocaleSet = new Set.from(availableLocales); | 57 availableLocaleSet = new Set.from(availableLocales); |
58 } | 58 } |
59 | 59 |
60 /** | 60 /** |
61 * Tests if we have data for the locale available. Note that this returns | 61 * Tests if we have data for the locale available. Note that this returns |
62 * true even if the data is known to be available remotely but not yet loaded. | 62 * true even if the data is known to be available remotely but not yet loaded. |
63 */ | 63 */ |
64 bool containsKey(String locale) => availableLocaleSet.contains(locale); | 64 bool containsKey(String locale) => availableLocaleSet.contains(locale); |
65 | 65 |
66 /** Returns the list of keys/locale names. */ | 66 /** Returns the list of keys/locale names. */ |
67 List getKeys() => availableLocales; | 67 List get keys => availableLocales; |
68 | 68 |
69 /** | 69 /** |
70 * Returns the data stored for [localeName]. If no data has been loaded | 70 * Returns the data stored for [localeName]. If no data has been loaded |
71 * for [localeName], throws an exception. If no data is available for | 71 * for [localeName], throws an exception. If no data is available for |
72 * [localeName] then throw an exception with a different message. | 72 * [localeName] then throw an exception with a different message. |
73 */ | 73 */ |
74 operator [](String localeName) { | 74 operator [](String localeName) { |
75 if (containsKey(localeName)) { | 75 if (containsKey(localeName)) { |
76 var data = map[localeName]; | 76 var data = map[localeName]; |
77 if (data == null) { | 77 if (data == null) { |
(...skipping 26 matching lines...) Expand all Loading... |
104 } | 104 } |
105 | 105 |
106 /** | 106 /** |
107 * Given a Future [input] whose value is expected to be a string in JSON form, | 107 * 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. | 108 * return another future that parses the JSON into a usable format. |
109 */ | 109 */ |
110 Future jsonData(Future input) { | 110 Future jsonData(Future input) { |
111 return input.transform( (response) => JSON.parse(response)); | 111 return input.transform( (response) => JSON.parse(response)); |
112 } | 112 } |
113 } | 113 } |
OLD | NEW |