4
4
// file that was distributed with this source code.
5
5
6
6
use clap:: { Arg , ArgAction , Command } ;
7
+ use std:: collections:: HashMap ;
7
8
use std:: fs:: File ;
8
9
use std:: io:: { BufRead , BufReader , Read , stdin} ;
9
10
use std:: path:: Path ;
10
11
use uucore:: error:: { FromIo , UResult , USimpleError , set_exit_code} ;
11
- use uucore:: locale:: get_message;
12
+ use uucore:: locale:: { get_message, get_message_with_args } ;
12
13
use uucore:: { format_usage, show_error} ;
13
14
14
15
mod helper;
@@ -89,9 +90,12 @@ impl TryFrom<&str> for NumberingStyle {
89
90
"n" => Ok ( Self :: None ) ,
90
91
_ if s. starts_with ( 'p' ) => match regex:: Regex :: new ( & s[ 1 ..] ) {
91
92
Ok ( re) => Ok ( Self :: Regex ( Box :: new ( re) ) ) ,
92
- Err ( _) => Err ( String :: from ( " invalid regular expression ") ) ,
93
+ Err ( _) => Err ( get_message ( "nl-error- invalid-regex ") ) ,
93
94
} ,
94
- _ => Err ( format ! ( "invalid numbering style: '{s}'" ) ) ,
95
+ _ => Err ( get_message_with_args (
96
+ "nl-error-invalid-numbering-style" ,
97
+ HashMap :: from ( [ ( "style" . to_string ( ) , s. to_string ( ) ) ] ) ,
98
+ ) ) ,
95
99
}
96
100
}
97
101
}
@@ -185,7 +189,11 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
185
189
if !parse_errors. is_empty ( ) {
186
190
return Err ( USimpleError :: new (
187
191
1 ,
188
- format ! ( "Invalid arguments supplied.\n {}" , parse_errors. join( "\n " ) ) ,
192
+ format ! (
193
+ "{}\n {}" ,
194
+ get_message( "nl-error-invalid-arguments" ) ,
195
+ parse_errors. join( "\n " )
196
+ ) ,
189
197
) ) ;
190
198
}
191
199
@@ -204,7 +212,13 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
204
212
let path = Path :: new ( file) ;
205
213
206
214
if path. is_dir ( ) {
207
- show_error ! ( "{}: Is a directory" , path. display( ) ) ;
215
+ show_error ! (
216
+ "{}" ,
217
+ get_message_with_args(
218
+ "nl-error-is-directory" ,
219
+ HashMap :: from( [ ( "path" . to_string( ) , path. display( ) . to_string( ) ) ] )
220
+ )
221
+ ) ;
208
222
set_exit_code ( 1 ) ;
209
223
} else {
210
224
let reader = File :: open ( path) . map_err_context ( || file. to_string ( ) ) ?;
@@ -228,7 +242,7 @@ pub fn uu_app() -> Command {
228
242
. arg (
229
243
Arg :: new ( options:: HELP )
230
244
. long ( options:: HELP )
231
- . help ( "Print help information." )
245
+ . help ( get_message ( "nl- help-help" ) )
232
246
. action ( ArgAction :: Help ) ,
233
247
)
234
248
. arg (
@@ -241,81 +255,81 @@ pub fn uu_app() -> Command {
241
255
Arg :: new ( options:: BODY_NUMBERING )
242
256
. short ( 'b' )
243
257
. long ( options:: BODY_NUMBERING )
244
- . help ( "use STYLE for numbering body lines" )
258
+ . help ( get_message ( "nl-help- body-numbering" ) )
245
259
. value_name ( "STYLE" ) ,
246
260
)
247
261
. arg (
248
262
Arg :: new ( options:: SECTION_DELIMITER )
249
263
. short ( 'd' )
250
264
. long ( options:: SECTION_DELIMITER )
251
- . help ( "use CC for separating logical pages" )
265
+ . help ( get_message ( "nl-help-section-delimiter" ) )
252
266
. value_name ( "CC" ) ,
253
267
)
254
268
. arg (
255
269
Arg :: new ( options:: FOOTER_NUMBERING )
256
270
. short ( 'f' )
257
271
. long ( options:: FOOTER_NUMBERING )
258
- . help ( "use STYLE for numbering footer lines" )
272
+ . help ( get_message ( "nl-help- footer-numbering" ) )
259
273
. value_name ( "STYLE" ) ,
260
274
)
261
275
. arg (
262
276
Arg :: new ( options:: HEADER_NUMBERING )
263
277
. short ( 'h' )
264
278
. long ( options:: HEADER_NUMBERING )
265
- . help ( "use STYLE for numbering header lines" )
279
+ . help ( get_message ( "nl-help- header-numbering" ) )
266
280
. value_name ( "STYLE" ) ,
267
281
)
268
282
. arg (
269
283
Arg :: new ( options:: LINE_INCREMENT )
270
284
. short ( 'i' )
271
285
. long ( options:: LINE_INCREMENT )
272
- . help ( " line number increment at each line" )
286
+ . help ( get_message ( "nl-help- line- increment" ) )
273
287
. value_name ( "NUMBER" )
274
288
. value_parser ( clap:: value_parser!( i64 ) ) ,
275
289
)
276
290
. arg (
277
291
Arg :: new ( options:: JOIN_BLANK_LINES )
278
292
. short ( 'l' )
279
293
. long ( options:: JOIN_BLANK_LINES )
280
- . help ( "group of NUMBER empty lines counted as one" )
294
+ . help ( get_message ( "nl-help-join-blank- lines" ) )
281
295
. value_name ( "NUMBER" )
282
296
. value_parser ( clap:: value_parser!( u64 ) ) ,
283
297
)
284
298
. arg (
285
299
Arg :: new ( options:: NUMBER_FORMAT )
286
300
. short ( 'n' )
287
301
. long ( options:: NUMBER_FORMAT )
288
- . help ( "insert line numbers according to FORMAT" )
302
+ . help ( get_message ( "nl-help-number-format" ) )
289
303
. value_name ( "FORMAT" )
290
304
. value_parser ( [ "ln" , "rn" , "rz" ] ) ,
291
305
)
292
306
. arg (
293
307
Arg :: new ( options:: NO_RENUMBER )
294
308
. short ( 'p' )
295
309
. long ( options:: NO_RENUMBER )
296
- . help ( "do not reset line numbers at logical pages" )
310
+ . help ( get_message ( "nl-help-no-renumber" ) )
297
311
. action ( ArgAction :: SetFalse ) ,
298
312
)
299
313
. arg (
300
314
Arg :: new ( options:: NUMBER_SEPARATOR )
301
315
. short ( 's' )
302
316
. long ( options:: NUMBER_SEPARATOR )
303
- . help ( "add STRING after (possible) line number" )
317
+ . help ( get_message ( "nl-help- number-separator" ) )
304
318
. value_name ( "STRING" ) ,
305
319
)
306
320
. arg (
307
321
Arg :: new ( options:: STARTING_LINE_NUMBER )
308
322
. short ( 'v' )
309
323
. long ( options:: STARTING_LINE_NUMBER )
310
- . help ( "first line number on each logical page" )
324
+ . help ( get_message ( "nl-help-starting- line- number" ) )
311
325
. value_name ( "NUMBER" )
312
326
. value_parser ( clap:: value_parser!( i64 ) ) ,
313
327
)
314
328
. arg (
315
329
Arg :: new ( options:: NUMBER_WIDTH )
316
330
. short ( 'w' )
317
331
. long ( options:: NUMBER_WIDTH )
318
- . help ( "use NUMBER columns for line numbers" )
332
+ . help ( get_message ( "nl-help-number-width" ) )
319
333
. value_name ( "NUMBER" )
320
334
. value_parser ( clap:: value_parser!( usize ) ) ,
321
335
)
@@ -326,7 +340,7 @@ fn nl<T: Read>(reader: &mut BufReader<T>, stats: &mut Stats, settings: &Settings
326
340
let mut current_numbering_style = & settings. body_numbering ;
327
341
328
342
for line in reader. lines ( ) {
329
- let line = line. map_err_context ( || " could not read line". to_string ( ) ) ?;
343
+ let line = line. map_err_context ( || get_message ( "nl-error- could- not- read- line") ) ?;
330
344
331
345
if line. is_empty ( ) {
332
346
stats. consecutive_empty_lines += 1 ;
@@ -366,7 +380,10 @@ fn nl<T: Read>(reader: &mut BufReader<T>, stats: &mut Stats, settings: &Settings
366
380
367
381
if is_line_numbered {
368
382
let Some ( line_number) = stats. line_number else {
369
- return Err ( USimpleError :: new ( 1 , "line number overflow" ) ) ;
383
+ return Err ( USimpleError :: new (
384
+ 1 ,
385
+ get_message ( "nl-error-line-number-overflow" ) ,
386
+ ) ) ;
370
387
} ;
371
388
println ! (
372
389
"{}{}{line}" ,
0 commit comments