| OLD | NEW |
| (Empty) | |
| 1 #!/usr/bin/env dart |
| 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 |
| 4 // BSD-style license that can be found in the LICENSE file. |
| 5 |
| 6 /** |
| 7 * This simulates a translation process, reading the messages generated |
| 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 |
| 10 * German and French locales. |
| 11 */ |
| 12 |
| 13 import 'dart:io'; |
| 14 import 'dart:json' as json; |
| 15 import 'package:pathos/path.dart' as path; |
| 16 import 'find_output_directory.dart'; |
| 17 |
| 18 /** A list of the French translations that we will produce. */ |
| 19 var french = { |
| 20 "types" : r"$a, $b, $c", |
| 21 "multiLine" : "Cette message prend plusiers lignes.", |
| 22 "message2" : r"Un autre message avec un seul paramètre $x", |
| 23 "alwaysTranslated" : "Cette chaîne est toujours traduit", |
| 24 "message1" : "Il s'agit d'un message", |
| 25 "leadingQuotes" : "\"Soi-disant\"", |
| 26 "trickyInterpolation" : r"L'interpolation est délicate " |
| 27 r"quand elle se termine une phrase comme ${s}.", |
| 28 "message3" : "Caractères qui doivent être échapper, par exemple barres \\ " |
| 29 "dollars \${ (les accolades sont ok), et xml/html réservés <& et " |
| 30 "des citations \" " |
| 31 "avec quelques paramètres ainsi \$a, \$b, et \$c", |
| 32 "method" : "Cela vient d'une méthode", |
| 33 "nonLambda" : "Cette méthode n'est pas un lambda", |
| 34 "staticMessage" : "Cela vient d'une méthode statique", |
| 35 "notAlwaysTranslated" : "Ce manque certaines traductions", |
| 36 "thisNameIsNotInTheOriginal" : "Could this lead to something malicious?", |
| 37 "originalNotInBMP" : "Anciens caractères grecs jeux du pendu: 𐅆𐅇.", |
| 38 "plural" : """Une des choses difficiles est \${Intl.plural(num, |
| 39 { |
| 40 '0' : 'la forme plurielle', |
| 41 '1' : 'la forme plurielle', |
| 42 'other' : 'des formes plurielles'})}""", |
| 43 "namedArgs" : "La chose est, \$thing", |
| 44 "escapable" : "Escapes: \n\r\f\b\t\v." |
| 45 }; |
| 46 |
| 47 /** A list of the German translations that we will produce. */ |
| 48 var german = { |
| 49 "types" : r"$a, $b, $c", |
| 50 "multiLine" : "Dieser String erstreckt sich über mehrere Zeilen erstrecken.", |
| 51 "message2" : r"Eine weitere Meldung mit dem Parameter $x", |
| 52 "alwaysTranslated" : "Diese Zeichenkette wird immer übersetzt", |
| 53 "message1" : "Dies ist eine Nachricht", |
| 54 "leadingQuotes" : "\"Sogenannt\"", |
| 55 "trickyInterpolation" : |
| 56 r"Interpolation ist schwierig, wenn es einen Satz wie dieser endet ${s}.", |
| 57 "message3" : "Zeichen, die Flucht benötigen, zB Schrägstriche \\ Dollar " |
| 58 "\${ (geschweiften Klammern sind ok) und xml reservierte Zeichen <& und " |
| 59 "Zitate \" Parameter \$a, \$b und \$c", |
| 60 "method" : "Dies ergibt sich aus einer Methode", |
| 61 "nonLambda" : "Diese Methode ist nicht eine Lambda", |
| 62 "staticMessage" : "Dies ergibt sich aus einer statischen Methode", |
| 63 "originalNotInBMP" : "Antike griechische Galgenmännchen Zeichen: 𐅆𐅇", |
| 64 "plurals" : """\${Intl.plural(num, |
| 65 { |
| 66 '0' : 'Einer der knifflige Dinge ist der Plural', |
| 67 '1' : 'Einer der knifflige Dinge ist der Plural', |
| 68 'other' : 'Zu den kniffligen Dinge Pluralformen' |
| 69 })}""", |
| 70 "namedArgs" : "Die Sache ist, \$thing", |
| 71 "escapable" : "Escapes: \n\r\f\b\t\v." |
| 72 }; |
| 73 |
| 74 /** The output directory for translated files. */ |
| 75 String targetDir; |
| 76 |
| 77 /** |
| 78 * Generate a translated json version from [originals] in [locale] looking |
| 79 * up the translations in [translations]. |
| 80 */ |
| 81 void translate(List originals, String locale, Map translations) { |
| 82 var translated = {"_locale" : locale}; |
| 83 for (var each in originals) { |
| 84 var name = each["name"]; |
| 85 translated[name] = translations[name]; |
| 86 } |
| 87 var file = new File(path.join(targetDir, 'translation_$locale.json')); |
| 88 file.writeAsStringSync(json.stringify(translated)); |
| 89 } |
| 90 |
| 91 main() { |
| 92 var args = new Options().arguments; |
| 93 if (args.length == 0) { |
| 94 print('Usage: generate_hardcoded_translation [--output-dir=<dir>] ' |
| 95 '[originalFile.dart]'); |
| 96 exit(0); |
| 97 } |
| 98 |
| 99 targetDir = findOutputDirectory(args); |
| 100 var fileArgs = args.where((x) => x.contains('.json')); |
| 101 |
| 102 var messages = json.parse(new File(fileArgs.first).readAsStringSync()); |
| 103 translate(messages, "fr", french); |
| 104 translate(messages, "de_DE", german); |
| 105 } |
| OLD | NEW |