在Linux系统下我们可以通过std::env::var(“LANG”)来获取操作系统的语言信息。但是在Windows下std::env::var("LANG")是没有值 的。这个时候就需要用到winapi了。
cargo.toml:
[package]
name = "winapi_sample"
version = "0.1.0"
authors = ["许阳 <mksword@126.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[target.'cfg(windows)'.dependencies]
winapi = { version = "0.3", features = ["winnls"] }
main.rs
#[cfg(windows)]
extern crate winapi;
#[cfg(windows)]
fn test() {
use winapi::um::winnls::GetUserDefaultLCID;
unsafe{
println!("{}", GetUserDefaultLCID());
}
}
fn main() {
test();
println!("Hello, world!");
}