utf8-locale — detect a UTF-8-capable locale for running child processes in


Sometimes it is useful for a program to be able to run a child process and more or less depend on its output being valid UTF-8. This can usually be accomplished by setting one or more environment variables, but there is the question of what to set them to - what UTF-8-capable locale is present on this particular system? This is where the utf8_locale library comes in.


For the Rust implementation:

use std::process; use utf8_locale; let utf8env = utf8_locale::Utf8Detect()::new().detect()?; let cmd = process::Command::new(...).env_clear().envs(utf8_env.env);

For the Python implementation:

import subprocess import utf8_locale utf8env = utf8_locale.Utf8Detect().detect() subprocess.check_output([...], encoding="UTF-8", env=utf8env.env)


The source of the utf8-locale library may be obtained at its devel.ringlet.net homepage. It is developed in a GitLab Git repository.

The current version of utf8-locale is utf8-locale-0.3.0:


Peter Pentchev roam@ringlet.net