OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * A utility program to take locale data represented as a Dart map whose keys | 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. | 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. | 8 * This should be run any time the locale data changes. |
9 * | 9 * |
10 * The files are written under "data/dates", in two subdirectories, "symbols" | 10 * The files are written under "data/dates", in two subdirectories, "symbols" |
(...skipping 11 matching lines...) Expand all Loading... |
22 | 22 |
23 main() { | 23 main() { |
24 initializeDateFormatting("en_IGNORED", null); | 24 initializeDateFormatting("en_IGNORED", null); |
25 writeSymbolData(); | 25 writeSymbolData(); |
26 writePatternData(); | 26 writePatternData(); |
27 writeLocaleList(); | 27 writeLocaleList(); |
28 } | 28 } |
29 | 29 |
30 void writeLocaleList() { | 30 void writeLocaleList() { |
31 var file = new File('${dataDirectory}localeList.dart'); | 31 var file = new File('${dataDirectory}localeList.dart'); |
32 var outputStream = file.openOutputStream(); | 32 var output = file.openWrite(); |
33 outputStream.writeString( | 33 output.addString( |
34 '// Copyright (c) 2012, the Dart project authors. Please see the ' | 34 '// Copyright (c) 2012, the Dart project authors. Please see the ' |
35 'AUTHORS file\n// for details. All rights reserved. Use of this source' | 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' | 36 'code is governed by a\n// BSD-style license that can be found in the' |
37 ' LICENSE file.\n\n' | 37 ' LICENSE file.\n\n' |
38 '/// Hard-coded list of all available locales for dates.\n'); | 38 '/// Hard-coded list of all available locales for dates.\n'); |
39 outputStream.writeString('final availableLocalesForDateFormatting = const ['); | 39 output.addString('final availableLocalesForDateFormatting = const ['); |
40 List<String> allLocales = DateFormat.allLocalesWithSymbols(); | 40 List<String> allLocales = DateFormat.allLocalesWithSymbols(); |
41 allLocales.forEach((locale) { | 41 allLocales.forEach((locale) { |
42 outputStream.writeString('"$locale"'); | 42 output.addString('"$locale"'); |
43 if (locale == allLocales.last) { | 43 if (locale == allLocales.last) { |
44 outputStream.writeString('];'); | 44 output.addString('];'); |
45 } else { | 45 } else { |
46 outputStream.writeString(',\n '); | 46 output.addString(',\n '); |
47 } | 47 } |
48 }); | 48 }); |
| 49 output.close(); |
49 } | 50 } |
50 | 51 |
51 void writeSymbolData() { | 52 void writeSymbolData() { |
52 dateTimeSymbolMap().forEach( | 53 dateTimeSymbolMap().forEach( |
53 (locale, symbols) => writeSymbols(locale, symbols)); | 54 (locale, symbols) => writeSymbols(locale, symbols)); |
54 } | 55 } |
55 | 56 |
56 void writePatternData() { | 57 void writePatternData() { |
57 dateTimePatternMap().forEach( | 58 dateTimePatternMap().forEach( |
58 (locale, patterns) => writePatterns(locale, patterns)); | 59 (locale, patterns) => writePatterns(locale, patterns)); |
59 } | 60 } |
60 | 61 |
61 void writeSymbols(locale, symbols) { | 62 void writeSymbols(locale, symbols) { |
62 var file = new File('${dataDirectory}symbols/${locale}.json'); | 63 var file = new File('${dataDirectory}symbols/${locale}.json'); |
63 var outputStream = file.openOutputStream(); | 64 var output = file.openWrite(); |
64 writeToJSON(symbols, outputStream); | 65 writeToJSON(symbols, output); |
65 outputStream.close(); | 66 output.close(); |
66 } | 67 } |
67 | 68 |
68 void writePatterns(locale, patterns) { | 69 void writePatterns(locale, patterns) { |
69 var file = new File('${dataDirectory}patterns/${locale}.json'); | 70 var file = new File('${dataDirectory}patterns/${locale}.json'); |
70 var outputStream = file.openOutputStream(); | 71 var output = file.openWrite(); |
71 outputStream.writeString(json.stringify(patterns)); | 72 output.addString(json.stringify(patterns)); |
72 outputStream.close(); | 73 output.close(); |
73 } | 74 } |
74 | 75 |
75 void writeToJSON(dynamic data, OutputStream out) { | 76 void writeToJSON(dynamic data, IOSink out) { |
76 out.writeString(json.stringify(data.serializeToMap())); | 77 out.addString(json.stringify(data.serializeToMap())); |
77 } | 78 } |
OLD | NEW |