Skip to content

Commit

Permalink
Merge branch 'main' into unwrap
Browse files Browse the repository at this point in the history
  • Loading branch information
eirnym committed Oct 21, 2024
2 parents 8cbab38 + 5f1fea8 commit 8961cc4
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 24 deletions.
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"] }
15 changes: 7 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
[![TravisCI Build Status](https://travis-ci.org/rust-locale/locale_config.svg?branch=master)](https://travis-ci.org/rust-locale/locale_config)
[![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/13100wtqs80tyink/branch/master?svg=true)](https://ci.appveyor.com/project/jan-hudec/locale-config/branch/master)
[![Crates.io Version](https://img.shields.io/crates/v/locale_config.svg)](https://crates.io/crates/locale_config)
[![Docs.rs](https://docs.rs/locale_config/badge.svg)](https://docs.rs/locale_config/)

# `locale_config`

Remembers locale configuration per-thread and per-process and initializes the
values by inspecting the system for user preferences.

FYI: it's a hard fork of https://github.com/rust-locale/locale_config which hasn't been maintained for a while

## Installation

You can depend on this library by adding `locale_config` to your Cargo dependencies:

```toml
[dependencies]
locale_config = "*"
locale_config = { git="https://github.com/eirtools/locale_config" }
```

Usually it is not recommended to depend on `*`, but in this case it is
Expand Down Expand Up @@ -69,8 +66,6 @@ Note that this crate does not itself provide any translation, formatting nor
collation functionality. Formatting and collation will be provided by
`locale` crate, translation has multiple available implementations.

See full documentation on [![Docs.rs](https://docs.rs/locale_config/badge.svg)](https://docs.rs/locale_config/) or [github](https://rust-locale.github.io/locale_config/locale_config/).

## Supported systems

* **Unix:** Using the POSIX standard environment variables `LANG`, `LC_*` and
Expand All @@ -97,6 +92,10 @@ See full documentation on [![Docs.rs](https://docs.rs/locale_config/badge.svg)](

## Changelog

### Unreleased

* Rebrand

### 0.3.0

* Support OS X `NSLocale`.
Expand Down
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()
};
Some(Locale::from(LanguageRange::from_unix(locale_identifier?.as_str()).ok()?))
let current_locale = unsafe { NSLocale::currentLocale() };
let locale_identifier = unsafe { current_locale.localeIdentifier() };
Some(Locale::from(
LanguageRange::from_unix(&locale_identifier.to_string()).unwrap(),
))
}

0 comments on commit 8961cc4

Please sign in to comment.