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

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') | pkg/intl/intl_standalone.dart » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/intl/intl.dart
===================================================================
--- pkg/intl/intl.dart (revision 12455)
+++ pkg/intl/intl.dart (working copy)
@@ -106,7 +106,7 @@
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 +124,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 +152,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,14 +175,20 @@
}
/**
+ * 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';
Emily Fortuna 2012/09/17 21:26:38 in that case, should by default we make systemLoca
Alan Knight 2012/09/17 22:16:18 Default: The user may not call either of these mec
+
+ /**
* 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';
+ return systemLocale;
}
/**
@@ -191,7 +197,7 @@
* locale.
*/
static String getCurrentLocale() {
- if (_defaultLocale == null) _defaultLocale = _getDefaultLocale();
+ if (_defaultLocale == null) _defaultLocale = systemLocale;
Emily Fortuna 2012/09/17 21:26:38 if you add this systemLocale variable, the necessi
Alan Knight 2012/09/17 22:16:18 Yes. I think I'd thought that but then forgot. Don
return _defaultLocale;
}
}
« no previous file with comments | « no previous file | pkg/intl/intl_browser.dart » ('j') | pkg/intl/intl_standalone.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698