| 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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 } catch (e) {}; | 74 } catch (e) {}; |
| 75 return null; | 75 return null; |
| 76 } | 76 } |
| 77 | 77 |
| 78 /** | 78 /** |
| 79 * Run the "defaults read -g AppleLocale" command and return the output in | 79 * Run the "defaults read -g AppleLocale" command and return the output in |
| 80 * a future. | 80 * a future. |
| 81 */ | 81 */ |
| 82 Future _getAppleDefaults() { | 82 Future _getAppleDefaults() { |
| 83 var p = Process.run('defaults', ['read', '-g', 'AppleLocale']); | 83 var p = Process.run('defaults', ['read', '-g', 'AppleLocale']); |
| 84 var myResult = p.chain((result) => _checkResult(result, _appleDefaultsRegex)); | 84 var myResult = p.then((result) => _checkResult(result, _appleDefaultsRegex)); |
| 85 return myResult; | 85 return myResult; |
| 86 } | 86 } |
| 87 | 87 |
| 88 /** | 88 /** |
| 89 * Run the "systemlocale" command and return the output in a future. | 89 * Run the "systemlocale" command and return the output in a future. |
| 90 */ | 90 */ |
| 91 Future _getWindowsSystemInfo() { | 91 Future _getWindowsSystemInfo() { |
| 92 var p = Process.run('systeminfo', []); | 92 var p = Process.run('systeminfo', []); |
| 93 var myResult = p.chain((result) => _checkResult(result, _sysInfoRegex)); | 93 var myResult = p.then((result) => _checkResult(result, _sysInfoRegex)); |
| 94 return myResult; | 94 return myResult; |
| 95 } | 95 } |
| 96 | 96 |
| 97 /** | 97 /** |
| 98 * Given [result], find its text and extract the locale from it using | 98 * Given [result], find its text and extract the locale from it using |
| 99 * [regex], and set it as the system locale. If the process didn't run correctly | 99 * [regex], and set it as the system locale. If the process didn't run correctly |
| 100 * then don't set the variable and return a future that completes with null. | 100 * then don't set the variable and return a future that completes with null. |
| 101 */ | 101 */ |
| 102 Future<String> _checkResult(ProcessResult result, RegExp regex) { | 102 Future<String> _checkResult(ProcessResult result, RegExp regex) { |
| 103 if (result.exitCode != 0) return new Future.immediate(null); | 103 if (result.exitCode != 0) return new Future.immediate(null); |
| 104 var match = regex.firstMatch(result.stdout); | 104 var match = regex.firstMatch(result.stdout); |
| 105 if (match == null) return new Future.immediate(null); | 105 if (match == null) return new Future.immediate(null); |
| 106 var locale = match.group(1); | 106 var locale = match.group(1); |
| 107 _setLocale(locale); | 107 _setLocale(locale); |
| 108 return new Future.immediate(locale); | 108 return new Future.immediate(locale); |
| 109 } | 109 } |
| 110 | 110 |
| 111 /** | 111 /** |
| 112 * Set [Intl.systemLocale] to be the canonicalizedLocale of [aLocale]. | 112 * Set [Intl.systemLocale] to be the canonicalizedLocale of [aLocale]. |
| 113 */ | 113 */ |
| 114 Future<String> _setLocale(aLocale) { | 114 Future<String> _setLocale(aLocale) { |
| 115 Intl.systemLocale = Intl.canonicalizedLocale(aLocale); | 115 Intl.systemLocale = Intl.canonicalizedLocale(aLocale); |
| 116 return new Future.immediate(Intl.systemLocale); | 116 return new Future.immediate(Intl.systemLocale); |
| 117 } | 117 } |
| OLD | NEW |