Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use objc2 and objc2-foundation #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ regex = "1"
winapi = { version = "0.3", features = ["winnls"] }

[target.'cfg(target_os = "macos")'.dependencies]
objc = "^0.2"
objc-foundation = "^0.1"
objc2 = "0.5.1"
objc2-foundation = { version = "0.2", features = ["NSLocale", "NSString"] }
8 changes: 5 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
#[macro_use]
extern crate lazy_static;

extern crate regex;
#[cfg(target_os = "macos")]
extern crate objc2;

#[cfg(target_os = "macos")]
#[macro_use]
extern crate objc;
extern crate objc2_foundation;

extern crate regex;

use regex::Regex;
use std::borrow::{Borrow,Cow};
Expand Down
17 changes: 6 additions & 11 deletions src/macos.rs
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(),
))
}