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

Side by Side Diff: pkg/intl/test/message_extraction/sample_with_messages.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: Fixes from review comments, also made tests more robust, removed scheduled_test dependency 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 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 /**
6 * This is a program with various [Intl.message] messages. It just prints
7 * all of them, and is used for testing of message extraction, translation,
8 * and code generation.
9 */
10 library sample;
11
12 import "package:intl/intl.dart";
13 import "package:intl/message_lookup_by_library.dart";
14 import "dart:async";
15 import "package:intl/src/intl_helpers.dart";
16 import "messages_all.dart";
17
18 part 'part_of_sample_with_messages.dart';
19
20 message1() => Intl.message("This is a message", name: 'message1', desc: 'foo' );
21
22 message2(x) => Intl.message("Another message with parameter $x",
23 name: 'message2', desc: 'Description 2', args: [x]);
24
25 // A string with multiple adjacent strings concatenated together, verify
26 // that the parser handles this properly.
27 multiLine() => Intl.message("This "
28 "string "
29 "extends "
30 "across "
31 "multiple "
32 "lines.",
33 name: "multiLine");
34
35 // Have types on the enclosing function's arguments.
36 types(int a, String b, List c) => Intl.message("$a, $b, $c", name: 'types',
37 args: [a, b, c]);
38
39 // This string will be printed with a French locale, so it will always show
40 // up in the French version, regardless of the current locale.
41 alwaysAccented() =>
42 Intl.message("This string is always translated", locale: 'fr',
43 name: 'alwaysTranslated');
44
45 // Test interpolation with curly braces around the expression, but it must
46 // still be just a variable reference.
47 trickyInterpolation(s) =>
48 Intl.message("Interpolation is tricky when it ends a sentence like ${s}.",
49 name: 'trickyInterpolation', args: [s]);
50
51 leadingQuotes() => Intl.message("\"So-called\"", name: 'leadingQuotes');
52
53 // A message with characters not in the basic multilingual plane.
54 originalNotInBMP() => Intl.message("Ancient Greek hangman characters: 𐅆𐅇.",
55 name: "originalNotInBMP");
56
57 // A string for which we don't provide all translations.
58 notAlwaysTranslated() => Intl.message("This is missing some translations",
59 name: "notAlwaysTranslated");
60
61 // This is invalid and should be recognized as such, because the message has
62 // to be a literal. Otherwise, interpolations would be outside of the function
63 // scope.
64 var someString = "No, it has to be a literal string";
65 noVariables() => Intl.message(someString, name: "noVariables");
66
67 // This is unremarkable in English, but the translated versions will contain
68 // characters that ought to be escaped during code generation.
69 escapable() => Intl.message("Escapable characters here: ", name: "escapable");
70
71 printStuff(Intl locale) {
72
73 // Use a name that's not a literal so this will get skipped. Then we have
74 // a name that's not in the original but we include it in the French
75 // translation. Because it's not in the original it shouldn't get included
76 // in the generated catalog and shouldn't get translated.
77 if (locale.locale == 'fr') {
78 var badName = "thisNameIsNotInTheOriginal";
79 var notInOriginal = Intl.message("foo", name: badName);
80 if (notInOriginal != "foo") {
81 throw "You shouldn't be able to introduce a new message in a translation";
82 }
83 }
84
85 // A function that is unnamed and assigned to a variable. It's also nested
86 // within another function definition.
87 var messageVariable = (a, b, c) => Intl.message(
88 "Characters that need escaping, e.g slashes \\ dollars \${ (curly braces "
89 "are ok) and xml reserved characters <& and quotes \" "
90 "parameters $a, $b, and $c",
91 name: 'message3',
92 args: [a, b, c]);
93
94 print("-------------------------------------------");
95 print("Printing messages for ${locale.locale}");
96 Intl.withLocale(locale.locale, () {
97 print(message1());
98 print(message2("hello"));
99 print(messageVariable(1,2,3));
100 print(multiLine());
101 print(types(1, "b", ["c", "d"]));
102 print(leadingQuotes());
103 print(alwaysAccented());
104 print(trickyInterpolation("this"));
105 var thing = new YouveGotMessages();
106 print(thing.method());
107 print(thing.nonLambda());
108 var x = YouveGotMessages.staticMessage();
109 print(YouveGotMessages.staticMessage());
110 print(notAlwaysTranslated());
111 print(originalNotInBMP());
112 // TODO(alanknight): Support named arguments.
113 // print(thing.namedArgs(thing: 'well...'));
114 // TODO(alanknight): Support plurals. Do we need to consider changing
115 // the form so as not to have a difficult to validate interpolation
116 // in our translation output?
117 // print(thing.plurals(1));
118 // print(thing.plurals(2));
119 print(escapable());
120 });
121 }
122
123 var localeToUse = 'en_US';
124
125 main() {
126 var fr = new Intl("fr");
127 var english = new Intl("en_US");
128 var de = new Intl("de_DE");
129 initializeMessages(fr.locale).then((_) => printStuff(fr));
130 initializeMessages(de.locale).then((_) => printStuff(de));
131 printStuff(english);
132 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698