Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 multiLine() => Intl.message("This " | |
| 26 "string " | |
| 27 "extends " | |
| 28 "across " | |
| 29 "multiple " | |
| 30 "lines.", | |
| 31 name: "multiLine"); | |
| 32 | |
| 33 types(int a, String b, List c) => Intl.message("$a, $b, $c", name: 'types', | |
| 34 args: [a, b, c]); | |
| 35 | |
| 36 alwaysAccented() => | |
| 37 Intl.message("This string is always translated", locale: 'fr', | |
| 38 name: 'alwaysTranslated'); | |
| 39 | |
| 40 trickyInterpolation(s) => | |
| 41 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
| |
| 42 name: 'trickyInterpolation', args: [s]); | |
| 43 | |
| 44 leadingQuotes() => Intl.message("\"So-called\"", name: 'leadingQuotes'); | |
| 45 | |
| 46 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
| |
| 47 name: "originalNotInBMP"); | |
| 48 | |
| 49 notAlwaysTranslated() => Intl.message("This is missing some translations", | |
| 50 name: "notAlwaysTranslated"); | |
| 51 | |
| 52 var someString = "No, it has to be a literal string"; | |
| 53 noVariables() => Intl.message(someString, name: "noVariables"); | |
| 54 | |
| 55 escapable() => Intl.message("Escapable characters here: ", name: "escapable"); | |
| 56 | |
| 57 printStuff(Intl locale) { | |
| 58 | |
| 59 // Use a name that's not a literal so this will get skipped. Then we have | |
| 60 // a name that's not in the original but we include it in the French | |
| 61 // translation. Because it's not in the original it shouldn't get included | |
| 62 // in the generated catalog and shouldn't get translated. | |
| 63 if (locale.locale == 'fr') { | |
| 64 var badName = "thisNameIsNotInTheOriginal"; | |
| 65 var notInOriginal = Intl.message("foo", name: badName); | |
| 66 if (notInOriginal != "foo") { | |
| 67 throw "You shouldn't be able to introduce a new message in a translation"; | |
| 68 } | |
| 69 } | |
| 70 | |
| 71 var messageVariable = (a, b, c) => Intl.message( | |
| 72 "Characters that need escaping, e.g slashes \\ dollars \${ (curly braces " | |
| 73 "are ok) and xml reserved characters <& and quotes \" " | |
| 74 "parameters $a, $b, and $c", | |
| 75 name: 'message3', | |
| 76 args: [a, b, c]); | |
| 77 | |
| 78 print("-------------------------------------------"); | |
| 79 print("Printing messages for ${locale.locale}"); | |
| 80 Intl.withLocale(locale.locale, () { | |
| 81 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
| |
| 82 print(message2("hello")); | |
| 83 print(messageVariable(1,2,3)); | |
| 84 print(multiLine()); | |
| 85 print(types(1, "b", ["c", "d"])); | |
| 86 print(leadingQuotes()); | |
| 87 print(alwaysAccented()); | |
| 88 print(trickyInterpolation("this")); | |
| 89 var thing = new YouveGotMessages(); | |
| 90 print(thing.method()); | |
| 91 print(thing.nonLambda()); | |
| 92 var x = YouveGotMessages.staticMessage(); | |
| 93 print(YouveGotMessages.staticMessage()); | |
| 94 print(notAlwaysTranslated()); | |
| 95 print(originalNotInBMP()); | |
| 96 // TODO(alanknight): Support named arguments. | |
| 97 // print(thing.namedArgs(thing: 'well...')); | |
| 98 // TODO(alanknight): Support plurals. Do we need to consider changing | |
| 99 // the form so as not to have a difficult to validate interpolation | |
| 100 // in our translation output? | |
| 101 // print(thing.plurals(1)); | |
| 102 // print(thing.plurals(2)); | |
| 103 print(escapable()); | |
| 104 }); | |
| 105 } | |
| 106 | |
| 107 var localeToUse = 'en_US'; | |
| 108 | |
| 109 main() { | |
| 110 var fr = new Intl("fr"); | |
| 111 var english = new Intl("en_US"); | |
| 112 var de = new Intl("de_DE"); | |
| 113 initializeMessages(fr.locale).then((_) => printStuff(fr)); | |
| 114 initializeMessages(de.locale).then((_) => printStuff(de)); | |
| 115 printStuff(english); | |
| 116 } | |
| OLD | NEW |