OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * This provides facilities for Internationalization that are only available | 6 * This provides facilities for Internationalization that are only available |
7 * when running standalone. You should import only one of this or | 7 * when running standalone. You should import only one of this or |
8 * intl_browser.dart. Right now the only thing provided here is finding | 8 * intl_browser.dart. Right now the only thing provided here is finding |
9 * the operating system locale. | 9 * the operating system locale. |
10 */ | 10 */ |
(...skipping 25 matching lines...) Expand all Loading... |
36 // On *nix systems we expect this is an environment variable, which is the | 36 // On *nix systems we expect this is an environment variable, which is the |
37 // easiest thing to check. On a Mac the environment variable may be present | 37 // easiest thing to check. On a Mac the environment variable may be present |
38 // so always check it first. We have no mechanism for this right now on | 38 // so always check it first. We have no mechanism for this right now on |
39 // Windows, so it will just fail. | 39 // Windows, so it will just fail. |
40 String baseLocale = _checkEnvironmentVariable(); | 40 String baseLocale = _checkEnvironmentVariable(); |
41 if (baseLocale != null) return _setLocale(baseLocale); | 41 if (baseLocale != null) return _setLocale(baseLocale); |
42 if (Platform.operatingSystem == 'macos') { | 42 if (Platform.operatingSystem == 'macos') { |
43 return _getAppleDefaults(); | 43 return _getAppleDefaults(); |
44 } | 44 } |
45 // We can't find anything, don't set the system locale and return null. | 45 // We can't find anything, don't set the system locale and return null. |
46 return new Future.immediate(null); | 46 return new Future.value(); |
47 } | 47 } |
48 | 48 |
49 /** | 49 /** |
50 * Regular expression to match the expected output of reading the defaults | 50 * Regular expression to match the expected output of reading the defaults |
51 * database for AppleLanguages on Mac systems. | 51 * database for AppleLanguages on Mac systems. |
52 * e.g. { | 52 * e.g. { |
53 * en, | 53 * en, |
54 * "pt-PT", | 54 * "pt-PT", |
55 * ... | 55 * ... |
56 */ | 56 */ |
(...skipping 19 matching lines...) Expand all Loading... |
76 var myResult = p.then((result) => _checkResult(result, _appleDefaultsRegex)); | 76 var myResult = p.then((result) => _checkResult(result, _appleDefaultsRegex)); |
77 return myResult; | 77 return myResult; |
78 } | 78 } |
79 | 79 |
80 /** | 80 /** |
81 * Given [result], find its text and extract the locale from it using | 81 * Given [result], find its text and extract the locale from it using |
82 * [regex], and set it as the system locale. If the process didn't run correctly | 82 * [regex], and set it as the system locale. If the process didn't run correctly |
83 * then don't set the variable and return a future that completes with null. | 83 * then don't set the variable and return a future that completes with null. |
84 */ | 84 */ |
85 Future<String> _checkResult(ProcessResult result, RegExp regex) { | 85 Future<String> _checkResult(ProcessResult result, RegExp regex) { |
86 if (result.exitCode != 0) return new Future.immediate(null); | 86 if (result.exitCode != 0) return new Future.value(); |
87 var match = regex.firstMatch(result.stdout); | 87 var match = regex.firstMatch(result.stdout); |
88 if (match == null) return new Future.immediate(null); | 88 if (match == null) return new Future.value(); |
89 var locale = match.group(1); | 89 var locale = match.group(1); |
90 _setLocale(locale); | 90 _setLocale(locale); |
91 return new Future.immediate(locale); | 91 return new Future.value(locale); |
92 } | 92 } |
93 | 93 |
94 /** | 94 /** |
95 * Set [Intl.systemLocale] to be the canonicalizedLocale of [aLocale]. | 95 * Set [Intl.systemLocale] to be the canonicalizedLocale of [aLocale]. |
96 */ | 96 */ |
97 Future<String> _setLocale(aLocale) { | 97 Future<String> _setLocale(aLocale) { |
98 Intl.systemLocale = Intl.canonicalizedLocale(aLocale); | 98 Intl.systemLocale = Intl.canonicalizedLocale(aLocale); |
99 return new Future.immediate(Intl.systemLocale); | 99 return new Future.value(Intl.systemLocale); |
100 } | 100 } |
OLD | NEW |