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

Unified 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: 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 side-by-side diff with in-line comments
Download patch
Index: pkg/intl/test/message_extraction/sample_with_messages.dart
diff --git a/pkg/intl/test/message_extraction/sample_with_messages.dart b/pkg/intl/test/message_extraction/sample_with_messages.dart
new file mode 100644
index 0000000000000000000000000000000000000000..b6eb0b3ebf207c1c9f0174a097a730c779574fc9
--- /dev/null
+++ b/pkg/intl/test/message_extraction/sample_with_messages.dart
@@ -0,0 +1,116 @@
+// 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 is a program with various [Intl.message] messages. It just prints
+ * all of them, and is used for testing of message extraction, translation,
+ * and code generation.
+ */
+library sample;
+
+import "package:intl/intl.dart";
+import "package:intl/message_lookup_by_library.dart";
+import "dart:async";
+import "package:intl/src/intl_helpers.dart";
+import "messages_all.dart";
+
+part 'part_of_sample_with_messages.dart';
+
+message1() => Intl.message("This is a message", name: 'message1', desc: 'foo' );
+
+message2(x) => Intl.message("Another message with parameter $x",
+ name: 'message2', desc: 'Description 2', args: [x]);
+
+multiLine() => Intl.message("This "
+ "string "
+ "extends "
+ "across "
+ "multiple "
+ "lines.",
+ name: "multiLine");
+
+types(int a, String b, List c) => Intl.message("$a, $b, $c", name: 'types',
+ args: [a, b, c]);
+
+alwaysAccented() =>
+ Intl.message("This string is always translated", locale: 'fr',
+ name: 'alwaysTranslated');
+
+trickyInterpolation(s) =>
+ Intl.message("Interpolation is tricky when it ends a sentence like ${s}.",
Emily Fortuna 2013/03/13 18:54:43 how is this different from message2?
Alan Knight 2013/03/14 17:49:05 The interpolation is ${s} rather than just $x and
+ name: 'trickyInterpolation', args: [s]);
+
+leadingQuotes() => Intl.message("\"So-called\"", name: 'leadingQuotes');
+
+originalNotInBMP() => Intl.message("Ancient Greek hangman characters: 𐅆𐅇.",
Emily Fortuna 2013/03/13 18:54:43 bmp?
Alan Knight 2013/03/14 17:49:05 Basic Multilingual Plane. Characters that fit in U
+ name: "originalNotInBMP");
+
+notAlwaysTranslated() => Intl.message("This is missing some translations",
+ name: "notAlwaysTranslated");
+
+var someString = "No, it has to be a literal string";
+noVariables() => Intl.message(someString, name: "noVariables");
+
+escapable() => Intl.message("Escapable characters here: ", name: "escapable");
+
+printStuff(Intl locale) {
+
+ // Use a name that's not a literal so this will get skipped. Then we have
+ // a name that's not in the original but we include it in the French
+ // translation. Because it's not in the original it shouldn't get included
+ // in the generated catalog and shouldn't get translated.
+ if (locale.locale == 'fr') {
+ var badName = "thisNameIsNotInTheOriginal";
+ var notInOriginal = Intl.message("foo", name: badName);
+ if (notInOriginal != "foo") {
+ throw "You shouldn't be able to introduce a new message in a translation";
+ }
+ }
+
+ var messageVariable = (a, b, c) => Intl.message(
+ "Characters that need escaping, e.g slashes \\ dollars \${ (curly braces "
+ "are ok) and xml reserved characters <& and quotes \" "
+ "parameters $a, $b, and $c",
+ name: 'message3',
+ args: [a, b, c]);
+
+ print("-------------------------------------------");
+ print("Printing messages for ${locale.locale}");
+ Intl.withLocale(locale.locale, () {
+ print(message1());
Emily Fortuna 2013/03/13 18:54:43 why print here instead of using expect?
Alan Knight 2013/03/14 17:49:05 I can't directly expect a constant here, because i
+ print(message2("hello"));
+ print(messageVariable(1,2,3));
+ print(multiLine());
+ print(types(1, "b", ["c", "d"]));
+ print(leadingQuotes());
+ print(alwaysAccented());
+ print(trickyInterpolation("this"));
+ var thing = new YouveGotMessages();
+ print(thing.method());
+ print(thing.nonLambda());
+ var x = YouveGotMessages.staticMessage();
+ print(YouveGotMessages.staticMessage());
+ print(notAlwaysTranslated());
+ print(originalNotInBMP());
+ // TODO(alanknight): Support named arguments.
+// print(thing.namedArgs(thing: 'well...'));
+ // TODO(alanknight): Support plurals. Do we need to consider changing
+ // the form so as not to have a difficult to validate interpolation
+ // in our translation output?
+// print(thing.plurals(1));
+// print(thing.plurals(2));
+ print(escapable());
+ });
+}
+
+var localeToUse = 'en_US';
+
+main() {
+ var fr = new Intl("fr");
+ var english = new Intl("en_US");
+ var de = new Intl("de_DE");
+ initializeMessages(fr.locale).then((_) => printStuff(fr));
+ initializeMessages(de.locale).then((_) => printStuff(de));
+ printStuff(english);
+}

Powered by Google App Engine
This is Rietveld 408576698