-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
These crates are the successor crates to objc and objc-foundation. Relevant to locale_config is that bindings to `NSLocale` is provided, avoiding the error-prone `msg_send!` macros.
- Loading branch information
Showing
3 changed files
with
13 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,12 @@ | ||
//! Inspect macOS system for locale configuration | ||
extern crate objc_foundation; | ||
|
||
use super::{LanguageRange, Locale}; | ||
|
||
use objc::runtime::Object; | ||
use self::objc_foundation::{INSString, NSString}; | ||
use objc2_foundation::NSLocale; | ||
|
||
pub fn system_locale() -> Option<Locale> { | ||
let locale_identifier = unsafe { | ||
let nslocale = class!(NSLocale); | ||
let current_locale: *mut Object = msg_send![nslocale, currentLocale]; | ||
let locale_identifier: *const NSString = msg_send![current_locale, localeIdentifier]; | ||
locale_identifier.as_ref().unwrap() | ||
}; | ||
Some(Locale::from(LanguageRange::from_unix(locale_identifier.as_str()).unwrap())) | ||
let current_locale = unsafe { NSLocale::currentLocale() }; | ||
let locale_identifier = unsafe { current_locale.localeIdentifier() }; | ||
Some(Locale::from( | ||
LanguageRange::from_unix(&locale_identifier.to_string()).unwrap(), | ||
)) | ||
} |