| OLD | NEW |
| 1 #!/usr/bin/env dart | 1 #!/usr/bin/env dart |
| 2 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 2 // Copyright (c) 2014, 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 ARB format output. See | 8 * calls in the target dart files and produces ARB format output. See |
| 9 * https://code.google.com/p/arb/wiki/ApplicationResourceBundleSpecification | 9 * https://code.google.com/p/arb/wiki/ApplicationResourceBundleSpecification |
| 10 */ | 10 */ |
| 11 library extract_to_arb; | 11 library extract_to_arb; |
| 12 | 12 |
| 13 import 'dart:convert'; | 13 import 'dart:convert'; |
| 14 import 'dart:io'; | 14 import 'dart:io'; |
| 15 import 'package:intl/extract_messages.dart'; | 15 import 'package:intl/extract_messages.dart'; |
| 16 import 'package:path/path.dart' as path; | 16 import 'package:path/path.dart' as path; |
| 17 import 'package:intl/src/intl_message.dart'; | 17 import 'package:intl/src/intl_message.dart'; |
| 18 import 'package:args/args.dart'; | 18 import 'package:args/args.dart'; |
| 19 | 19 |
| 20 main(List<String> args) { | 20 main(List<String> args) { |
| 21 var targetDir; | 21 var targetDir; |
| 22 var parser = new ArgParser(); | 22 var parser = new ArgParser(); |
| 23 parser.addFlag("suppress-warnings", defaultsTo: false, callback: (x) => | 23 parser.addFlag("suppress-warnings", defaultsTo: false, callback: (x) => |
| 24 suppressWarnings = x); | 24 suppressWarnings = x, help: 'Suppress printing of warnings.'); |
| 25 parser.addFlag("warnings-are-errors", defaultsTo: false, callback: (x) => | 25 parser.addFlag("warnings-are-errors", defaultsTo: false, callback: (x) => |
| 26 warningsAreErrors = x); | 26 warningsAreErrors = x, |
| 27 help: 'Treat all warnings as errors, stop processing '); |
| 28 parser.addFlag("embedded-plurals", defaultsTo: true, |
| 29 callback: (x) => allowEmbeddedPluralsAndGenders = x, |
| 30 help: 'Allow plurals and genders to be embedded as part of a larger ' |
| 31 'string, otherwise they must be at the top level.'); |
| 27 | 32 |
| 28 parser.addOption("output-dir", defaultsTo: '.', callback: (value) => targetDir | 33 parser.addOption("output-dir", defaultsTo: '.', callback: (value) => targetDir |
| 29 = value); | 34 = value, help: 'Specify the output directory.'); |
| 30 parser.parse(args); | 35 parser.parse(args); |
| 31 if (args.length == 0) { | 36 if (args.length == 0) { |
| 32 print('Usage: extract_to_arb [--output-dir=<dir>] [files.dart]'); | |
| 33 print('Accepts Dart files and produces intl_messages.json'); | 37 print('Accepts Dart files and produces intl_messages.json'); |
| 38 print('Usage: extract_to_arb [options] [files.dart]'); |
| 39 print(parser.getUsage()); |
| 34 exit(0); | 40 exit(0); |
| 35 } | 41 } |
| 36 var allMessages = {}; | 42 var allMessages = {}; |
| 37 for (var arg in args.where((x) => x.contains(".dart"))) { | 43 for (var arg in args.where((x) => x.contains(".dart"))) { |
| 38 var messages = parseFile(new File(arg)); | 44 var messages = parseFile(new File(arg)); |
| 39 messages.forEach((k, v) => allMessages.addAll(toARB(v))); | 45 messages.forEach((k, v) => allMessages.addAll(toARB(v))); |
| 40 } | 46 } |
| 41 var file = new File(path.join(targetDir, 'intl_messages.arb')); | 47 var file = new File(path.join(targetDir, 'intl_messages.arb')); |
| 42 file.writeAsStringSync(JSON.encode(allMessages)); | 48 file.writeAsStringSync(JSON.encode(allMessages)); |
| 43 if (hasWarnings && warningsAreErrors) { | 49 if (hasWarnings && warningsAreErrors) { |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 if (chunk is Message) { | 120 if (chunk is Message) { |
| 115 return chunk.expanded((message, chunk) => turnInterpolationIntoICUForm( | 121 return chunk.expanded((message, chunk) => turnInterpolationIntoICUForm( |
| 116 message, chunk, shouldEscapeICU: shouldEscapeICU)); | 122 message, chunk, shouldEscapeICU: shouldEscapeICU)); |
| 117 } | 123 } |
| 118 throw new FormatException("Illegal interpolation: $chunk"); | 124 throw new FormatException("Illegal interpolation: $chunk"); |
| 119 } | 125 } |
| 120 | 126 |
| 121 String escape(String s) { | 127 String escape(String s) { |
| 122 return s.replaceAll("'", "''").replaceAll("{", "'{'").replaceAll("}", "'}'"); | 128 return s.replaceAll("'", "''").replaceAll("{", "'{'").replaceAll("}", "'}'"); |
| 123 } | 129 } |
| OLD | NEW |