Skip to content
This repository was archived by the owner on Aug 30, 2023. It is now read-only.

Commit f8ad835

Browse files
committed
Use Platform.localeName on standalone [Intl]
From https://codereview.chromium.org/2786223004/ ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=159046535
1 parent 77b8ba5 commit f8ad835

File tree

3 files changed

+9
-61
lines changed

3 files changed

+9
-61
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 0.15.1
2+
* Use the platform.locale API to get the OS platform.
3+
14
## 0.15.0
25
* Fix compactCurrency to correctly use passed-in symbol.
36
* A tweak to the way we retry on DateTime.asDate to compensate for a VM bug.

lib/intl_standalone.dart

Lines changed: 5 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -20,67 +20,12 @@ import "intl.dart";
2020
// as ways to get rid of this requirement.
2121
/// Find the system locale, accessed via the appropriate system APIs, and
2222
/// set it as the default for internationalization operations in
23-
/// the [Intl.systemLocale] variable. To find it, we
24-
/// check the "LANG" environment variable on *nix, use the "systeminfo"
25-
/// command on Windows, and on the Mac check the environment variable "LANG",
26-
/// and if it's not found, use "defaults read -g AppleLocale". This
27-
/// is not an ideal way of getting a single system locale, even if that
28-
/// concept really made sense, but it's a reasonable first approximation that's
29-
/// not too difficult to get. If it can't find the locale information, it will
30-
/// not modify [Intl.systemLocale] and the Future will complete with null.
23+
/// the [Intl.systemLocale] variable.
3124
Future<String> findSystemLocale() {
32-
// On *nix systems we expect this is an environment variable, which is the
33-
// easiest thing to check. On a Mac the environment variable may be present
34-
// so always check it first. We have no mechanism for this right now on
35-
// Windows, so it will just fail.
36-
String baseLocale = _checkEnvironmentVariable();
37-
if (baseLocale != null) return _setLocale(baseLocale);
38-
if (Platform.operatingSystem == 'macos') {
39-
return _getAppleDefaults();
40-
}
41-
// We can't find anything, don't set the system locale and return null.
42-
return new Future.value();
43-
}
44-
45-
/// Regular expression to match the expected output of reading the defaults
46-
/// database for AppleLanguages on Mac systems.
47-
/// e.g. {
48-
/// en,
49-
/// "pt-PT",
50-
/// ...
51-
RegExp _appleDefaultsRegex = new RegExp(r'((\w\w)_\w+)');
52-
53-
/// Check to see if we have a "LANG" environment variable we can use and return
54-
/// it if found. Otherwise return null;
55-
String _checkEnvironmentVariable() {
5625
try {
57-
return Platform.environment['LANG'];
58-
} catch (e) {}
59-
return null;
60-
}
61-
62-
/// Run the "defaults read -g AppleLocale" command and return the output in
63-
/// a future.
64-
Future<String> _getAppleDefaults() {
65-
var p = Process.run('defaults', ['read', '-g', 'AppleLocale']);
66-
var myResult = p.then((result) => _checkResult(result, _appleDefaultsRegex));
67-
return myResult;
68-
}
69-
70-
/// Given [result], find its text and extract the locale from it using [regex],
71-
/// and set it as the system locale. If the process didn't run correctly then
72-
/// don't set the variable and return a future that completes with null.
73-
String _checkResult(ProcessResult result, RegExp regex) {
74-
if (result.exitCode != 0) return null;
75-
var match = regex.firstMatch(result.stdout);
76-
if (match == null) return null;
77-
var locale = match.group(1);
78-
_setLocale(locale);
79-
return locale;
80-
}
81-
82-
/// Set [Intl.systemLocale] to be the canonicalizedLocale of [aLocale].
83-
Future<String> _setLocale(aLocale) {
84-
Intl.systemLocale = Intl.canonicalizedLocale(aLocale);
26+
Intl.systemLocale = Intl.canonicalizedLocale(Platform.localeName);
27+
} catch (e) {
28+
return new Future.value();
29+
}
8530
return new Future.value(Intl.systemLocale);
8631
}

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ author: Dart Team <[email protected]>
44
description: Contains code to deal with internationalized/localized messages, date and number formatting and parsing, bi-directional text, and other internationalization issues.
55
homepage: https://github.com/dart-lang/intl
66
environment:
7-
sdk: '>=1.12.0 <2.0.0'
7+
sdk: '>=1.24.0 <2.0.0'
88
documentation: http://www.dartdocs.org/documentation/intl/latest
99
dependencies:
1010
path: '>=0.9.0 <2.0.0'

0 commit comments

Comments
 (0)