Chromium Code Reviews| Index: pkg/intl/intl.dart |
| =================================================================== |
| --- pkg/intl/intl.dart (revision 12224) |
| +++ pkg/intl/intl.dart (working copy) |
| @@ -8,10 +8,11 @@ |
| */ |
| #library('intl'); |
| -#import('../../pkg/htmlescape/htmlescape.dart'); |
| +#import('../htmlescape/htmlescape.dart'); |
| #import('date_format.dart'); |
| -#source('intl_message.dart'); |
| +#import('lib/intl_helpers.dart'); |
|
Emily Fortuna
2012/09/12 01:23:48
I don't see any "intl_helpers.dart" did this not g
Alan Knight
2012/09/12 20:58:20
It's in the /lib directory, but should be there.
h
|
| + |
| #source('bidi_formatter.dart'); |
| #source('bidi_utils.dart'); |
| @@ -20,36 +21,34 @@ |
| * String indicating the locale code with which the message is to be |
| * formatted (such as en-CA). |
| */ |
| - static String _locale; |
| + String _locale; |
| - IntlMessage intlMsg; |
| + /** The default locale, which normally will be obtained from the browser. */ |
| + static String _defaultLocale; |
| /** |
| * Return a new date format using the specified [pattern]. |
| * If [desiredLocale] is not specified, then we default to [locale]. |
| */ |
| - DateFormat date(String pattern, [String desiredLocale]) { |
| - var actualLocale = (desiredLocale == null) ? _locale : desiredLocale; |
| + DateFormat date([String pattern, String desiredLocale]) { |
| + var actualLocale = (desiredLocale == null) ? locale : desiredLocale; |
| return new DateFormat(pattern, actualLocale); |
| } |
| /** |
| - * Constructor optionally [_locale] for specifics of the language |
| + * Constructor optionally [aLocale] for specifics of the language |
| * locale to be used, otherwise, we will attempt to infer it (acceptable if |
| * Dart is running on the client, we can infer from the browser/client |
| * preferences). |
| */ |
| - Intl([a_locale]) { |
| - if (a_locale == null) { |
| - _locale = _getDefaultLocale(); |
| - } else { |
| - _locale = verifiedLocale(a_locale); |
| + Intl([String aLocale]) { |
| + if (aLocale != null) { |
| + _locale = aLocale; |
|
Emily Fortuna
2012/09/12 01:23:48
why not set a default here? then you don't have to
Alan Knight
2012/09/12 20:58:20
Done.
|
| } |
| - intlMsg = new IntlMessage(_locale); |
| } |
| /** |
| - * Create a message that can be internationalized. It takes a |
| + * Returns a message that can be internationalized. It takes a |
| * [message_str] that will be translated, which may be interpolated |
| * based on one or more variables, a [desc] providing a description of usage |
| * for the [message_str], and a map of [examples] for each data element to be |
| @@ -62,17 +61,26 @@ |
| * The expected usage of this is inside a function that takes as parameters |
| * the variables used in the interpolated string, and additionally also a |
| * locale (optional). |
| + * Ultimately, the information about the enclosing function and its arguments |
| + * will be extracted automatically but for the time being it must be passed |
| + * explicitly in the [name] and [args] arguments. |
| */ |
| static String message(String message_str, [final String desc='', |
| - final Map examples=const {}, String locale='']) { |
| - return message_str; |
| + final Map examples=const {}, String locale, String name, |
|
Emily Fortuna
2012/09/12 01:23:48
indent at least two more spaces here
Alan Knight
2012/09/12 20:58:20
Done.
|
| + List<String> args]) { |
| + return _messageLookup. |
|
Emily Fortuna
2012/09/12 01:23:48
do the line break at the opening of the ( please i
Emily Fortuna
2012/09/12 01:23:48
indent two less spaces here
Alan Knight
2012/09/12 20:58:20
Done.
Alan Knight
2012/09/12 20:58:20
Done.
|
| + lookupMessage(message_str, desc, examples, locale, name, args); |
| } |
| /** |
| * Return the locale for this instance. If none was set, the locale will |
| * be the default. |
| */ |
| - String get locale => _locale; |
| + String get locale { |
| + if (_locale == null) { |
| + _locale = _getDefaultLocale();} |
| + return _locale; |
| + } |
| /** |
| * Return true if the locale exists, or if it is null. The null case |
| @@ -143,11 +151,11 @@ |
| static String withLocale(String locale, Function msg_function) { |
| // We have to do this silliness because Locale is not known at compile time, |
| // but must be a static variable. |
| - if (_locale == null) _locale = _getDefaultLocale(); |
| - var oldLocale = _locale; |
| - _locale = locale; |
| + if (_defaultLocale == null) _defaultLocale = _getDefaultLocale(); |
| + var oldLocale = _defaultLocale; |
| + _defaultLocale = locale; |
| var result = msg_function(); |
| - _locale = oldLocale; |
| + _defaultLocale = oldLocale; |
| return result; |
| } |
| @@ -182,6 +190,24 @@ |
| * locale. |
| */ |
| static String getCurrentLocale() { |
| - return _locale; |
| + if (_defaultLocale == null) _defaultLocale = _getDefaultLocale(); |
| + return _defaultLocale; |
| } |
| } |
| + |
| +/** The internal mechanism for looking up messages. We expect this to be set |
|
Emily Fortuna
2012/09/12 01:23:48
/**
* The internal....
*/
Alan Knight
2012/09/12 20:58:20
Done.
|
| + * by the implementing package so that we're not dependent on its |
| + * implementation. |
| + */ |
| +var _messageLookup = const |
| + UninitializedLocaleData('initializeMessages(<locale>)'); |
| + |
| +/** Initialize the message lookup mechanism. This is for internal use only. |
|
Emily Fortuna
2012/09/12 01:23:48
same formatting here
Alan Knight
2012/09/12 20:58:20
Done.
|
| + * User applications should import message_lookup_local.dart and call |
| + * initializeMessages |
| + */ |
| +void initializeInternalMessageLookup(Function lookupFunction) { |
| + if (_messageLookup is UninitializedLocaleData) { |
| + _messageLookup = lookupFunction(); |
| + } |
| +} |