| OLD | NEW |
| 1 #!/usr/bin/env dart | 1 #!/usr/bin/env dart |
| 2 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 2 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 3 // for details. All rights reserved. Use of this source code is governed by a | 3 // for details. All rights reserved. Use of this source code is governed by a |
| 4 // BSD-style license that can be found in the LICENSE file. | 4 // BSD-style license that can be found in the LICENSE file. |
| 5 | 5 |
| 6 /** | 6 /** |
| 7 * This script uses the extract_messages.dart library to find the Intl.message | 7 * This script uses the extract_messages.dart library to find the Intl.message |
| 8 * calls in the target dart files and produces intl_messages.json containing the | 8 * calls in the target dart files and produces intl_messages.json containing the |
| 9 * information on those messages. It uses the analyzer-experimental parser | 9 * information on those messages. It uses the analyzer-experimental parser |
| 10 * to find the information. | 10 * to find the information. |
| 11 * | 11 * |
| 12 * This is intended to test the basic functioning of extracting messages and | 12 * This is intended to test the basic functioning of extracting messages and |
| 13 * serve as an example for how a program to extract them to a translation | 13 * serve as an example for how a program to extract them to a translation |
| 14 * file format could work. In the tests, this file is then run through a | 14 * file format could work. In the tests, this file is then run through a |
| 15 * simulated translation and the results of that are used to generate code. See | 15 * simulated translation and the results of that are used to generate code. See |
| 16 * message_extraction_test.dart | 16 * message_extraction_test.dart |
| 17 * | 17 * |
| 18 * If the environment variable INTL_MESSAGE_OUTPUT is set then it will use | 18 * If the environment variable INTL_MESSAGE_OUTPUT is set then it will use |
| 19 * that as the output directory, otherwise it will use the working directory. | 19 * that as the output directory, otherwise it will use the working directory. |
| 20 */ | 20 */ |
| 21 library extract_to_json; | 21 library extract_to_json; |
| 22 | 22 |
| 23 import 'dart:convert'; | 23 import 'dart:convert'; |
| 24 import 'dart:io'; | 24 import 'dart:io'; |
| 25 import 'package:intl/extract_messages.dart'; | 25 import 'package:intl/extract_messages.dart'; |
| 26 import 'package:path/path.dart' as path; | 26 import 'package:path/path.dart' as path; |
| 27 import 'package:intl/src/intl_message.dart'; | 27 import 'package:intl/src/intl_message.dart'; |
| 28 import 'package:args/args.dart'; | 28 import 'package:args/args.dart'; |
| 29 | 29 |
| 30 main() { | 30 main(List<String> args) { |
| 31 var args = new Options().arguments; | |
| 32 var targetDir; | 31 var targetDir; |
| 33 var parser = new ArgParser(); | 32 var parser = new ArgParser(); |
| 34 parser.addFlag("suppress-warnings", defaultsTo: false, | 33 parser.addFlag("suppress-warnings", defaultsTo: false, |
| 35 callback: (x) => suppressWarnings = x); | 34 callback: (x) => suppressWarnings = x); |
| 36 parser.addFlag("warnings-are-errors", defaultsTo: false, | 35 parser.addFlag("warnings-are-errors", defaultsTo: false, |
| 37 callback: (x) => warningsAreErrors = x); | 36 callback: (x) => warningsAreErrors = x); |
| 38 | 37 |
| 39 parser.addOption("output-dir", defaultsTo: '.', | 38 parser.addOption("output-dir", defaultsTo: '.', |
| 40 callback: (value) => targetDir = value); | 39 callback: (value) => targetDir = value); |
| 41 parser.parse(args); | 40 parser.parse(args); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 71 /** | 70 /** |
| 72 * Convert the [MainMessage] to a trivial JSON format. | 71 * Convert the [MainMessage] to a trivial JSON format. |
| 73 */ | 72 */ |
| 74 Map toJson(MainMessage message) { | 73 Map toJson(MainMessage message) { |
| 75 var result = new Map<String, Object>(); | 74 var result = new Map<String, Object>(); |
| 76 for (var attribute in message.attributeNames) { | 75 for (var attribute in message.attributeNames) { |
| 77 result[attribute] = message[attribute]; | 76 result[attribute] = message[attribute]; |
| 78 } | 77 } |
| 79 result["message"] = message.expanded(leaveTheInterpolationsInDartForm); | 78 result["message"] = message.expanded(leaveTheInterpolationsInDartForm); |
| 80 return result; | 79 return result; |
| 81 } | 80 } |
| OLD | NEW |