Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 that's represented as a Dart map | |
| 7 * indexed by locale into individual files named by locale. This should be run | |
| 8 * any time the locale data changes. | |
| 9 * This writes the files into two directories - the result of [dataDirectory], | |
| 10 * imported from date_time_format_file_test, and a subdirectory of it called | |
| 11 * patterns. The main directory will also have a list of all the locales in | |
| 12 * a file called localeList.dart, which will be imported by the | |
|
Emily Fortuna
2012/09/04 20:14:42
Comment is incomplete here. Try rephrasing this so
Alan Knight
2012/09/04 23:39:03
Done.
| |
| 13 */ | |
| 14 | |
| 15 #import('../date_symbols.dart'); | |
| 16 #import('../date_symbol_data_local.dart'); | |
| 17 #import('../date_time_patterns.dart'); | |
| 18 #import('../date_format.dart'); | |
| 19 #import('dart:io'); | |
| 20 #import('dart:json'); | |
| 21 #import('../test/data_directory.dart'); | |
| 22 | |
| 23 main() { | |
| 24 initializeDateFormatting("en_IGNORED", null); | |
| 25 writeSymbolData(); | |
| 26 writePatternData(); | |
| 27 // TODO(alanknight): Are the en_ISO patterns reliably the same as general en? | |
| 28 writePatterns("en_ISO", dateTimePatternMap()["en"]); | |
| 29 writeLocaleList(); | |
| 30 } | |
| 31 | |
| 32 void writeLocaleList() { | |
| 33 var file = new File('${dataDirectory}localeList.dart'); | |
| 34 var outputStream = file.openOutputStream(); | |
| 35 outputStream.writeString( | |
| 36 '// Copyright (c) 2012, the Dart project authors. Please see the ' | |
| 37 'AUTHORS file\n// for details. All rights reserved. Use of this source' | |
| 38 'code is governed by a\n// BSD-style license that can be found in the' | |
| 39 ' LICENSE file.\n\n' | |
| 40 '/// Hard-coded list of all available locales for dates.\n'); | |
| 41 outputStream.writeString('final availableLocalesForDateFormatting = const ['); | |
| 42 List<String> allLocales = DateFormat.allLocalesWithSymbols(); | |
| 43 allLocales.forEach((locale) { | |
| 44 outputStream.writeString('"$locale"'); | |
| 45 if (locale == allLocales.last()) { | |
| 46 outputStream.writeString('];'); | |
| 47 } else { | |
| 48 outputStream.writeString(',\n '); | |
| 49 } | |
| 50 }); | |
| 51 } | |
| 52 | |
| 53 void writeSymbolData() { | |
| 54 dateTimeSymbolMap().forEach( | |
| 55 (locale, symbols) => writeSymbols(locale, symbols)); | |
| 56 } | |
| 57 | |
| 58 void writePatternData() { | |
| 59 dateTimePatternMap().forEach( | |
| 60 (locale, patterns) => writePatterns(locale, patterns)); | |
| 61 } | |
| 62 | |
| 63 void writeSymbols(locale, symbols) { | |
| 64 var file = new File('${dataDirectory}symbols/${locale}.json'); | |
| 65 var outputStream = file.openOutputStream(); | |
| 66 writeToJSON(symbols, outputStream); | |
| 67 outputStream.close(); | |
| 68 } | |
| 69 | |
| 70 void writePatterns(locale, patterns) { | |
| 71 var file = new File('${dataDirectory}patterns/${locale}.json'); | |
| 72 var outputStream = file.openOutputStream(); | |
| 73 outputStream.writeString(JSON.stringify(patterns)); | |
| 74 outputStream.close(); | |
| 75 } | |
| 76 | |
| 77 void writeToJSON(Dynamic data, OutputStream out) { | |
| 78 out.writeString(JSON.stringify(data.serializeToMap())); | |
| 79 } | |
| OLD | NEW |