blob: 1e641dff4441a1fb1df8deef2846b679812c0970 [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
5/**
6 * This file should be imported, along with date_format.dart in order to read
7 * locale data from files in the file system.
8 */
9
[email protected]529c00a2014-04-21 21:34:47 +000010library date_symbol_data_file;
[email protected]47a318c2012-09-05 19:54:01 +000011
[email protected]ad196272013-01-07 11:23:16 +000012import 'dart:async';
[email protected]d27c8f12014-04-21 22:04:20 +000013
[email protected]67d9da72013-07-12 17:54:48 +000014import 'package:path/path.dart' as path;
[email protected]47a318c2012-09-05 19:54:01 +000015
[email protected]d27c8f12014-04-21 22:04:20 +000016import 'date_symbols.dart';
17import 'src/data/dates/locale_list.dart';
18import 'src/date_format_internal.dart';
19import 'src/file_data_reader.dart';
20import 'src/lazy_locale_data.dart';
21
22export 'src/data/dates/locale_list.dart';
[email protected]47a318c2012-09-05 19:54:01 +000023
24/**
25 * This should be called for at least one [locale] before any date formatting
26 * methods are called. It sets up the lookup for date symbols using [path].
27 * The [path] parameter should end with a directory separator appropriate
28 * for the platform.
29 */
[email protected]3a314d32013-03-14 20:49:26 +000030Future initializeDateFormatting(String locale, String filePath) {
31 var reader = new FileDataReader(path.join(filePath, 'symbols'));
[email protected]47a318c2012-09-05 19:54:01 +000032 initializeDateSymbols(() => new LazyLocaleData(
33 reader, _createDateSymbol, availableLocalesForDateFormatting));
[email protected]3a314d32013-03-14 20:49:26 +000034 var reader2 = new FileDataReader(path.join(filePath, 'patterns'));
[email protected]47a318c2012-09-05 19:54:01 +000035 initializeDatePatterns(() => new LazyLocaleData(
36 reader2, (x) => x, availableLocalesForDateFormatting));
37 return initializeIndividualLocaleDateFormatting(
38 (symbols, patterns) {
[email protected]bd2d2a92013-01-11 09:46:45 +000039 return Future.wait([
[email protected]47a318c2012-09-05 19:54:01 +000040 symbols.initLocale(locale),
41 patterns.initLocale(locale)]);
42 });
43}
44
45/** Defines how new date symbol entries are created. */
[email protected]388c91e2014-01-31 21:36:12 +000046DateSymbols _createDateSymbol(Map map) =>
47 new DateSymbols.deserializeFromMap(map);