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

Unified Diff: packages/intl/lib/intl_standalone.dart

Issue 2989763002: Update charted to 0.4.8 and roll (Closed)
Patch Set: Removed Cutch from list of reviewers Created 3 years, 5 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 | « packages/intl/lib/intl_browser.dart ('k') | packages/intl/lib/message_lookup_by_library.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: packages/intl/lib/intl_standalone.dart
diff --git a/packages/intl/lib/intl_standalone.dart b/packages/intl/lib/intl_standalone.dart
index c69378d2af83c935f28b3acb0c4c53ae12d02a2a..7da66d0cc9f6f8d15590961624657eacf81d1f0f 100644
--- a/packages/intl/lib/intl_standalone.dart
+++ b/packages/intl/lib/intl_standalone.dart
@@ -2,12 +2,10 @@
// 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.
-/**
- * This provides facilities for Internationalization that are only available
- * when running standalone. You should import only one of this or
- * intl_browser.dart. Right now the only thing provided here is finding
- * the operating system locale.
- */
+/// This provides facilities for Internationalization that are only available
+/// when running standalone. You should import only one of this or
+/// intl_browser.dart. Right now the only thing provided here is finding
+/// the operating system locale.
library intl_standalone;
@@ -20,81 +18,14 @@ import "intl.dart";
// seems to be no graceful way to do this at all. Either mirror access on
// dart2js or the ability to do spawnUri in the browser would be promising
// as ways to get rid of this requirement.
-/**
- * Find the system locale, accessed via the appropriate system APIs, and
- * set it as the default for internationalization operations in
- * the [Intl.systemLocale] variable. To find it, we
- * check the "LANG" environment variable on *nix, use the "systeminfo"
- * command on Windows, and on the Mac check the environment variable "LANG",
- * and if it's not found, use "defaults read -g AppleLocale". This
- * is not an ideal way of getting a single system locale, even if that
- * concept really made sense, but it's a reasonable first approximation that's
- * not too difficult to get. If it can't find the locale information, it will
- * not modify [Intl.systemLocale] and the Future will complete with null.
- */
+/// Find the system locale, accessed via the appropriate system APIs, and
+/// set it as the default for internationalization operations in
+/// the [Intl.systemLocale] variable.
Future<String> findSystemLocale() {
- // On *nix systems we expect this is an environment variable, which is the
- // easiest thing to check. On a Mac the environment variable may be present
- // so always check it first. We have no mechanism for this right now on
- // Windows, so it will just fail.
- String baseLocale = _checkEnvironmentVariable();
- if (baseLocale != null) return _setLocale(baseLocale);
- if (Platform.operatingSystem == 'macos') {
- return _getAppleDefaults();
- }
- // We can't find anything, don't set the system locale and return null.
- return new Future.value();
-}
-
-/**
- * Regular expression to match the expected output of reading the defaults
- * database for AppleLanguages on Mac systems.
- * e.g. {
- * en,
- * "pt-PT",
- * ...
- */
-RegExp _appleDefaultsRegex = new RegExp(r'((\w\w)_\w+)');
-
-/**
- * Check to see if we have a "LANG" environment variable we can use and return
- * it if found. Otherwise return null;
- */
-String _checkEnvironmentVariable() {
try {
- return Platform.environment['LANG'];
- } catch (e) {}
- return null;
-}
-
-/**
- * Run the "defaults read -g AppleLocale" command and return the output in
- * a future.
- */
-Future _getAppleDefaults() {
- var p = Process.run('defaults', ['read', '-g', 'AppleLocale']);
- var myResult = p.then((result) => _checkResult(result, _appleDefaultsRegex));
- return myResult;
-}
-
-/**
- * Given [result], find its text and extract the locale from it using
- * [regex], and set it as the system locale. If the process didn't run correctly
- * then don't set the variable and return a future that completes with null.
- */
-Future<String> _checkResult(ProcessResult result, RegExp regex) {
- if (result.exitCode != 0) return new Future.value();
- var match = regex.firstMatch(result.stdout);
- if (match == null) return new Future.value();
- var locale = match.group(1);
- _setLocale(locale);
- return new Future.value(locale);
-}
-
-/**
- * Set [Intl.systemLocale] to be the canonicalizedLocale of [aLocale].
- */
-Future<String> _setLocale(aLocale) {
- Intl.systemLocale = Intl.canonicalizedLocale(aLocale);
+ Intl.systemLocale = Intl.canonicalizedLocale(Platform.localeName);
+ } catch (e) {
+ return new Future.value();
+ }
return new Future.value(Intl.systemLocale);
}
« no previous file with comments | « packages/intl/lib/intl_browser.dart ('k') | packages/intl/lib/message_lookup_by_library.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698