Skip to content

fix(l10n): honor LC_ALL and LC_MESSAGES for locale detection (fixes #8922)#12348

Open
leno23 wants to merge 1 commit into
uutils:mainfrom
leno23:fix/locale-honor-lc-all-8922
Open

fix(l10n): honor LC_ALL and LC_MESSAGES for locale detection (fixes #8922)#12348
leno23 wants to merge 1 commit into
uutils:mainfrom
leno23:fix/locale-honor-lc-all-8922

Conversation

@leno23
Copy link
Copy Markdown
Contributor

@leno23 leno23 commented May 17, 2026

Summary

  • Detect locale from LC_ALL, then LC_MESSAGES, then LANG (GNU precedence).
  • Treat empty locale env vars as unset.
  • Add regression test ensuring LC_ALL overrides LANG.

Test plan

  • cargo test -p uucore test_detect_system_locale

Fixes #8922

Made with Cursor

GNU locale precedence uses LC_ALL before LANG; respect LC_MESSAGES as well
and treat empty env values as unset. Add regression test for LC_ALL.

Fixes uutils#8922

Co-authored-by: Cursor <cursoragent@cursor.com>
@github-actions
Copy link
Copy Markdown

GNU testsuite comparison:

GNU test failed: tests/expr/expr. tests/expr/expr is passing on 'main'. Maybe you have to rebase?
GNU test failed: tests/join/join. tests/join/join is passing on 'main'. Maybe you have to rebase?
GNU test failed: tests/uniq/uniq. tests/uniq/uniq is passing on 'main'. Maybe you have to rebase?
Skipping an intermittent issue tests/tail/pipe-f (passes in this run but fails in the 'main' branch)
Skipping an intermittent issue tests/tail/symlink (passes in this run but fails in the 'main' branch)

Comment on lines +422 to +425
let locale_str = locale_var("LC_ALL")
.or_else(|| locale_var("LC_MESSAGES"))
.or_else(|| locale_var("LANG"))
.unwrap_or_else(|| DEFAULT_LOCALE.to_string())
Copy link
Copy Markdown
Contributor

@xtqqczze xtqqczze May 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let locale_str = locale_var("LC_ALL")
.or_else(|| locale_var("LC_MESSAGES"))
.or_else(|| locale_var("LANG"))
.unwrap_or_else(|| DEFAULT_LOCALE.to_string())
let locale_str = ["LC_ALL", "LC_MESSAGES", "LANG"]
.into_iter()
.find_map(|k| std::env::var(k).ok().filter(|v| !v.is_empty()))
.as_deref()
.unwrap_or(DEFAULT_LOCALE)

@xtqqczze
Copy link
Copy Markdown
Contributor

cargo test test_env_french is failing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

l10n: LC_ALL is ignored

2 participants