How to get the environment variable "LANG" under windows system?

I noticed that we can use "LANG" environment variable via "cargo run". However, it will get exception when we run the complied program under windows system. My question is how to use "LANG" environment variable under windows system without "cargo run"?

Configuration - The Cargo Book doesn't contain LANG. Are you referring to the POSIX environment variable for locales? That doesn't have anything to do with Cargo or Rust, it's just an API that doesn't exist on Windows.

1 Like

Tanks for your reply. Does there exist any crates which can get culture info from windows system?

Seeing as this is OS-specific you're probably looking for GetLocaleInfoEx() and friends from the Windows API. There are probably nice wrappers, but you can always use winapi::um::winnls::GetLocaleInfoEx() to access the function directly.

Thanks Michael!
I followed your reply and find it out.

I set Cargo.toml like this:
winapi = { version = "0.3", features = ["winnls"] }

And In my

extern crate winapi;


fn test() {

use winapi::um::winnls::GetUserDefaultLCID;


    println!("{}", GetUserDefaultLCID());



fn main() {


println!("Hello, world!");


It works fine.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.