| 1 |
//! Inspect macOS system for locale configuration |
| 2 |
extern crate objc_foundation; |
| 3 |
|
| 4 |
use super::{LanguageRange, Locale}; |
| 5 |
|
| 6 |
use objc::runtime::Object; |
| 7 |
use self::objc_foundation::{INSString, NSString}; |
| 8 |
|
| 9 |
pub fn system_locale() -> Option<Locale> { |
| 10 |
let locale_identifier = unsafe { |
| 11 |
let nslocale = class!(NSLocale); |
| 12 |
let current_locale: *mut Object = msg_send![nslocale, currentLocale]; |
| 13 |
let locale_identifier: *const NSString = msg_send![current_locale, localeIdentifier]; |
| 14 |
locale_identifier.as_ref().unwrap() |
| 15 |
}; |
| 16 |
Some(Locale::from(LanguageRange::from_unix(locale_identifier.as_str()).unwrap())) |
| 17 |
} |