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 * A main program that takes as input a source Dart file and a number | 7 * A main program that takes as input a source Dart file and a number |
8 * of ARB files representing translations of messages from the corresponding | 8 * of ARB files representing translations of messages from the corresponding |
9 * Dart file. See extract_to_arb.dart and make_hardcoded_translation.dart. | 9 * Dart file. See extract_to_arb.dart and make_hardcoded_translation.dart. |
10 * | 10 * |
(...skipping 16 matching lines...) Expand all Loading... |
27 /** | 27 /** |
28 * Keeps track of all the messages we have processed so far, keyed by message | 28 * Keeps track of all the messages we have processed so far, keyed by message |
29 * name. | 29 * name. |
30 */ | 30 */ |
31 Map<String, List<MainMessage>> messages; | 31 Map<String, List<MainMessage>> messages; |
32 | 32 |
33 main(List<String> args) { | 33 main(List<String> args) { |
34 var targetDir; | 34 var targetDir; |
35 var parser = new ArgParser(); | 35 var parser = new ArgParser(); |
36 parser.addFlag("suppress-warnings", defaultsTo: false, | 36 parser.addFlag("suppress-warnings", defaultsTo: false, |
37 callback: (x) => suppressWarnings = x); | 37 callback: (x) => suppressWarnings = x, |
| 38 help: 'Suppress printing of warnings.'); |
38 parser.addOption("output-dir", defaultsTo: '.', | 39 parser.addOption("output-dir", defaultsTo: '.', |
39 callback: (x) => targetDir = x); | 40 callback: (x) => targetDir = x, |
| 41 help: 'Specify the output directory.'); |
40 parser.addOption("generated-file-prefix", defaultsTo: '', | 42 parser.addOption("generated-file-prefix", defaultsTo: '', |
41 callback: (x) => generatedFilePrefix = x); | 43 callback: (x) => generatedFilePrefix = x, |
| 44 help: 'Specify a prefix to be used for the generated file names.'); |
42 parser.addFlag("use-deferred-loading", defaultsTo: true, | 45 parser.addFlag("use-deferred-loading", defaultsTo: true, |
43 callback: (x) => useDeferredLoading = x); | 46 callback: (x) => useDeferredLoading = x, |
| 47 help: 'Generate message code that must be loaded with deferred loading. ' |
| 48 'Otherwise, all messages are eagerly loaded.'); |
44 parser.parse(args); | 49 parser.parse(args); |
45 var dartFiles = args.where((x) => x.endsWith("dart")).toList(); | 50 var dartFiles = args.where((x) => x.endsWith("dart")).toList(); |
46 var jsonFiles = args.where((x) => x.endsWith(".arb")).toList(); | 51 var jsonFiles = args.where((x) => x.endsWith(".arb")).toList(); |
47 if (dartFiles.length == 0 || jsonFiles.length == 0) { | 52 if (dartFiles.length == 0 || jsonFiles.length == 0) { |
48 print('Usage: generate_from_arb [--output-dir=<dir>]' | 53 print('Usage: generate_from_arb [options]' |
49 ' [--[no-]use-deferred-loading]' | 54 ' file1.dart file2.dart ...' |
50 ' [--generated-file-prefix=<prefix>] file1.dart file2.dart ...' | |
51 ' translation1_<languageTag>.arb translation2.arb ...'); | 55 ' translation1_<languageTag>.arb translation2.arb ...'); |
| 56 print(parser.getUsage()); |
52 exit(0); | 57 exit(0); |
53 } | 58 } |
54 | 59 |
55 // We're re-parsing the original files to find the corresponding messages, | 60 // We're re-parsing the original files to find the corresponding messages, |
56 // so if there are warnings extracting the messages, suppress them. | 61 // so if there are warnings extracting the messages, suppress them. |
57 suppressWarnings = true; | 62 suppressWarnings = true; |
58 var allMessages = dartFiles.map((each) => parseFile(new File(each))); | 63 var allMessages = dartFiles.map((each) => parseFile(new File(each))); |
59 | 64 |
60 messages = new Map(); | 65 messages = new Map(); |
61 for (var eachMap in allMessages) { | 66 for (var eachMap in allMessages) { |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 List<MainMessage> get originalMessages => (super.originalMessages == null) ? | 137 List<MainMessage> get originalMessages => (super.originalMessages == null) ? |
133 _findOriginals() : super.originalMessages; | 138 _findOriginals() : super.originalMessages; |
134 | 139 |
135 // We know that our [id] is the name of the message, which is used as the | 140 // We know that our [id] is the name of the message, which is used as the |
136 //key in [messages]. | 141 //key in [messages]. |
137 List<MainMessage> _findOriginals() => originalMessages = messages[id]; | 142 List<MainMessage> _findOriginals() => originalMessages = messages[id]; |
138 } | 143 } |
139 | 144 |
140 final pluralAndGenderParser = new IcuParser().message; | 145 final pluralAndGenderParser = new IcuParser().message; |
141 final plainParser = new IcuParser().nonIcuMessage; | 146 final plainParser = new IcuParser().nonIcuMessage; |
OLD | NEW |