Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/uu/sort/locales/en-US.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ sort-failed-to-set-up-signal-handler = failed to set up signal handler: {$error}
# Warning messages
sort-warning-failed-to-set-locale = failed to set locale
sort-warning-simple-byte-comparison = text ordering performed using simple byte comparison
sort-warning-sort-rule = text ordering performed using ‘{$locale}’ sorting rules
sort-warning-key-zero-width = key {$key} has zero width and will be ignored
sort-warning-key-numeric-spans-fields = key {$key} is numeric and spans multiple fields
sort-warning-leading-blanks-significant = leading blanks are significant in key {$key}; consider also specifying 'b'
Expand Down
12 changes: 11 additions & 1 deletion src/uu/sort/src/sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1797,7 +1797,17 @@ fn emit_debug_warnings(
show_error!("{}", translate!("sort-warning-failed-to-set-locale"));
}

show_error!("{}", translate!("sort-warning-simple-byte-comparison"));
let (locale, encoding) = i18n::get_collating_locale();

if matches!(encoding, i18n::UEncoding::Utf8) {
let locale_as_posix = format!("{}.UTF-8", locale.to_string().replace('-', "_"));
show_error!(
"{}",
translate!("sort-warning-sort-rule", "locale" => locale_as_posix)
);
} else {
show_error!("{}", translate!("sort-warning-simple-byte-comparison"));
}

for (idx, selector) in settings.selectors.iter().enumerate() {
let key_index = idx + 1;
Expand Down
2 changes: 1 addition & 1 deletion src/uucore/src/lib/features/i18n/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ pub fn get_locale_from_env(locale_name: &str) -> (Locale, UEncoding) {
}

/// Get the collating locale from the environment
fn get_collating_locale() -> &'static (Locale, UEncoding) {
pub fn get_collating_locale() -> &'static (Locale, UEncoding) {
static COLLATING_LOCALE: OnceLock<(Locale, UEncoding)> = OnceLock::new();

COLLATING_LOCALE.get_or_init(|| get_locale_from_env("LC_COLLATE"))
Expand Down
20 changes: 20 additions & 0 deletions tests/by-util/test_sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2713,6 +2713,26 @@ fn test_locale_complex_utf8_sorting() {
.stdout_is("apple\nApple\nbanana\nBanana\nzebra\nZebra\n");
}

#[test]
fn test_locale_posix_sort_debug_message() {
new_ucmd!()
.env("LC_ALL", "C")
.arg("--debug")
.pipe_in("a\nA\nb\nB\n")
.succeeds()
.stderr_contains("text ordering performed using simple byte comparison");
}

#[test]
fn test_locale_utf8_sort_debug_message() {
new_ucmd!()
.env("LC_ALL", "en_US.UTF-8")
.arg("--debug")
.pipe_in("a\nA\nb\nB\n")
.succeeds()
.stderr_contains("text ordering performed using ‘en_US.UTF-8’ sorting rules");
}

#[test]
fn test_locale_utf8_with_key_field() {
// Regression test for issue #10909
Expand Down
Loading