Index: lib/i18n/intl.dart |
=================================================================== |
--- lib/i18n/intl.dart (revision 8510) |
+++ lib/i18n/intl.dart (working copy) |
@@ -1,8 +1,8 @@ |
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
+// for details. All rights reserved. Use of this source code is governed by a |
+// BSD-style license that can be found in the LICENSE file. |
+ |
/** |
- * Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
- * for details. All rights reserved. Use of this source code is governed by a |
- * BSD-style license that can be found in the LICENSE file. |
- * |
* Internationalization object providing access to message formatting objects, |
* date formatting, parsing, bidirectional text relative to a specific locale. |
*/ |
@@ -13,7 +13,6 @@ |
#import('date_format.dart'); |
class Intl { |
- |
/** |
* String indicating the locale code with which the message is to be |
* formatted (such as en-CA). |
@@ -22,17 +21,46 @@ |
IntlMessage intlMsg; |
- DateFormat date; |
+ /** |
+ * Return a new date format using the specified [pattern] or with no |
+ * pattern if it was omitted. In the second case we assume that pattern |
+ * will be set later, otherwise the format is not useful. |
Emily Fortuna
2012/07/31 05:52:53
why make pattern optional?
Alan Knight
2012/08/03 23:02:15
OK, made it required.
|
+ * If [locale] is not specified, then we default to the locale specified |
Emily Fortuna
2012/07/31 05:52:53
desiredLocale
Alan Knight
2012/08/03 23:02:15
Done.
|
+ * in this instance. Note that this is different from using the static |
Emily Fortuna
2012/07/31 05:52:53
"locale specified in this instance" please clarify
Alan Knight
2012/08/03 23:02:15
Done.
|
+ * version of this, in which case we will default to the overall default |
Emily Fortuna
2012/07/31 05:52:53
please rephrase this last sentence. "this" is a bi
Alan Knight
2012/08/03 23:02:15
Moot, since I removed the static version as per a
|
+ * locale. |
+ */ |
+ DateFormat date([String pattern, String desiredLocale]) { |
+ var actualLocale = (desiredLocale == null) ? _locale : desiredLocale; |
+ return new DateFormat(pattern,actualLocale); |
+ } |
/** |
+ * Return a new date format using the specified [pattern] or with no |
+ * pattern if it was omitted. In the second case we assume that pattern |
+ * will be set later, otherwise the format is not useful. |
+ * If [locale] is not specified, then we use the global default locale. |
+ * Note that this is different from using the instance method |
+ * version of this, in which case we will default to the locale of that |
+ * instance. |
+ */ |
+ static DateFormat Date([pattern, desiredLocale]) { |
Emily Fortuna
2012/07/31 05:52:53
types for parameters
Alan Knight
2012/08/03 23:02:15
Method removed.
|
+ //TODO(alanknight): I don't love the uppercase for static convention here |
+ // but couldn't come up with better names, and it seems useful to be able |
+ // to do this both statically and on an instance. |
Emily Fortuna
2012/07/31 05:52:53
if you're going to do this statically the user mig
Alan Knight
2012/08/03 23:02:15
Done.
|
+ var actualLocale = (desiredLocale == null) ? defaultLocale: desiredLocale; |
+ return new DateFormat(pattern,actualLocale); |
+ } |
+ |
+ /** |
* Constructor optionally [_locale] 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([this._locale]) { |
+ Intl([locale]) { |
+ _locale = locale; |
intlMsg = new IntlMessage(_locale); |
- date = new DateFormat(_locale); |
} |
/** |
@@ -53,7 +81,24 @@ |
return message_str; |
} |
+ /** The default locale for this environment. */ |
+ //TODO(alanknight): Return the correct locale using either |
+ // window.navigator.language or appropriate environment variable or other |
+ // mechanism for command-line apps. |
+ static String defaultLocale = 'en_US'; |
+ |
/** |
+ * Return the locale for this instance. If none was set, returns the |
+ * default. |
+ */ |
+ String get locale() { |
+ if (_locale == null) { |
Emily Fortuna
2012/07/31 05:52:53
please sync your files before submitting for revie
|
+ return defaultLocale; |
+ } else { |
+ return _locale;} |
+ } |
+ |
+ /** |
* Support method for message formatting. Select the correct plural form from |
* [cases] given [howMany]. |
*/ |