| 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 simulates a translation process, reading the messages generated | 7 * This simulates a translation process, reading the messages generated |
| 8 * from extract_message.dart for the files sample_with_messages.dart and | 8 * from extract_message.dart for the files sample_with_messages.dart and |
| 9 * part_of_sample_with_messages.dart and writing out hard-coded translations for | 9 * part_of_sample_with_messages.dart and writing out hard-coded translations for |
| 10 * German and French locales. | 10 * German and French locales. |
| 11 */ | 11 */ |
| 12 | 12 |
| 13 import 'dart:io'; | 13 import 'dart:io'; |
| 14 import 'dart:json' as json; | 14 import 'dart:json' as json; |
| 15 import 'package:pathos/path.dart' as path; | 15 import 'package:pathos/path.dart' as path; |
| 16 import 'find_output_directory.dart'; | 16 import 'package:args/args.dart'; |
| 17 | 17 |
| 18 /** A list of the French translations that we will produce. */ | 18 /** A list of the French translations that we will produce. */ |
| 19 var french = { | 19 var french = { |
| 20 "types" : r"$a, $b, $c", | 20 "types" : r"$a, $b, $c", |
| 21 "multiLine" : "Cette message prend plusiers lignes.", | 21 "multiLine" : "Cette message prend plusiers lignes.", |
| 22 "message2" : r"Un autre message avec un seul paramètre $x", | 22 "message2" : r"Un autre message avec un seul paramètre $x", |
| 23 "alwaysTranslated" : "Cette chaîne est toujours traduit", | 23 "alwaysTranslated" : "Cette chaîne est toujours traduit", |
| 24 "message1" : "Il s'agit d'un message", | 24 "message1" : "Il s'agit d'un message", |
| 25 "leadingQuotes" : "\"Soi-disant\"", | 25 "leadingQuotes" : "\"Soi-disant\"", |
| 26 "trickyInterpolation" : r"L'interpolation est délicate " | 26 "trickyInterpolation" : r"L'interpolation est délicate " |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 file.writeAsStringSync(json.stringify(translated)); | 88 file.writeAsStringSync(json.stringify(translated)); |
| 89 } | 89 } |
| 90 | 90 |
| 91 main() { | 91 main() { |
| 92 var args = new Options().arguments; | 92 var args = new Options().arguments; |
| 93 if (args.length == 0) { | 93 if (args.length == 0) { |
| 94 print('Usage: generate_hardcoded_translation [--output-dir=<dir>] ' | 94 print('Usage: generate_hardcoded_translation [--output-dir=<dir>] ' |
| 95 '[originalFile.dart]'); | 95 '[originalFile.dart]'); |
| 96 exit(0); | 96 exit(0); |
| 97 } | 97 } |
| 98 var parser = new ArgParser(); |
| 99 parser.addOption("output-dir", defaultsTo: '.', |
| 100 callback: (value) => targetDir = value); |
| 101 parser.parse(args); |
| 98 | 102 |
| 99 targetDir = findOutputDirectory(args); | |
| 100 var fileArgs = args.where((x) => x.contains('.json')); | 103 var fileArgs = args.where((x) => x.contains('.json')); |
| 101 | 104 |
| 102 var messages = json.parse(new File(fileArgs.first).readAsStringSync()); | 105 var messages = json.parse(new File(fileArgs.first).readAsStringSync()); |
| 103 translate(messages, "fr", french); | 106 translate(messages, "fr", french); |
| 104 translate(messages, "de_DE", german); | 107 translate(messages, "de_DE", german); |
| 105 } | 108 } |
| OLD | NEW |