Chromium Code Reviews| Index: pkg/intl/test/message_extraction/make_hardcoded_translation.dart |
| diff --git a/pkg/intl/test/message_extraction/make_hardcoded_translation.dart b/pkg/intl/test/message_extraction/make_hardcoded_translation.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..c889855ee7a3fb11210e7bf5ea882c691c85436b |
| --- /dev/null |
| +++ b/pkg/intl/test/message_extraction/make_hardcoded_translation.dart |
| @@ -0,0 +1,99 @@ |
| +#!/usr/bin/env dart |
| +// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| +// for details. All rights reserved. Use of this source code is governed by a |
| +// BSD-style license that can be found in the LICENSE file. |
| + |
| +/** |
| + * This simulates a translation process, reading the messages generated |
| + * from extract_message.dart for the files sample_with_messages.dart and |
| + * part_of_sample_with_messages.dart and writing out hard-coded translations for |
| + * German and French locales. |
| + */ |
| + |
| +import 'dart:io'; |
| +import 'dart:json' as json; |
| +import 'package:pathos/path.dart' as path; |
| + |
| +/** A list of the French translations that we will produce. */ |
| +var french = { |
| + "types" : r"$a, $b, $c", |
| + "multiLine" : "Cette message prend plusiers lignes.", |
| + "message2" : r"Un autre message avec un seul paramètre $x", |
| + "alwaysTranslated" : "Cette chaîne est toujours traduit", |
| + "message1" : "Il s'agit d'un message", |
| + "leadingQuotes" : "\"Soi-disant\"", |
| + "trickyInterpolation" : |
| + r"L'interpolation est délicate quand elle se termine une phrase comme ${s}.", |
|
Emily Fortuna
2013/03/13 18:54:43
80 char
Alan Knight
2013/03/14 17:49:05
Done.
|
| + "message3" : "Caractères qui doivent être échapper, par exemple barres \\ " |
| + "dollars \${ (les accolades sont ok), et xml/html réservés <& et " |
| + "des citations \" " |
| + "avec quelques paramètres ainsi \$a, \$b, et \$c", |
| + "method" : "Cela vient d'une méthode", |
| + "nonLambda" : "Cette méthode n'est pas un lambda", |
| + "staticMessage" : "Cela vient d'une méthode statique", |
| + "notAlwaysTranslated" : "Ce manque certaines traductions", |
| + "thisNameIsNotInTheOriginal" : "Could this lead to something malicious?", |
| + "originalNotInBMP" : "Anciens caractères grecs jeux du pendu: 𐅆𐅇.", |
| + "plural" : """Une des choses difficiles est \${Intl.plural(num, |
| + { |
| + '0' : 'la forme plurielle', |
| + '1' : 'la forme plurielle', |
| + 'other' : 'des formes plurielles'})}""", |
| + "namedArgs" : "La chose est, \$thing", |
| + "escapable" : "Escapes: \n\r\f\b\t\v." |
| +}; |
| + |
| +/** A list of the German translations that we will produce. */ |
| +var german = { |
| + "types" : r"$a, $b, $c", |
| + "multiLine" : "Dieser String erstreckt sich über mehrere Zeilen erstrecken.", |
| + "message2" : r"Eine weitere Meldung mit dem Parameter $x", |
| + "alwaysTranslated" : "Diese Zeichenkette wird immer übersetzt", |
| + "message1" : "Dies ist eine Nachricht", |
| + "leadingQuotes" : "\"Sogenannt\"", |
| + "trickyInterpolation" : |
| + r"Interpolation ist schwierig, wenn es einen Satz wie dieser endet ${s}.", |
| + "message3" : "Zeichen, die Flucht benötigen, zB Schrägstriche \\ Dollar " |
| + "\${ (geschweiften Klammern sind ok) und xml reservierte Zeichen <& und " |
| + "Zitate \" Parameter \$a, \$b und \$c", |
| + "method" : "Dies ergibt sich aus einer Methode", |
| + "nonLambda" : "Diese Methode ist nicht eine Lambda", |
| + "staticMessage" : "Dies ergibt sich aus einer statischen Methode", |
| + "originalNotInBMP" : "Antike griechische Galgenmännchen Zeichen: 𐅆𐅇", |
| + "plurals" : """\${Intl.plural(num, |
| + { |
| + '0' : 'Einer der knifflige Dinge ist der Plural', |
| + '1' : 'Einer der knifflige Dinge ist der Plural', |
| + 'other' : 'Zu den kniffligen Dinge Pluralformen' |
| + })}""", |
| + "namedArgs" : "Die Sache ist, \$thing", |
| + "escapable" : "Escapes: \n\r\f\b\t\v." |
| +}; |
| + |
| +/** |
| + * Generate a translated json version from [originals] in [locale] looking |
| + * up the translations in [translations]. |
| + */ |
| +translate(List originals, String locale, Map translations) { |
| + var translated = {"_locale" : locale}; |
| + for (var each in originals) { |
| + var name = each["name"]; |
| + translated[name] = translations[name]; |
| + } |
| + ifNull(x, y) => (x == null) ? y : x; |
| + var target = ifNull(Platform.environment["INTL_MESSAGE_OUTPUT"], '.'); |
| + var file = new File(path.join(target, 'translation_$locale.json')); |
| + file.writeAsStringSync(json.stringify(translated)); |
| +} |
| + |
| +main() { |
| + var args = new Options().arguments; |
| + if (args.length == 0) { |
| + print('Usage: generate_hardcoded_translation [originalFile.dart]'); |
| + exit(0); |
| + } |
| + |
| + var messages = json.parse(new File(args.first).readAsStringSync()); |
| + translate(messages, "fr", french); |
| + translate(messages, "de_DE", german); |
| +} |