From 2d0c9840ab4e47d84ef1909c17defddb656e9b0a Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Sat, 7 Jun 2025 18:58:47 +0200 Subject: [PATCH] l10n: port tsort to translation + add french --- src/uu/tsort/locales/en-US.ftl | 3 +++ src/uu/tsort/locales/fr-FR.ftl | 8 ++++++++ src/uu/tsort/src/tsort.rs | 11 ++++++----- 3 files changed, 17 insertions(+), 5 deletions(-) create mode 100644 src/uu/tsort/locales/fr-FR.ftl diff --git a/src/uu/tsort/locales/en-US.ftl b/src/uu/tsort/locales/en-US.ftl index 12cafe40c..a4b4218c3 100644 --- a/src/uu/tsort/locales/en-US.ftl +++ b/src/uu/tsort/locales/en-US.ftl @@ -3,3 +3,6 @@ tsort-about = Topological sort the strings in FILE. Useful for scheduling and determining execution order. If FILE is not passed in, stdin is used instead. tsort-usage = tsort [OPTIONS] FILE +tsort-error-is-dir = read error: Is a directory +tsort-error-odd = input contains an odd number of tokens +tsort-error-loop = input contains a loop: diff --git a/src/uu/tsort/locales/fr-FR.ftl b/src/uu/tsort/locales/fr-FR.ftl new file mode 100644 index 000000000..18349b978 --- /dev/null +++ b/src/uu/tsort/locales/fr-FR.ftl @@ -0,0 +1,8 @@ +tsort-about = Tri topologique des chaînes présentes dans FILE. + Les chaînes sont définies comme toute séquence de jetons séparés par des espaces (tabulation, espace ou saut de ligne), ordonnées selon les dépendances dans un graphe orienté acyclique (DAG). + Utile pour la planification et la détermination de l'ordre d'exécution. + Si FILE n'est pas fourni, l'entrée standard (stdin) est utilisée. +tsort-usage = tsort [OPTIONS] FILE +tsort-error-is-dir = erreur de lecture : c'est un répertoire +tsort-error-odd = l'entrée contient un nombre impair de jetons +tsort-error-loop = l'entrée contient une boucle : diff --git a/src/uu/tsort/src/tsort.rs b/src/uu/tsort/src/tsort.rs index 3a3a3c51c..4f273e621 100644 --- a/src/uu/tsort/src/tsort.rs +++ b/src/uu/tsort/src/tsort.rs @@ -20,18 +20,18 @@ mod options { #[derive(Debug, Error)] enum TsortError { /// The input file is actually a directory. - #[error("{0}: read error: Is a directory")] + #[error("{input}: {message}", input = .0, message = get_message("tsort-error-is-dir"))] IsDir(String), /// The number of tokens in the input data is odd. /// /// The list of edges must be even because each edge has two /// components: a source node and a target node. - #[error("{input}: input contains an odd number of tokens", input = .0.maybe_quote())] + #[error("{input}: {message}", input = .0.maybe_quote(), message = get_message("tsort-error-odd"))] NumTokensOdd(String), /// The graph contains a cycle. - #[error("{0}: input contains a loop:")] + #[error("{input}: {message}", input = .0, message = get_message("tsort-error-loop"))] Loop(String), /// A particular node in a cycle. (This is mainly used for printing.) @@ -72,6 +72,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { g.run_tsort(); Ok(()) } + pub fn uu_app() -> Command { Command::new(uucore::util_name()) .version(uucore::crate_version!()) @@ -147,7 +148,7 @@ impl<'input> Graph<'input> { /// Implementation of algorithm T from TAOCP (Don. Knuth), vol. 1. fn run_tsort(&mut self) { - // First, we find a node that have no prerequisites (independent nodes) + // First, we find nodes that have no prerequisites (independent nodes). // If no such node exists, then there is a cycle. let mut independent_nodes_queue: VecDeque<&'input str> = self .nodes @@ -177,7 +178,7 @@ impl<'input> Graph<'input> { let successor_node = self.nodes.get_mut(successor_name).unwrap(); successor_node.predecessor_count -= 1; if successor_node.predecessor_count == 0 { - // if we find nodes without any other prerequisites, we add them to the queue. + // If we find nodes without any other prerequisites, we add them to the queue. independent_nodes_queue.push_back(successor_name); } }