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:convert'; |
| 14 import 'dart:io'; |
| 15 import 'package:path/path.dart' as path; |
| 16 import 'package:args/args.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 "YouveGotMessages_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 "escapable": "Escapes: \n\r\f\b\t\v.", |
| 39 "sameContentsDifferentName": "Bonjour tout le monde", |
| 40 "differentNameSameContents": "Bonjour tout le monde", |
| 41 "rentToBePaid": "loyer", |
| 42 "rentAsVerb": "louer", |
| 43 "plurals": "{num,plural, =0{Est-ce que nulle est pluriel?}=1{C'est singulier}" |
| 44 "other{C'est pluriel ({num}).}}", |
| 45 "whereTheyWentMessage": "{gender,select, male{{name} est allé à sa {place}}" |
| 46 "female{{name} est allée à sa {place}}other{{name}" |
| 47 " est allé à sa {place}}}", |
| 48 // Gratuitously different translation for testing. Ignoring gender of place. |
| 49 "nestedMessage": "{combinedGender,select, " |
| 50 "other{" |
| 51 "{number,plural, " |
| 52 "=0{Personne n'avait allé à la {place}}" |
| 53 "=1{{names} était allé à la {place}}" |
| 54 "other{{names} étaient allés à la {place}}" |
| 55 "}" |
| 56 "}" |
| 57 "female{" |
| 58 "{number,plural, " |
| 59 "=1{{names} était allée à la {place}}" |
| 60 "other{{names} étaient allées à la {place}}" |
| 61 "}" |
| 62 "}" |
| 63 "}", |
| 64 "outerPlural": "{n,plural, =0{rien}=1{un}other{quelques-uns}}", |
| 65 "outerGender": "{g,select, male {homme} female {femme} other {autre}}", |
| 66 "pluralThatFailsParsing": "{noOfThings,plural, " |
| 67 "=1{1 chose:}other{{noOfThings} choses:}}", |
| 68 "nestedOuter": "{number,plural, other{" |
| 69 "{gen,select, male{{number} homme}other{{number} autre}}}}", |
| 70 "outerSelect": "{currency,select, CDN{{amount} dollars Canadiens}" |
| 71 "other{{amount} certaine devise ou autre.}}}", |
| 72 "nestedSelect": "{currency,select, CDN{{amount,plural, " |
| 73 "=1{{amount} dollar Canadien}" |
| 74 "other{{amount} dollars Canadiens}}}" |
| 75 "other{N'importe quoi}" |
| 76 "}}" |
| 77 }; |
| 78 |
| 79 /** A list of the German translations that we will produce. */ |
| 80 var german = { |
| 81 "types": r"{a}, {b}, {c}", |
| 82 "multiLine": "Dieser String erstreckt sich über mehrere Zeilen erstrecken.", |
| 83 "message2": r"Eine weitere Meldung mit dem Parameter {x}", |
| 84 "alwaysTranslated": "Diese Zeichenkette wird immer übersetzt", |
| 85 "message1": "Dies ist eine Nachricht", |
| 86 "leadingQuotes": "\"Sogenannt\"", |
| 87 "trickyInterpolation": r"Interpolation ist schwierig, wenn es einen Satz " |
| 88 "wie dieser endet {s}.", |
| 89 "message3": "Zeichen, die Flucht benötigen, zB Schrägstriche \\ Dollar " |
| 90 "\${ (geschweiften Klammern sind ok) und xml reservierte Zeichen <& und " |
| 91 "Zitate \" Parameter {a}, {b} und {c}", |
| 92 "YouveGotMessages_method": "Dies ergibt sich aus einer Methode", |
| 93 "nonLambda": "Diese Methode ist nicht eine Lambda", |
| 94 "staticMessage": "Dies ergibt sich aus einer statischen Methode", |
| 95 "thisNameIsNotInTheOriginal": "Could this lead to something malicious?", |
| 96 "originalNotInBMP": "Antike griechische Galgenmännchen Zeichen: 𐅆𐅇", |
| 97 "escapable": "Escapes: \n\r\f\b\t\v.", |
| 98 "sameContentsDifferentName": "Hallo Welt", |
| 99 "differentNameSameContents": "Hallo Welt", |
| 100 "rentToBePaid": "Miete", |
| 101 "rentAsVerb": "mieten", |
| 102 "plurals": "{num,plural, =0{Ist Null Plural?}=1{Dies ist einmalig}" |
| 103 "other{Dies ist Plural ({num}).}}", |
| 104 "whereTheyWentMessage": "{gender,select, male{{name} ging zu seinem {place}}" |
| 105 "female{{name} ging zu ihrem {place}}other{{name} ging zu seinem {place}}}
", |
| 106 //Note that we're only using the gender of the people. The gender of the |
| 107 //place also matters, but we're not dealing with that here. |
| 108 "nestedMessage": "{combinedGender,select, " |
| 109 "other{" |
| 110 "{number,plural, " |
| 111 "=0{Niemand ging zu {place}}" |
| 112 "=1{{names} ging zum {place}}" |
| 113 "other{{names} gingen zum {place}}" |
| 114 "}" |
| 115 "}" |
| 116 "female{" |
| 117 "{number,plural, " |
| 118 "=1{{names} ging in dem {place}}" |
| 119 "other{{names} gingen zum {place}}" |
| 120 "}" |
| 121 "}" |
| 122 "}", |
| 123 "outerPlural": "{n,plural, =0{Null}=1{ein}other{einige}}", |
| 124 "outerGender": "{g,select, male{Mann}female{Frau}other{andere}}", |
| 125 "pluralThatFailsParsing": "{noOfThings,plural, " |
| 126 "=1{eins:}other{{noOfThings} Dinge:}}", |
| 127 "nestedOuter": "{number,plural, other{" |
| 128 "{gen,select, male{{number} Mann}other{{number} andere}}}}", |
| 129 "outerSelect": "{currency,select, CDN{{amount} Kanadischen dollar}" |
| 130 "other{{amount} einige Währung oder anderen.}}}", |
| 131 "nestedSelect": "{currency,select, CDN{{amount,plural, " |
| 132 "=1{{amount} Kanadischer dollar}" |
| 133 "other{{amount} Kanadischen dollar}}}" |
| 134 "other{whatever}" |
| 135 "}" |
| 136 }; |
| 137 |
| 138 /** The output directory for translated files. */ |
| 139 String targetDir; |
| 140 |
| 141 /** |
| 142 * Generate a translated json version from [originals] in [locale] looking |
| 143 * up the translations in [translations]. |
| 144 */ |
| 145 void translate(Map originals, String locale, Map translations) { |
| 146 var translated = {"_locale": locale}; |
| 147 originals.forEach((name, text) { |
| 148 translated[name] = translations[name]; |
| 149 }); |
| 150 var file = new File(path.join(targetDir, 'translation_$locale.arb')); |
| 151 file.writeAsStringSync(JSON.encode(translated)); |
| 152 } |
| 153 |
| 154 main(List<String> args) { |
| 155 if (args.length == 0) { |
| 156 print('Usage: make_hardcoded_translation [--output-dir=<dir>] ' |
| 157 '[originalFile.arb]'); |
| 158 exit(0); |
| 159 } |
| 160 var parser = new ArgParser(); |
| 161 parser.addOption("output-dir", |
| 162 defaultsTo: '.', callback: (value) => targetDir = value); |
| 163 parser.parse(args); |
| 164 |
| 165 var fileArgs = args.where((x) => x.contains('.arb')); |
| 166 |
| 167 var messages = JSON.decode(new File(fileArgs.first).readAsStringSync()); |
| 168 translate(messages, "fr", french); |
| 169 translate(messages, "de_DE", german); |
| 170 } |
OLD | NEW |