blob: c6c5f86a24406be01d6c64d6720ffbf36e856dbf [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.
4
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]ad196272013-01-07 11:23:16 +000010import 'dart:async';
[email protected]d27c8f12014-04-21 22:04:20 +000011
[email protected]67d9da72013-07-12 17:54:48 +000012import 'package:path/path.dart' as path;
[email protected]47a318c2012-09-05 19:54:01 +000013
[email protected]d27c8f12014-04-21 22:04:20 +000014import 'date_symbols.dart';
15import 'src/data/dates/locale_list.dart';
16import 'src/date_format_internal.dart';
17import 'src/file_data_reader.dart';
18import 'src/lazy_locale_data.dart';
19
20export 'src/data/dates/locale_list.dart';
[email protected]47a318c2012-09-05 19:54:01 +000021
alanknighta110b9c2016-01-11 09:54:18 -080022/// 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]3a314d32013-03-14 20:49:26 +000026Future initializeDateFormatting(String locale, String filePath) {
27 var reader = new FileDataReader(path.join(filePath, 'symbols'));
[email protected]47a318c2012-09-05 19:54:01 +000028 initializeDateSymbols(() => new LazyLocaleData(
29 reader, _createDateSymbol, availableLocalesForDateFormatting));
[email protected]3a314d32013-03-14 20:49:26 +000030 var reader2 = new FileDataReader(path.join(filePath, 'patterns'));
Kevin Moore4f4b8b42015-04-24 16:34:31 -070031 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]47a318c2012-09-05 19:54:01 +000037}
38
alanknighta110b9c2016-01-11 09:54:18 -080039/// Defines how new date symbol entries are created.
[email protected]388c91e2014-01-31 21:36:12 +000040DateSymbols _createDateSymbol(Map map) =>
41 new DateSymbols.deserializeFromMap(map);