blob: bb14310361a6257a4e25a64650a918a83ea19d50 [file] [log] [blame]
[email protected]47a318c2012-09-05 19:54:01 +00001// 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]47a318c2012-09-05 19:54:01 +00004
alanknighta110b9c2016-01-11 09:54:18 -08005/// 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]47a318c2012-09-05 19:54:01 +00007
[email protected]529c00a2014-04-21 21:34:47 +00008library date_symbol_data_file;
[email protected]47a318c2012-09-05 19:54:01 +00009
[email protected]67d9da72013-07-12 17:54:48 +000010import 'package:path/path.dart' as path;
[email protected]47a318c2012-09-05 19:54:01 +000011
[email protected]d27c8f12014-04-21 22:04:20 +000012import 'date_symbols.dart';
13import 'src/data/dates/locale_list.dart';
14import 'src/date_format_internal.dart';
15import 'src/file_data_reader.dart';
16import 'src/lazy_locale_data.dart';
17
18export 'src/data/dates/locale_list.dart';
[email protected]47a318c2012-09-05 19:54:01 +000019
alanknighta110b9c2016-01-11 09:54:18 -080020/// 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 Team795c4902019-08-29 10:58:28 -070024Future<void> initializeDateFormatting(String locale, String filePath) {
25 var reader = FileDataReader(path.join(filePath, 'symbols'));
26 initializeDateSymbols(() => LazyLocaleData(
[email protected]47a318c2012-09-05 19:54:01 +000027 reader, _createDateSymbol, availableLocalesForDateFormatting));
Dart Team795c4902019-08-29 10:58:28 -070028 var reader2 = FileDataReader(path.join(filePath, 'patterns'));
Kevin Moore4f4b8b42015-04-24 16:34:31 -070029 initializeDatePatterns(() =>
Dart Team795c4902019-08-29 10:58:28 -070030 LazyLocaleData(reader2, (x) => x, availableLocalesForDateFormatting));
Kevin Moore4f4b8b42015-04-24 16:34:31 -070031 return initializeIndividualLocaleDateFormatting((symbols, patterns) {
Dart Team795c4902019-08-29 10:58:28 -070032 return Future.wait(<Future<dynamic>>[
33 symbols.initLocale(locale),
34 patterns.initLocale(locale)
35 ]);
Kevin Moore4f4b8b42015-04-24 16:34:31 -070036 });
[email protected]47a318c2012-09-05 19:54:01 +000037}
38
alanknighta110b9c2016-01-11 09:54:18 -080039/// Defines how new date symbol entries are created.
Dart Team795c4902019-08-29 10:58:28 -070040DateSymbols _createDateSymbol(Map<dynamic, dynamic> map) =>
41 DateSymbols.deserializeFromMap(map);