| 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 JSON files representing translations of messages from the corresponding | 8 * of JSON files representing translations of messages from the corresponding |
| 9 * Dart file. See extract_to_json.dart and make_hardcoded_translation.dart. | 9 * Dart file. See extract_to_json.dart and make_hardcoded_translation.dart. |
| 10 * | 10 * |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 var parser = new ArgParser(); | 36 var parser = new ArgParser(); |
| 37 parser.addFlag("suppress-warnings", defaultsTo: false, | 37 parser.addFlag("suppress-warnings", defaultsTo: false, |
| 38 callback: (x) => suppressWarnings = x); | 38 callback: (x) => suppressWarnings = x); |
| 39 parser.addOption("output-dir", defaultsTo: '.', | 39 parser.addOption("output-dir", defaultsTo: '.', |
| 40 callback: (x) => targetDir = x); | 40 callback: (x) => targetDir = x); |
| 41 parser.addOption("generated-file-prefix", defaultsTo: '', | 41 parser.addOption("generated-file-prefix", defaultsTo: '', |
| 42 callback: (x) => generatedFilePrefix = x); | 42 callback: (x) => generatedFilePrefix = x); |
| 43 parser.parse(args); | 43 parser.parse(args); |
| 44 if (args.length == 0) { | 44 if (args.length == 0) { |
| 45 print('Usage: generate_from_json [--output-dir=<dir>]' | 45 print('Usage: generate_from_json [--output-dir=<dir>]' |
| 46 ' [generated-file-prefix=<prefix>] file1.dart file2.dart ...' | 46 ' [--generated-file-prefix=<prefix>] file1.dart file2.dart ...' |
| 47 ' outputFile.json'); | 47 ' translation1.json translation2.json ...'); |
| 48 exit(0); | 48 exit(0); |
| 49 } | 49 } |
| 50 | 50 |
| 51 var dartFiles = args.where((x) => x.endsWith("dart")).toList(); | 51 var dartFiles = args.where((x) => x.endsWith("dart")).toList(); |
| 52 var jsonFiles = args.where((x) => x.endsWith(".json")).toList(); | 52 var jsonFiles = args.where((x) => x.endsWith(".json")).toList(); |
| 53 | 53 |
| 54 // We're re-parsing the original files to find the corresponding messages, | 54 // We're re-parsing the original files to find the corresponding messages, |
| 55 // so if there are warnings extracting the messages, suppress them. | 55 // so if there are warnings extracting the messages, suppress them. |
| 56 suppressWarnings = true; | 56 suppressWarnings = true; |
| 57 var allMessages = dartFiles.map((each) => parseFile(new File(each))); | 57 var allMessages = dartFiles.map((each) => parseFile(new File(each))); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 BasicTranslatedMessage(String name, String translated) : | 99 BasicTranslatedMessage(String name, String translated) : |
| 100 super(name, translated); | 100 super(name, translated); |
| 101 | 101 |
| 102 IntlMessage get originalMessage => | 102 IntlMessage get originalMessage => |
| 103 (super.originalMessage == null) ? _findOriginal() : super.originalMessage; | 103 (super.originalMessage == null) ? _findOriginal() : super.originalMessage; |
| 104 | 104 |
| 105 // We know that our [id] is the name of the message, which is used as the | 105 // We know that our [id] is the name of the message, which is used as the |
| 106 //key in [messages]. | 106 //key in [messages]. |
| 107 IntlMessage _findOriginal() => originalMessage = messages[id]; | 107 IntlMessage _findOriginal() => originalMessage = messages[id]; |
| 108 } | 108 } |
| OLD | NEW |