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
13 changes: 13 additions & 0 deletions src/uu/unexpand/locales/en-US.ftl
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
unexpand-about = Convert blanks in each FILE to tabs, writing to standard output.
With no FILE, or when FILE is -, read standard input.
unexpand-usage = unexpand [OPTION]... [FILE]...

# Help messages
unexpand-help-all = convert all blanks, instead of just initial blanks
unexpand-help-first-only = convert only leading sequences of blanks (overrides -a)
unexpand-help-tabs = use comma separated LIST of tab positions or have tabs N characters apart instead of 8 (enables -a)
unexpand-help-no-utf8 = interpret input file as 8-bit ASCII rather than UTF-8

# Error messages
unexpand-error-invalid-character = tab size contains invalid character(s): { $char }
unexpand-error-tab-size-cannot-be-zero = tab size cannot be 0
unexpand-error-tab-size-too-large = tab stop value is too large
unexpand-error-tab-sizes-must-be-ascending = tab sizes must be ascending
unexpand-error-is-directory = { $path }: Is a directory
16 changes: 16 additions & 0 deletions src/uu/unexpand/locales/fr-FR.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
unexpand-about = Convertir les espaces dans chaque FICHIER en tabulations, en écrivant vers la sortie standard.
Sans FICHIER, ou quand FICHIER est -, lire l'entrée standard.
unexpand-usage = unexpand [OPTION]... [FICHIER]...

# Messages d'aide
unexpand-help-all = convertir tous les espaces, au lieu de seulement les espaces initiaux
unexpand-help-first-only = convertir seulement les séquences d'espaces en début de ligne (remplace -a)
unexpand-help-tabs = utiliser une LISTE séparée par des virgules de positions de tabulations ou avoir des tabulations de N caractères au lieu de 8 (active -a)
unexpand-help-no-utf8 = interpréter le fichier d'entrée comme ASCII 8-bit plutôt que UTF-8

# Messages d'erreur
unexpand-error-invalid-character = la taille de tabulation contient des caractères invalides : { $char }
unexpand-error-tab-size-cannot-be-zero = la taille de tabulation ne peut pas être 0
unexpand-error-tab-size-too-large = la valeur d'arrêt de tabulation est trop grande
unexpand-error-tab-sizes-must-be-ascending = les tailles de tabulation doivent être croissantes
unexpand-error-is-directory = { $path } : Est un répertoire
27 changes: 14 additions & 13 deletions src/uu/unexpand/src/unexpand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// spell-checker:ignore (ToDO) nums aflag uflag scol prevtab amode ctype cwidth nbytes lastcol pctype Preprocess

use clap::{Arg, ArgAction, Command};
use std::collections::HashMap;
use std::fs::File;
use std::io::{BufRead, BufReader, BufWriter, Read, Stdout, Write, stdin, stdout};
use std::num::IntErrorKind;
Expand All @@ -17,19 +18,19 @@ use uucore::display::Quotable;
use uucore::error::{FromIo, UError, UResult, USimpleError};
use uucore::{format_usage, show};

use uucore::locale::get_message;
use uucore::locale::{get_message, get_message_with_args};

const DEFAULT_TABSTOP: usize = 8;

#[derive(Debug, Error)]
enum ParseError {
#[error("tab size contains invalid character(s): {}", _0.quote())]
#[error("{}", get_message_with_args("unexpand-error-invalid-character", HashMap::from([("char".to_string(), _0.quote().to_string())])))]
InvalidCharacter(String),
#[error("tab size cannot be 0")]
#[error("{}", get_message("unexpand-error-tab-size-cannot-be-zero"))]
TabSizeCannotBeZero,
#[error("tab stop value is too large")]
#[error("{}", get_message("unexpand-error-tab-size-too-large"))]
TabSizeTooLarge,
#[error("tab sizes must be ascending")]
#[error("{}", get_message("unexpand-error-tab-sizes-must-be-ascending"))]
TabSizesMustBeAscending,
}

Expand Down Expand Up @@ -169,31 +170,28 @@ pub fn uu_app() -> Command {
Arg::new(options::ALL)
.short('a')
.long(options::ALL)
.help("convert all blanks, instead of just initial blanks")
.help(get_message("unexpand-help-all"))
.action(ArgAction::SetTrue),
)
.arg(
Arg::new(options::FIRST_ONLY)
.long(options::FIRST_ONLY)
.help("convert only leading sequences of blanks (overrides -a)")
.help(get_message("unexpand-help-first-only"))
.action(ArgAction::SetTrue),
)
.arg(
Arg::new(options::TABS)
.short('t')
.long(options::TABS)
.help(
"use comma separated LIST of tab positions or have tabs N characters \
apart instead of 8 (enables -a)",
)
.help(get_message("unexpand-help-tabs"))
.action(ArgAction::Append)
.value_name("N, LIST"),
)
.arg(
Arg::new(options::NO_UTF8)
.short('U')
.long(options::NO_UTF8)
.help("interpret input file as 8-bit ASCII rather than UTF-8")
.help(get_message("unexpand-help-no-utf8"))
.action(ArgAction::SetTrue),
)
}
Expand All @@ -204,7 +202,10 @@ fn open(path: &str) -> UResult<BufReader<Box<dyn Read + 'static>>> {
if filename.is_dir() {
Err(Box::new(USimpleError {
code: 1,
message: format!("{}: Is a directory", filename.display()),
message: get_message_with_args(
"unexpand-error-is-directory",
HashMap::from([("path".to_string(), filename.display().to_string())]),
),
}))
} else if path == "-" {
Ok(BufReader::new(Box::new(stdin()) as Box<dyn Read>))
Expand Down
Loading