Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(25)

Side by Side Diff: packages/intl/tool/generate_locale_data_files.dart

Issue 1400473008: Roll Observatory packages and add a roll script (Closed) Base URL: git@github.com:dart-lang/observatory_pub_packages.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « packages/intl/test/number_test_data.dart ('k') | packages/logging/.gitignore » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
5 /**
6 * A utility program to take locale data represented as a Dart map whose keys
7 * are locale names and write it into individual JSON files named by locale.
8 * This should be run any time the locale data changes.
9 *
10 * The files are written under "data/dates", in two subdirectories, "symbols"
11 * and "patterns". In "data/dates" it will also generate "locale_list.dart",
12 * which is sourced by the date_symbol_data... files.
13 */
14
15 import '../lib/date_symbol_data_local.dart';
16 import '../lib/date_time_patterns.dart';
17 import '../lib/intl.dart';
18 import 'dart:convert';
19 import 'dart:io';
20 import '../test/data_directory.dart';
21 import 'package:path/path.dart' as path;
22
23 main() {
24 initializeDateFormatting("en_IGNORED", null);
25 writeSymbolData();
26 writePatternData();
27 writeLocaleList();
28 }
29
30 void writeLocaleList() {
31 var file = new File(path.join(dataDirectory, 'locale_list.dart'));
32 var output = file.openWrite();
33 output.write(
34 '// Copyright (c) 2012, the Dart project authors. Please see the '
35 'AUTHORS file\n// for details. All rights reserved. Use of this source'
36 'code is governed by a\n// BSD-style license that can be found in the'
37 ' LICENSE file.\n\n'
38 '/// Hard-coded list of all available locales for dates.\n');
39 output.write('final availableLocalesForDateFormatting = const [');
40 List<String> allLocales = DateFormat.allLocalesWithSymbols();
41 allLocales.forEach((locale) {
42 output.write('"$locale"');
43 if (locale == allLocales.last) {
44 output.write('];');
45 } else {
46 output.write(',\n ');
47 }
48 });
49 output.close();
50 }
51
52 void writeSymbolData() {
53 dateTimeSymbolMap()
54 .forEach((locale, symbols) => writeSymbols(locale, symbols));
55 }
56
57 void writePatternData() {
58 dateTimePatternMap()
59 .forEach((locale, patterns) => writePatterns(locale, patterns));
60 }
61
62 void writeSymbols(locale, symbols) {
63 var file = new File(path.join(dataDirectory, 'symbols', '${locale}.json'));
64 var output = file.openWrite();
65 writeToJSON(symbols, output);
66 output.close();
67 }
68
69 void writePatterns(locale, patterns) {
70 var file = new File(path.join(dataDirectory, 'patterns', '${locale}.json'));
71 file.openWrite()
72 ..write(JSON.encode(patterns))
73 ..close();
74 }
75
76 void writeToJSON(dynamic data, IOSink out) {
77 out.write(JSON.encode(data.serializeToMap()));
78 }
OLDNEW
« no previous file with comments | « packages/intl/test/number_test_data.dart ('k') | packages/logging/.gitignore » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698