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

Side by Side Diff: pkg/intl/lib/intl.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
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 /** 5 /**
6 * This library provides internationalization and localization. This includes 6 * This library provides internationalization and localization. This includes
7 * message formatting and replacement, date and number formatting and parsing, 7 * message formatting and replacement, date and number formatting and parsing,
8 * and utilities for working with Bidirectional text. 8 * and utilities for working with Bidirectional text.
9 * 9 *
10 * For things that require locale or other data, there are multiple different 10 * For things that require locale or other data, there are multiple different
(...skipping 25 matching lines...) Expand all
36 * 36 *
37 * Message example: 37 * Message example:
38 * '''I see ${Intl.plural(num_people, 38 * '''I see ${Intl.plural(num_people,
39 * {'0': 'no one at all', 39 * {'0': 'no one at all',
40 * '1': 'one other person', 40 * '1': 'one other person',
41 * 'other': '$num_people other people'})} in $place.'''' 41 * 'other': '$num_people other people'})} in $place.''''
42 * 42 *
43 * Usage examples: 43 * Usage examples:
44 * today(date) => Intl.message( 44 * today(date) => Intl.message(
45 * "Today's date is $date", 45 * "Today's date is $date",
46 * name: 'today',
47 * args: [date],
46 * desc: 'Indicate the current date', 48 * desc: 'Indicate the current date',
47 * examples: {'date' : 'June 8, 2012'}); 49 * examples: {'date' : 'June 8, 2012'});
48 * print(today(new DateTime.now()); 50 * print(today(new DateTime.now());
49 * 51 *
50 * msg({num_people, place}) => Intl.message( 52 * msg(num_people, place) => Intl.message(
51 * '''I see ${Intl.plural(num_people, 53 * '''I see ${Intl.plural(num_people,
52 * {'0': 'no one at all', 54 * {'0': 'no one at all',
53 * '1': 'one other person', 55 * '1': 'one other person',
54 * 'other': '$num_people other people'})} in $place.'''', 56 * 'other': '$num_people other people'})} in $place.'''',
57 * name: 'msg',
58 * args: [num_people, place],
55 * desc: 'Description of how many people are seen as program start.', 59 * desc: 'Description of how many people are seen as program start.',
56 * examples: {'num_people': 3, 'place': 'London'}); 60 * examples: {'num_people': 3, 'place': 'London'});
57 * 61 *
58 * Calling `msg({'num_people': 2, 'place': 'Athens'});` would 62 * Calling `msg(2, 'Athens'});` would
Emily Fortuna 2013/03/14 19:45:00 nit: remove }
Alan Knight 2013/03/14 20:50:04 Done.
59 * produce "I see 2 other people in Athens." as output in the default locale. 63 * produce "I see 2 other people in Athens." as output in the default locale.
60 * 64 *
61 * To use a locale other than the default, use the `withLocale` function. 65 * To use a locale other than the default, use the `withLocale` function.
62 * var todayString = new DateFormat("pt_BR").format(new DateTime.now()); 66 * var todayString = new DateFormat("pt_BR").format(new DateTime.now());
63 * print(withLocale("pt_BR", () => today(todayString)); 67 * print(withLocale("pt_BR", () => today(todayString));
64 * 68 *
65 * See `tests/message_format_test.dart` for more examples. 69 * See `tests/message_format_test.dart` for more examples.
66 */ 70 */
67 //TODO(efortuna): documentation example involving the offset parameter? 71 //TODO(efortuna): documentation example involving the offset parameter?
68 72
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 * The values of [desc] and [examples] are not used at run-time but are only 125 * The values of [desc] and [examples] are not used at run-time but are only
122 * made available to the translators, so they MUST be simple Strings available 126 * made available to the translators, so they MUST be simple Strings available
123 * at compile time: no String interpolation or concatenation. 127 * at compile time: no String interpolation or concatenation.
124 * The expected usage of this is inside a function that takes as parameters 128 * The expected usage of this is inside a function that takes as parameters
125 * the variables used in the interpolated string, and additionally also a 129 * the variables used in the interpolated string, and additionally also a
126 * locale (optional). 130 * locale (optional).
127 * Ultimately, the information about the enclosing function and its arguments 131 * Ultimately, the information about the enclosing function and its arguments
128 * will be extracted automatically but for the time being it must be passed 132 * will be extracted automatically but for the time being it must be passed
129 * explicitly in the [name] and [args] arguments. 133 * explicitly in the [name] and [args] arguments.
130 */ 134 */
131 static Future<String> message(String message_str, {final String desc: '', 135 static String message(String message_str, {final String desc: '',
132 final Map examples: const {}, String locale, String name, 136 final Map examples: const {}, String locale, String name,
133 List<String> args}) { 137 List<String> args}) {
134 return messageLookup.lookupMessage( 138 return messageLookup.lookupMessage(
135 message_str, desc, examples, locale, name, args); 139 message_str, desc, examples, locale, name, args);
136 } 140 }
137 141
138 /** 142 /**
139 * Return the locale for this instance. If none was set, the locale will 143 * Return the locale for this instance. If none was set, the locale will
140 * be the default. 144 * be the default.
141 */ 145 */
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 268
265 /** 269 /**
266 * Accessor for the current locale. This should always == the default locale, 270 * Accessor for the current locale. This should always == the default locale,
267 * unless for some reason this gets called inside a message that resets the 271 * unless for some reason this gets called inside a message that resets the
268 * locale. 272 * locale.
269 */ 273 */
270 static String getCurrentLocale() { 274 static String getCurrentLocale() {
271 if (_defaultLocale == null) _defaultLocale = systemLocale; 275 if (_defaultLocale == null) _defaultLocale = systemLocale;
272 return _defaultLocale; 276 return _defaultLocale;
273 } 277 }
278
279 toString() => "Intl($locale)";
274 } 280 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698