Skip to content

locale: honor LC_ALL and LC_MESSAGES precedence over LANG - #13331

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

costajohnt wants to merge 1 commit into
uutils:mainfrom
costajohnt:fix/8922-lc-all-locale-precedence

Conversation

@costajohnt

@costajohnt costajohnt commented Jul 9, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #8922.

Message locale detection only read LANG, so LC_ALL and LC_MESSAGES were ignored. GNU honors all three, so LC_ALL=fr_FR.UTF-8 sleep --help prints French there and English in uutils.

This applies the POSIX precedence LC_ALL > LC_MESSAGES > LANG. The first non-empty value wins, and with none set it falls back to en-US as before. LC_ALL=C still resolves to English through the existing fallback, so the English fast path from #16907 is unchanged.

The lookup is a small get_locale_env_var(category) helper in locale.rs, shared with i18n::get_locale_from_env, which already did the same thing for other categories. docs/src/l10n.md is updated to match.

Tests

  • Table test for the precedence (LC_ALL wins, LC_MESSAGES over LANG, empty counts as unset, nothing set falls back), plus LC_ALL=C with LANG=fr_FR giving English.
  • test_env_lc_all_c_overrides_lang end to end.
  • Tests that picked French through LANG alone now use LC_ALL, since the test harness sets LC_ALL=C.

GNU tests

The GNU cut, expr, fold, join and uniq perl tests run their multibyte cases with LC_ALL=fr_FR.UTF-8 and expect English diagnostics, relying on LANGUAGE=C. Without LANGUAGE support they would now get French, so build-gnu.sh moves those to LANG and pins LC_MESSAGES=C. This sed and the shared lookup come from #14870 (its author is credited on the commit). Locally tests/cut/cut.pl had 45 French-stderr failures without it and passes with it.

LANGUAGE support will come as a separate PR.

@github-actions

github-actions Bot commented Jul 10, 2026 •

Copy link
Copy Markdown

GNU testsuite comparison:

Skipping an intermittent issue tests/misc/usage_vs_getopt (passes in this run but fails in the 'main' branch)

@codspeed

codspeed Bot commented Jul 12, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

1 warning

⚠️ 2 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

✅ 2 untouched benchmarks
⏩ 488 skipped benchmarks1


Comparing costajohnt:fix/8922-lc-all-locale-precedence (1c90fa1) with main (0c4b68f)

Open in CodSpeed

Footnotes

  1. 488 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@costajohnt
costajohnt force-pushed the fix/8922-lc-all-locale-precedence branch 2 times, most recently from 181d188 to 14822ba Compare July 20, 2026 04:45
@github-actions

github-actions Bot commented Aug 27, 2026 •

Copy link
Copy Markdown

Binary size comparison:

Individual binary size comparison VS main (threshold: >=5% AND >=4 KB).

Total size of compared binaries: 158.29 MB (+2.90 MB, +1.87%)

Significant per-binary changes:
  env     1.20 MB ->    1.30 MB  (+108 KB, +8.79%)

@sylvestre
sylvestre force-pushed the fix/8922-lc-all-locale-precedence branch from c557bb2 to 913aa3f Compare August 27, 2026 21:22
@costajohnt
costajohnt force-pushed the fix/8922-lc-all-locale-precedence branch from 913aa3f to 12c9701 Compare October 6, 2026 17:36
@costajohnt
costajohnt force-pushed the fix/8922-lc-all-locale-precedence branch from 12c9701 to 508efc9 Compare October 25, 2026 00:41
@RenjiSann
RenjiSann force-pushed the fix/8922-lc-all-locale-precedence branch from 1bf0246 to d08925e Compare October 26, 2026 01:04
@costajohnt

Copy link
Copy Markdown
Contributor Author

Anything else needed from my side here? Checks are green and it merges cleanly.

@sylvestre
sylvestre force-pushed the fix/8922-lc-all-locale-precedence branch 2 times, most recently from 5dddf46 to e4cffed Compare November 8, 2026 11:35
@costajohnt
costajohnt force-pushed the fix/8922-lc-all-locale-precedence branch from e4cffed to dbdf3c7 Compare November 16, 2026 18:47
@sylvestre
sylvestre force-pushed the fix/8922-lc-all-locale-precedence branch from dbdf3c7 to 793c2ee Compare November 18, 2026 08:54
Comment thread src/uucore/src/lib/mods/locale.rs Outdated
return default();
}

if let Some(language) = lookup("LANGUAGE").filter(|value| !value.is_empty()) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

the LANGUAGE handling isn't in the description and isn't needed for #8922.
please split it into a separate PR and keep this one to LC_ALL/LC_MESSAGES

Comment thread src/uucore/src/lib/mods/locale.rs Outdated
LanguageIdentifier::from_str(&locale_str).map_err(|_| {
LocalizationError::ParseLocale(format!("Failed to parse locale: {locale_str}"))
})
/// Resolve the message-locale candidates from an environment lookup, applying

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nobody will read a 25-line comment :) please make it shorter

Comment thread src/uucore/src/lib/mods/locale.rs Outdated
catalogs
}

thread_local! {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

do we need this cache? the locales dir has only a few files

Comment thread src/uucore/src/lib/mods/locale.rs Outdated
/// gettext's territory stripping. Only consulted when there is no exact
/// catalog.
///
/// [`DEFAULT_LOCALE`] is never returned: `en-US.ftl` always exists, so

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

please make this comment shorter too

Comment thread src/uucore/src/lib/mods/locale.rs Outdated
let localized = locales
.iter()
.take_while(|locale| **locale != default_locale)
.find_map(|locale| create_wasi_bundle_from_embedded(locale, p).ok());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why does wasi not get the same-language fallback?

Message locale detection only read LANG. Use the POSIX order
LC_ALL > LC_MESSAGES > LANG, skipping empty values, and share the
lookup with i18n::get_locale_from_env.

Tests that selected French through LANG alone now set LC_ALL, since
the test harness sets LC_ALL=C by default. The GNU cut, expr, fold,
join and uniq tests select their multibyte locale through LC_ALL while
expecting English diagnostics, so build-gnu.sh moves that to LANG and
pins LC_MESSAGES=C.

Fixes uutils#8922

Co-authored-by: soldierboy <191002121+sunsss123soldier@users.noreply.github.com>
@costajohnt
costajohnt force-pushed the fix/8922-lc-all-locale-precedence branch from 793c2ee to 1c90fa1 Compare December 1, 2026 14:58
@costajohnt

Copy link
Copy Markdown
Contributor Author

Done, this is now just LC_ALL/LC_MESSAGES, rebased on main and squashed. Your list-walk commit and the rest of the LANGUAGE work are saved on a branch, and your comments on that code will be answered in the separate LANGUAGE PR, which explains the GNU motivation up front.

Without LANGUAGE, the GNU cut/expr/fold/join/uniq perl tests print French under their LC_ALL=fr_FR runs (cut.pl had 45 failures locally), so I took the build-gnu.sh sed and the shared lookup from #14870 and credited its author on the commit. That makes the two PRs overlap a lot now. Happy to close this one if you'd rather land #14870.

This branch has not been deployed

No deployments
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