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

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

Issue 18543009: Plurals and Genders (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix typo Created 7 years, 5 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
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 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 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; 3 // BSD-style license that can be found in the LICENSE file.part of sample;
4 4
5 part of sample; 5 part of sample;
6 6
7 class Person {
8 String name;
9 String gender;
10 Person(this.name, this.gender);
11 }
12
7 class YouveGotMessages { 13 class YouveGotMessages {
8 14
9 // A static message, rather than a standalone function. 15 // A static message, rather than a standalone function.
10 static staticMessage() => Intl.message("This comes from a static method", 16 static staticMessage() => Intl.message("This comes from a static method",
11 name: 'staticMessage'); 17 name: 'staticMessage');
12 18
13 // An instance method, rather than a standalone function. 19 // An instance method, rather than a standalone function.
14 method() => Intl.message("This comes from a method", name: 'method'); 20 method() => Intl.message("This comes from a method", name: 'method');
15 21
16 // A non-lambda, i.e. not using => syntax, and with an additional statement 22 // A non-lambda, i.e. not using => syntax, and with an additional statement
17 // before the Intl.message call. 23 // before the Intl.message call.
18 nonLambda() { 24 nonLambda() {
19 // TODO(alanknight): I'm really not sure that this shouldn't be disallowed. 25 // TODO(alanknight): I'm really not sure that this shouldn't be disallowed.
20 var x = 'something'; 26 var x = 'something';
21 return Intl.message("This method is not a lambda", name: 'nonLambda'); 27 return Intl.message("This method is not a lambda", name: 'nonLambda');
22 } 28 }
23 29
24 // TODO(alanknight): Support plurals and named arguments. 30 plurals(num) => Intl.message("""${Intl.plural(num,
25 // plurals(num) => Intl.message(""" 31 zero : 'Is zero plural?',
26 //One of the tricky things is ${Intl.plural(num, 32 one : 'This is singular.',
27 // { 33 other : 'This is plural ($num).')
28 // '0' : 'the plural form', 34 }""",
29 // '1' : 'the plural form', 35 name: "plurals", args: [num], desc: "Basic plurals");
30 // 'other' : 'plural forms'})}""", 36
31 // name: "plurals"); 37 whereTheyWent(Person person, String place) =>
32 // 38 whereTheyWentMessage(person.name, person.gender, place);
33 //namedArgs({thing}) => Intl.message("The thing is, $thing", name: "namedArgs"); 39
34 } 40 whereTheyWentMessage(String name, String gender, String place) {
41 return Intl.message(
42 "${Intl.gender(gender,
43 male: '$name went to his $place',
44 female: '$name went to her $place',
45 other: '$name went to its $place')
46 }",
47 name: "whereTheyWent",
48 args: [name, gender, place],
49 desc: 'A person went to some place that they own, e.g. their room'
50 );
51 }
52
53 // English doesn't do enough with genders, and pseudo-localization doesn't
54 // do anything with them, so this example is French.
55 nested(List people, String place) {
56 var names = people.map((x) => x.name).join(", ");
57 var number = people.length;
58 var combinedGender = people.every(
59 (x) => x.gender == "female") ? "female" : "other";
60 if (number == 0) combinedGender = "other";
61
62 nestedMessage(names, number, combinedGender, place) => Intl.message(
63 '''${Intl.gender(combinedGender,
64 other: '${Intl.plural(number,
65 zero: "Personne n'est allé au $place",
66 one: "${names} est allé au $place",
67 other: "${names} sont allés au $place")}',
68 female: '${Intl.plural(number,
69 one: "$names est allée au $place",
70 other: "$names sont allées au $place")}'
71 )}''',
72 name: "nestedMessage",
73 args: [names, number, combinedGender, place]);
74 return nestedMessage(names, number, combinedGender, place);
75 }
76 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698