[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. |
[email protected] | 47a318c | 2012-09-05 19:54:01 +0000 | [diff] [blame] | 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] | 67d9da7 | 2013-07-12 17:54:48 +0000 | [diff] [blame] | 10 | import 'package:path/path.dart' as path; |
[email protected] | 47a318c | 2012-09-05 19:54:01 +0000 | [diff] [blame] | 11 | |
[email protected] | d27c8f1 | 2014-04-21 22:04:20 +0000 | [diff] [blame] | 12 | import 'date_symbols.dart'; |
| 13 | import 'src/data/dates/locale_list.dart'; |
| 14 | import 'src/date_format_internal.dart'; |
| 15 | import 'src/file_data_reader.dart'; |
| 16 | import 'src/lazy_locale_data.dart'; |
| 17 | |
| 18 | export 'src/data/dates/locale_list.dart'; |
[email protected] | 47a318c | 2012-09-05 19:54:01 +0000 | [diff] [blame] | 19 | |
alanknight | a110b9c | 2016-01-11 09:54:18 -0800 | [diff] [blame] | 20 | /// This should be called for at least one [locale] before any date formatting |
| 21 | /// methods are called. It sets up the lookup for date symbols using [path]. |
| 22 | /// The [path] parameter should end with a directory separator appropriate |
| 23 | /// for the platform. |
Dart Team | 795c490 | 2019-08-29 10:58:28 -0700 | [diff] [blame] | 24 | Future<void> initializeDateFormatting(String locale, String filePath) { |
| 25 | var reader = FileDataReader(path.join(filePath, 'symbols')); |
| 26 | initializeDateSymbols(() => LazyLocaleData( |
[email protected] | 47a318c | 2012-09-05 19:54:01 +0000 | [diff] [blame] | 27 | reader, _createDateSymbol, availableLocalesForDateFormatting)); |
Dart Team | 795c490 | 2019-08-29 10:58:28 -0700 | [diff] [blame] | 28 | var reader2 = FileDataReader(path.join(filePath, 'patterns')); |
Kevin Moore | 4f4b8b4 | 2015-04-24 16:34:31 -0700 | [diff] [blame] | 29 | initializeDatePatterns(() => |
Dart Team | 795c490 | 2019-08-29 10:58:28 -0700 | [diff] [blame] | 30 | LazyLocaleData(reader2, (x) => x, availableLocalesForDateFormatting)); |
Kevin Moore | 4f4b8b4 | 2015-04-24 16:34:31 -0700 | [diff] [blame] | 31 | return initializeIndividualLocaleDateFormatting((symbols, patterns) { |
Dart Team | 795c490 | 2019-08-29 10:58:28 -0700 | [diff] [blame] | 32 | return Future.wait(<Future<dynamic>>[ |
| 33 | symbols.initLocale(locale), |
| 34 | patterns.initLocale(locale) |
| 35 | ]); |
Kevin Moore | 4f4b8b4 | 2015-04-24 16:34:31 -0700 | [diff] [blame] | 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. |
Dart Team | 795c490 | 2019-08-29 10:58:28 -0700 | [diff] [blame] | 40 | DateSymbols _createDateSymbol(Map<dynamic, dynamic> map) => |
| 41 | DateSymbols.deserializeFromMap(map); |