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.part of sample; | |
4 | |
5 part of sample; | |
6 | |
7 class Person { | |
8 String name; | |
9 String gender; | |
10 Person(this.name, this.gender); | |
11 } | |
12 | |
13 class YouveGotMessages { | |
14 | |
15 // A static message, rather than a standalone function. | |
16 static staticMessage() => | |
17 Intl.message("This comes from a static method", name: 'staticMessage'); | |
18 | |
19 // An instance method, rather than a standalone function. | |
20 method() => Intl.message("This comes from a method", | |
21 name: 'YouveGotMessages_method', desc: 'This is a method with a ' | |
22 'long description which spans ' | |
23 'multiple lines.'); | |
24 | |
25 // A non-lambda, i.e. not using => syntax, and with an additional statement | |
26 // before the Intl.message call. | |
27 nonLambda() { | |
28 var aTrueValue = true; | |
29 var msg = Intl.message("This method is not a lambda", name: 'nonLambda'); | |
30 expect(aTrueValue, isTrue, | |
31 reason: 'Parser should not fail with additional code.'); | |
32 return msg; | |
33 } | |
34 | |
35 plurals(num) => Intl.message("""${Intl.plural(num, | |
36 zero : 'Is zero plural?', | |
37 one : 'This is singular.', | |
38 other : 'This is plural ($num).') | |
39 }""", name: "plurals", args: [num], desc: "Basic plurals"); | |
40 | |
41 whereTheyWent(Person person, String place) => | |
42 whereTheyWentMessage(person.name, person.gender, place); | |
43 | |
44 whereTheyWentMessage(String name, String gender, String place) { | |
45 return Intl.message("${Intl.gender(gender, | |
46 male: '$name went to his $place', | |
47 female: '$name went to her $place', | |
48 other: '$name went to its $place') | |
49 }", | |
50 name: "whereTheyWentMessage", | |
51 args: [name, gender, place], | |
52 desc: 'A person went to some place that they own, e.g. their room'); | |
53 } | |
54 | |
55 // English doesn't do enough with genders, so this example is French. | |
56 nested(List people, String place) { | |
57 var names = people.map((x) => x.name).join(", "); | |
58 var number = people.length; | |
59 var combinedGender = | |
60 people.every((x) => x.gender == "female") ? "female" : "other"; | |
61 if (number == 0) combinedGender = "other"; | |
62 | |
63 nestedMessage(names, number, combinedGender, place) => Intl.message( | |
64 '''${Intl.gender(combinedGender, | |
65 other: '${Intl.plural(number, | |
66 zero: "Personne n'est allé au $place", | |
67 one: "${names} est allé au $place", | |
68 other: "${names} sont allés au $place")}', | |
69 female: '${Intl.plural(number, | |
70 one: "$names est allée au $place", | |
71 other: "$names sont allées au $place")}' | |
72 )}''', | |
73 name: "nestedMessage", args: [names, number, combinedGender, place]); | |
74 return nestedMessage(names, number, combinedGender, place); | |
75 } | |
76 } | |
OLD | NEW |