Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(63)

Side by Side Diff: pkg/intl/test/message_extraction/make_hardcoded_translation.dart

Issue 12733003: Adds facilities for extracting Intl.message calls and generating code from translations (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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
17 /** A list of the French translations that we will produce. */
18 var french = {
19 "types" : r"$a, $b, $c",
20 "multiLine" : "Cette message prend plusiers lignes.",
21 "message2" : r"Un autre message avec un seul paramètre $x",
22 "alwaysTranslated" : "Cette chaîne est toujours traduit",
23 "message1" : "Il s'agit d'un message",
24 "leadingQuotes" : "\"Soi-disant\"",
25 "trickyInterpolation" :
26 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.
27 "message3" : "Caractères qui doivent être échapper, par exemple barres \\ "
28 "dollars \${ (les accolades sont ok), et xml/html réservés <& et "
29 "des citations \" "
30 "avec quelques paramètres ainsi \$a, \$b, et \$c",
31 "method" : "Cela vient d'une méthode",
32 "nonLambda" : "Cette méthode n'est pas un lambda",
33 "staticMessage" : "Cela vient d'une méthode statique",
34 "notAlwaysTranslated" : "Ce manque certaines traductions",
35 "thisNameIsNotInTheOriginal" : "Could this lead to something malicious?",
36 "originalNotInBMP" : "Anciens caractères grecs jeux du pendu: 𐅆𐅇.",
37 "plural" : """Une des choses difficiles est \${Intl.plural(num,
38 {
39 '0' : 'la forme plurielle',
40 '1' : 'la forme plurielle',
41 'other' : 'des formes plurielles'})}""",
42 "namedArgs" : "La chose est, \$thing",
43 "escapable" : "Escapes: \n\r\f\b\t\v."
44 };
45
46 /** A list of the German translations that we will produce. */
47 var german = {
48 "types" : r"$a, $b, $c",
49 "multiLine" : "Dieser String erstreckt sich über mehrere Zeilen erstrecken.",
50 "message2" : r"Eine weitere Meldung mit dem Parameter $x",
51 "alwaysTranslated" : "Diese Zeichenkette wird immer übersetzt",
52 "message1" : "Dies ist eine Nachricht",
53 "leadingQuotes" : "\"Sogenannt\"",
54 "trickyInterpolation" :
55 r"Interpolation ist schwierig, wenn es einen Satz wie dieser endet ${s}.",
56 "message3" : "Zeichen, die Flucht benötigen, zB Schrägstriche \\ Dollar "
57 "\${ (geschweiften Klammern sind ok) und xml reservierte Zeichen <& und "
58 "Zitate \" Parameter \$a, \$b und \$c",
59 "method" : "Dies ergibt sich aus einer Methode",
60 "nonLambda" : "Diese Methode ist nicht eine Lambda",
61 "staticMessage" : "Dies ergibt sich aus einer statischen Methode",
62 "originalNotInBMP" : "Antike griechische Galgenmännchen Zeichen: 𐅆𐅇",
63 "plurals" : """\${Intl.plural(num,
64 {
65 '0' : 'Einer der knifflige Dinge ist der Plural',
66 '1' : 'Einer der knifflige Dinge ist der Plural',
67 'other' : 'Zu den kniffligen Dinge Pluralformen'
68 })}""",
69 "namedArgs" : "Die Sache ist, \$thing",
70 "escapable" : "Escapes: \n\r\f\b\t\v."
71 };
72
73 /**
74 * Generate a translated json version from [originals] in [locale] looking
75 * up the translations in [translations].
76 */
77 translate(List originals, String locale, Map translations) {
78 var translated = {"_locale" : locale};
79 for (var each in originals) {
80 var name = each["name"];
81 translated[name] = translations[name];
82 }
83 ifNull(x, y) => (x == null) ? y : x;
84 var target = ifNull(Platform.environment["INTL_MESSAGE_OUTPUT"], '.');
85 var file = new File(path.join(target, 'translation_$locale.json'));
86 file.writeAsStringSync(json.stringify(translated));
87 }
88
89 main() {
90 var args = new Options().arguments;
91 if (args.length == 0) {
92 print('Usage: generate_hardcoded_translation [originalFile.dart]');
93 exit(0);
94 }
95
96 var messages = json.parse(new File(args.first).readAsStringSync());
97 translate(messages, "fr", french);
98 translate(messages, "de_DE", german);
99 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698