[email protected] | 47a318c | 2012-09-05 19:54:01 +0000 | [diff] [blame] | 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 | |
alanknight | a110b9c | 2016-01-11 09:54:18 -0800 | [diff] [blame^] | 5 | /// This file should be imported, along with date_format.dart in order to read |
| 6 | /// locale data from files in the file system. |
[email protected] | 47a318c | 2012-09-05 19:54:01 +0000 | [diff] [blame] | 7 | |
[email protected] | 529c00a | 2014-04-21 21:34:47 +0000 | [diff] [blame] | 8 | library date_symbol_data_file; |
[email protected] | 47a318c | 2012-09-05 19:54:01 +0000 | [diff] [blame] | 9 | |
[email protected] | ad19627 | 2013-01-07 11:23:16 +0000 | [diff] [blame] | 10 | import 'dart:async'; |
[email protected] | d27c8f1 | 2014-04-21 22:04:20 +0000 | [diff] [blame] | 11 | |
[email protected] | 67d9da7 | 2013-07-12 17:54:48 +0000 | [diff] [blame] | 12 | import 'package:path/path.dart' as path; |
[email protected] | 47a318c | 2012-09-05 19:54:01 +0000 | [diff] [blame] | 13 | |
[email protected] | d27c8f1 | 2014-04-21 22:04:20 +0000 | [diff] [blame] | 14 | import 'date_symbols.dart'; |
| 15 | import 'src/data/dates/locale_list.dart'; |
| 16 | import 'src/date_format_internal.dart'; |
| 17 | import 'src/file_data_reader.dart'; |
| 18 | import 'src/lazy_locale_data.dart'; |
| 19 | |
| 20 | export 'src/data/dates/locale_list.dart'; |
[email protected] | 47a318c | 2012-09-05 19:54:01 +0000 | [diff] [blame] | 21 | |
alanknight | a110b9c | 2016-01-11 09:54:18 -0800 | [diff] [blame^] | 22 | /// This should be called for at least one [locale] before any date formatting |
| 23 | /// methods are called. It sets up the lookup for date symbols using [path]. |
| 24 | /// The [path] parameter should end with a directory separator appropriate |
| 25 | /// for the platform. |
[email protected] | 3a314d3 | 2013-03-14 20:49:26 +0000 | [diff] [blame] | 26 | Future initializeDateFormatting(String locale, String filePath) { |
| 27 | var reader = new FileDataReader(path.join(filePath, 'symbols')); |
[email protected] | 47a318c | 2012-09-05 19:54:01 +0000 | [diff] [blame] | 28 | initializeDateSymbols(() => new LazyLocaleData( |
| 29 | reader, _createDateSymbol, availableLocalesForDateFormatting)); |
[email protected] | 3a314d3 | 2013-03-14 20:49:26 +0000 | [diff] [blame] | 30 | var reader2 = new FileDataReader(path.join(filePath, 'patterns')); |
Kevin Moore | 4f4b8b4 | 2015-04-24 16:34:31 -0700 | [diff] [blame] | 31 | initializeDatePatterns(() => |
| 32 | new LazyLocaleData(reader2, (x) => x, availableLocalesForDateFormatting)); |
| 33 | return initializeIndividualLocaleDateFormatting((symbols, patterns) { |
| 34 | return Future |
| 35 | .wait([symbols.initLocale(locale), patterns.initLocale(locale)]); |
| 36 | }); |
[email protected] | 47a318c | 2012-09-05 19:54:01 +0000 | [diff] [blame] | 37 | } |
| 38 | |
alanknight | a110b9c | 2016-01-11 09:54:18 -0800 | [diff] [blame^] | 39 | /// Defines how new date symbol entries are created. |
[email protected] | 388c91e | 2014-01-31 21:36:12 +0000 | [diff] [blame] | 40 | DateSymbols _createDateSymbol(Map map) => |
| 41 | new DateSymbols.deserializeFromMap(map); |