Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 29 matching lines...) Expand all Loading... | |
| 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 * desc: 'Indicate the current date', | 46 * desc: 'Indicate the current date', |
| 47 * examples: {'date' : 'June 8, 2012'}); | 47 * examples: {'date' : 'June 8, 2012'}); |
| 48 * print(today(new DateTime.now()); | 48 * print(today(new DateTime.now()); |
| 49 * | 49 * |
| 50 * msg({num_people, place}) => Intl.message( | 50 * msg(num_people, place) => Intl.message( |
|
Emily Fortuna
2013/03/13 18:54:43
So now we can take an arbitrary number of paramete
Alan Knight
2013/03/14 17:49:05
Yes, it can take an arbitrary number. I'm using Fu
Emily Fortuna
2013/03/14 19:45:00
sgtm.
| |
| 51 * '''I see ${Intl.plural(num_people, | 51 * '''I see ${Intl.plural(num_people, |
| 52 * {'0': 'no one at all', | 52 * {'0': 'no one at all', |
| 53 * '1': 'one other person', | 53 * '1': 'one other person', |
| 54 * 'other': '$num_people other people'})} in $place.'''', | 54 * 'other': '$num_people other people'})} in $place.'''', |
| 55 * desc: 'Description of how many people are seen as program start.', | 55 * desc: 'Description of how many people are seen as program start.', |
| 56 * examples: {'num_people': 3, 'place': 'London'}); | 56 * examples: {'num_people': 3, 'place': 'London'}); |
| 57 * | 57 * |
| 58 * Calling `msg({'num_people': 2, 'place': 'Athens'});` would | 58 * Calling `msg({'num_people': 2, 'place': 'Athens'});` would |
| 59 * produce "I see 2 other people in Athens." as output in the default locale. | 59 * produce "I see 2 other people in Athens." as output in the default locale. |
| 60 * | 60 * |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 121 * The values of [desc] and [examples] are not used at run-time but are only | 121 * 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 | 122 * made available to the translators, so they MUST be simple Strings available |
| 123 * at compile time: no String interpolation or concatenation. | 123 * at compile time: no String interpolation or concatenation. |
| 124 * The expected usage of this is inside a function that takes as parameters | 124 * 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 | 125 * the variables used in the interpolated string, and additionally also a |
| 126 * locale (optional). | 126 * locale (optional). |
| 127 * Ultimately, the information about the enclosing function and its arguments | 127 * Ultimately, the information about the enclosing function and its arguments |
| 128 * will be extracted automatically but for the time being it must be passed | 128 * will be extracted automatically but for the time being it must be passed |
| 129 * explicitly in the [name] and [args] arguments. | 129 * explicitly in the [name] and [args] arguments. |
| 130 */ | 130 */ |
| 131 static Future<String> message(String message_str, {final String desc: '', | 131 static message(String message_str, {final String desc: '', |
|
Emily Fortuna
2013/03/13 18:54:43
should the return type here be a String?
Alan Knight
2013/03/14 17:49:05
Oh yeah, right. Got so caught up in it having been
| |
| 132 final Map examples: const {}, String locale, String name, | 132 final Map examples: const {}, String locale, String name, |
| 133 List<String> args}) { | 133 List<String> args}) { |
| 134 return messageLookup.lookupMessage( | 134 return messageLookup.lookupMessage( |
| 135 message_str, desc, examples, locale, name, args); | 135 message_str, desc, examples, locale, name, args); |
| 136 } | 136 } |
| 137 | 137 |
| 138 /** | 138 /** |
| 139 * Return the locale for this instance. If none was set, the locale will | 139 * Return the locale for this instance. If none was set, the locale will |
| 140 * be the default. | 140 * be the default. |
| 141 */ | 141 */ |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 264 | 264 |
| 265 /** | 265 /** |
| 266 * Accessor for the current locale. This should always == the default locale, | 266 * 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 | 267 * unless for some reason this gets called inside a message that resets the |
| 268 * locale. | 268 * locale. |
| 269 */ | 269 */ |
| 270 static String getCurrentLocale() { | 270 static String getCurrentLocale() { |
| 271 if (_defaultLocale == null) _defaultLocale = systemLocale; | 271 if (_defaultLocale == null) _defaultLocale = systemLocale; |
| 272 return _defaultLocale; | 272 return _defaultLocale; |
| 273 } | 273 } |
| 274 | |
| 275 toString() => "Intl($locale)"; | |
| 274 } | 276 } |
| OLD | NEW |