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:io'; | 23 import 'dart:io'; |
24 import 'package:intl/extract_messages.dart'; | 24 import 'package:intl/extract_messages.dart'; |
25 import 'dart:json' as json; | 25 import 'dart:json' as json; |
26 import 'package:pathos/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() { |
31 var args = new Options().arguments; | 31 var args = new Options().arguments; |
32 var targetDir; | 32 var targetDir; |
33 var parser = new ArgParser(); | 33 var parser = new ArgParser(); |
34 parser.addFlag("suppress-warnings", defaultsTo: false, | 34 parser.addFlag("suppress-warnings", defaultsTo: false, |
35 callback: (x) => suppressWarnings = x); | 35 callback: (x) => suppressWarnings = x); |
36 | 36 |
(...skipping 30 matching lines...) Expand all Loading... |
67 * Convert the [MainMessage] to a trivial JSON format. | 67 * Convert the [MainMessage] to a trivial JSON format. |
68 */ | 68 */ |
69 Map toJson(MainMessage message) { | 69 Map toJson(MainMessage message) { |
70 var result = new Map<String, Object>(); | 70 var result = new Map<String, Object>(); |
71 for (var attribute in message.attributeNames) { | 71 for (var attribute in message.attributeNames) { |
72 result[attribute] = message[attribute]; | 72 result[attribute] = message[attribute]; |
73 } | 73 } |
74 result["message"] = message.expanded(leaveTheInterpolationsInDartForm); | 74 result["message"] = message.expanded(leaveTheInterpolationsInDartForm); |
75 return result; | 75 return result; |
76 } | 76 } |
OLD | NEW |