Use Platform.localeName on standalone [Intl]
From https://codereview.chromium.org/2786223004/
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=159046535
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 816d139..e63466e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,6 @@
+## 0.15.1
+ * Use the platform.locale API to get the OS platform.
+
## 0.15.0
* Fix compactCurrency to correctly use passed-in symbol.
* A tweak to the way we retry on DateTime.asDate to compensate for a VM bug.
diff --git a/lib/intl_standalone.dart b/lib/intl_standalone.dart
index 081ff4c..7da66d0 100644
--- a/lib/intl_standalone.dart
+++ b/lib/intl_standalone.dart
@@ -20,67 +20,12 @@
// 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.
+/// 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<String> _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.
-String _checkResult(ProcessResult result, RegExp regex) {
- if (result.exitCode != 0) return null;
- var match = regex.firstMatch(result.stdout);
- if (match == null) return null;
- var locale = match.group(1);
- _setLocale(locale);
- return 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);
}
diff --git a/pubspec.yaml b/pubspec.yaml
index 0e04b80..eadf150 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -4,7 +4,7 @@
description: Contains code to deal with internationalized/localized messages, date and number formatting and parsing, bi-directional text, and other internationalization issues.
homepage: https://github.com/dart-lang/intl
environment:
- sdk: '>=1.12.0 <2.0.0'
+ sdk: '>=1.24.0 <2.0.0'
documentation: http://www.dartdocs.org/documentation/intl/latest
dependencies:
path: '>=0.9.0 <2.0.0'