| 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" |
| 11 * and "patterns". In "data/dates" it will also generate "localeList.dart", | 11 * and "patterns". In "data/dates" it will also generate "localeList.dart", |
| 12 * which is sourced by the date_symbol_data... files. | 12 * which is sourced by the date_symbol_data... files. |
| 13 */ | 13 */ |
| 14 | 14 |
| 15 import '../lib/date_symbols.dart'; | 15 import '../lib/date_symbols.dart'; |
| 16 import '../lib/date_symbol_data_local.dart'; | 16 import '../lib/date_symbol_data_local.dart'; |
| 17 import '../lib/date_time_patterns.dart'; | 17 import '../lib/date_time_patterns.dart'; |
| 18 import '../lib/intl.dart'; | 18 import '../lib/intl.dart'; |
| 19 import 'dart:io'; | 19 import 'dart:io'; |
| 20 import 'dart:json' as json; | 20 import 'dart:json' as json; |
| 21 import '../test/data_directory.dart'; | 21 import '../test/data_directory.dart'; |
| 22 import 'package:pathos/path.dart' as path; |
| 22 | 23 |
| 23 main() { | 24 main() { |
| 24 initializeDateFormatting("en_IGNORED", null); | 25 initializeDateFormatting("en_IGNORED", null); |
| 25 writeSymbolData(); | 26 writeSymbolData(); |
| 26 writePatternData(); | 27 writePatternData(); |
| 27 writeLocaleList(); | 28 writeLocaleList(); |
| 28 } | 29 } |
| 29 | 30 |
| 30 void writeLocaleList() { | 31 void writeLocaleList() { |
| 31 var file = new File('${dataDirectory}localeList.dart'); | 32 var file = new File(path.join(dataDirectory, 'localeList.dart')); |
| 32 var output = file.openWrite(); | 33 var output = file.openWrite(); |
| 33 output.addString( | 34 output.write( |
| 34 '// Copyright (c) 2012, the Dart project authors. Please see the ' | 35 '// Copyright (c) 2012, the Dart project authors. Please see the ' |
| 35 'AUTHORS file\n// for details. All rights reserved. Use of this source' | 36 '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 'code is governed by a\n// BSD-style license that can be found in the' |
| 37 ' LICENSE file.\n\n' | 38 ' LICENSE file.\n\n' |
| 39 'part of date_symbol_data_json;\n\n' |
| 38 '/// Hard-coded list of all available locales for dates.\n'); | 40 '/// Hard-coded list of all available locales for dates.\n'); |
| 39 output.addString('final availableLocalesForDateFormatting = const ['); | 41 output.write('final availableLocalesForDateFormatting = const ['); |
| 40 List<String> allLocales = DateFormat.allLocalesWithSymbols(); | 42 List<String> allLocales = DateFormat.allLocalesWithSymbols(); |
| 41 allLocales.forEach((locale) { | 43 allLocales.forEach((locale) { |
| 42 output.addString('"$locale"'); | 44 output.write('"$locale"'); |
| 43 if (locale == allLocales.last) { | 45 if (locale == allLocales.last) { |
| 44 output.addString('];'); | 46 output.write('];'); |
| 45 } else { | 47 } else { |
| 46 output.addString(',\n '); | 48 output.write(',\n '); |
| 47 } | 49 } |
| 48 }); | 50 }); |
| 49 output.close(); | 51 output.close(); |
| 50 } | 52 } |
| 51 | 53 |
| 52 void writeSymbolData() { | 54 void writeSymbolData() { |
| 53 dateTimeSymbolMap().forEach( | 55 dateTimeSymbolMap().forEach( |
| 54 (locale, symbols) => writeSymbols(locale, symbols)); | 56 (locale, symbols) => writeSymbols(locale, symbols)); |
| 55 } | 57 } |
| 56 | 58 |
| 57 void writePatternData() { | 59 void writePatternData() { |
| 58 dateTimePatternMap().forEach( | 60 dateTimePatternMap().forEach( |
| 59 (locale, patterns) => writePatterns(locale, patterns)); | 61 (locale, patterns) => writePatterns(locale, patterns)); |
| 60 } | 62 } |
| 61 | 63 |
| 62 void writeSymbols(locale, symbols) { | 64 void writeSymbols(locale, symbols) { |
| 63 var file = new File('${dataDirectory}symbols/${locale}.json'); | 65 var file = new File(path.join(dataDirectory, 'symbols', '${locale}.json')); |
| 64 var output = file.openWrite(); | 66 var output = file.openWrite(); |
| 65 writeToJSON(symbols, output); | 67 writeToJSON(symbols, output); |
| 66 output.close(); | 68 output.close(); |
| 67 } | 69 } |
| 68 | 70 |
| 69 void writePatterns(locale, patterns) { | 71 void writePatterns(locale, patterns) { |
| 70 var file = new File('${dataDirectory}patterns/${locale}.json'); | 72 var file = new File(path.join(dataDirectory, 'patterns', '${locale}.json')); |
| 71 var output = file.openWrite(); | 73 var output = file.openWrite(); |
| 72 output.addString(json.stringify(patterns)); | 74 output.write(json.stringify(patterns)); |
| 73 output.close(); | 75 output.close(); |
| 74 } | 76 } |
| 75 | 77 |
| 76 void writeToJSON(dynamic data, IOSink out) { | 78 void writeToJSON(dynamic data, IOSink out) { |
| 77 out.addString(json.stringify(data.serializeToMap())); | 79 out.write(json.stringify(data.serializeToMap())); |
| 78 } | 80 } |
| OLD | NEW |