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

Unified Diff: pkg/intl/intl.dart

Issue 10907266: Find the system locale from the browser or OS (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/intl/intl_browser.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/intl/intl.dart
===================================================================
--- pkg/intl/intl.dart (revision 12460)
+++ pkg/intl/intl.dart (working copy)
@@ -24,10 +24,23 @@
*/
String _locale;
- /** The default locale, which normally will be obtained from the browser. */
+ /** The default locale. This defaults to being set from systemLocale, but
+ * can also be set explicitly, and will then apply to any new instances where
+ * the locale isn't specified.
+ */
static String _defaultLocale;
/**
+ * The system's locale, as obtained from the window.navigator.language
+ * or other operating system mechanism. Note that due to system limitations
+ * this is not automatically set, and must be set by importing one of
+ * intl_browser.dart or intl_standalone.dart and calling findSystemLocale().
+ */
+ // TODO(alanknight): Detect this without forcing the jump through hoops.
+ // Issue 5171.
+ static String systemLocale = 'en_US';
+
+ /**
* Return a new date format using the specified [pattern].
* If [desiredLocale] is not specified, then we default to [locale].
*/
@@ -102,11 +115,11 @@
static String verifiedLocale(String newLocale) {
// TODO(alanknight): This is specific to DateFormat, and only used there
// now. This should be moved, renamed, or generalized.
- if (newLocale == null) return _getDefaultLocale();
+ if (newLocale == null) return systemLocale;
if (_localeExists(newLocale)) {
return newLocale;
}
- for (var each in [_canonicalized(newLocale), _shortLocale(newLocale)]) {
+ for (var each in [canonicalizedLocale(newLocale), _shortLocale(newLocale)]) {
if (_localeExists(each)) {
return each;
}
@@ -124,7 +137,7 @@
* Return a locale name turned into xx_YY where it might possibly be
* in the wrong case or with a hyphen instead of an underscore.
*/
- static String _canonicalized(String aLocale) {
+ static String canonicalizedLocale(String aLocale) {
// Locales of length < 5 are presumably two-letter forms, or else malformed.
// Locales of length > 6 are likely to be malformed. In either case we
// return them unmodified and if correct they will be found.
@@ -152,7 +165,7 @@
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 (_defaultLocale == null) _defaultLocale = _getDefaultLocale();
+ if (_defaultLocale == null) _defaultLocale = systemLocale;
var oldLocale = _defaultLocale;
_defaultLocale = locale;
var result = msg_function();
@@ -175,23 +188,12 @@
}
/**
- * Helper to detect the locale as defined at runtime.
- */
- static String _getDefaultLocale() {
- // TODO(efortuna): Detect the default locale given the user preferences.
- // That would mean using window.navigator.language in a browser or
- // an environment variable or other OS mechanism for the standalone VM.
- // Yay, hard-coding for now!
- return 'en_US';
- }
-
- /**
* Accessor for the current locale. This should always == the default locale,
* unless for some reason this gets called inside a message that resets the
* locale.
*/
static String getCurrentLocale() {
- if (_defaultLocale == null) _defaultLocale = _getDefaultLocale();
+ if (_defaultLocale == null) _defaultLocale = systemLocale;
return _defaultLocale;
}
}
« no previous file with comments | « no previous file | pkg/intl/intl_browser.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698