OLD | NEW |
| (Empty) |
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 | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 /** | |
6 * This file should be imported, along with date_format.dart in order to read | |
7 * locale data via http requests to a web server.. | |
8 */ | |
9 library date_symbol_data_http_request; | |
10 | |
11 import 'dart:async'; | |
12 | |
13 import 'date_symbols.dart'; | |
14 import 'intl.dart'; | |
15 import 'src/data/dates/locale_list.dart'; | |
16 import 'src/date_format_internal.dart'; | |
17 import 'src/http_request_data_reader.dart'; | |
18 import 'src/lazy_locale_data.dart'; | |
19 | |
20 export 'src/data/dates/locale_list.dart'; | |
21 | |
22 /** | |
23 * This should be called for at least one [locale] before any date formatting | |
24 * methods are called. It sets up the lookup for date symbols using [url]. | |
25 * The [url] parameter should end with a "/". For example, | |
26 * "http://localhost:8000/dates/" | |
27 */ | |
28 Future initializeDateFormatting(String locale, String url) { | |
29 var reader = new HttpRequestDataReader('${url}symbols/'); | |
30 initializeDateSymbols(() => new LazyLocaleData( | |
31 reader, _createDateSymbol, availableLocalesForDateFormatting)); | |
32 var reader2 = new HttpRequestDataReader('${url}patterns/'); | |
33 initializeDatePatterns(() => new LazyLocaleData( | |
34 reader2, (x) => x, availableLocalesForDateFormatting)); | |
35 var actualLocale = Intl.verifiedLocale(locale, | |
36 (l) => availableLocalesForDateFormatting.contains(l)); | |
37 return initializeIndividualLocaleDateFormatting( | |
38 (symbols, patterns) { | |
39 return Future.wait([ | |
40 symbols.initLocale(actualLocale), | |
41 patterns.initLocale(actualLocale)]); | |
42 }); | |
43 } | |
44 | |
45 /** Defines how new date symbol entries are created. */ | |
46 DateSymbols _createDateSymbol(Map map) => | |
47 new DateSymbols.deserializeFromMap(map); | |
OLD | NEW |