@@ -11,19 +11,20 @@ use crate::uu_app;
1111use uucore:: display:: Quotable ;
1212use uucore:: error:: { FromIo , UResult } ;
1313use uucore:: libc:: { S_IWGRP , STDIN_FILENO , ttyname} ;
14+ use uucore:: locale:: { get_message, get_message_with_args} ;
1415use uucore:: utmpx:: { self , Utmpx , time} ;
1516
1617use std:: borrow:: Cow ;
18+ use std:: collections:: HashMap ;
1719use std:: ffi:: CStr ;
1820use std:: fmt:: Write ;
1921use std:: os:: unix:: fs:: MetadataExt ;
2022use std:: path:: PathBuf ;
2123
2224fn get_long_usage ( ) -> String {
23- format ! (
24- "If FILE is not specified, use {}. /var/log/wtmp as FILE is common.\n \
25- If ARG1 ARG2 given, -m presumed: 'am i' or 'mom likes' are usual.",
26- utmpx:: DEFAULT_FILE ,
25+ get_message_with_args (
26+ "who-long-usage" ,
27+ HashMap :: from ( [ ( "default_file" . to_string ( ) , utmpx:: DEFAULT_FILE . to_string ( ) ) ] ) ,
2728 )
2829}
2930
@@ -158,7 +159,7 @@ fn idle_string<'a>(when: i64, boottime: i64) -> Cow<'a, str> {
158159 . into ( )
159160 }
160161 } else {
161- " old " . into ( )
162+ get_message ( "who-idle- old" ) . into ( )
162163 }
163164 } )
164165}
@@ -208,7 +209,13 @@ impl Who {
208209 . map ( |ut| ut. user ( ) )
209210 . collect :: < Vec < _ > > ( ) ;
210211 println ! ( "{}" , users. join( " " ) ) ;
211- println ! ( "# users={}" , users. len( ) ) ;
212+ println ! (
213+ "{}" ,
214+ get_message_with_args(
215+ "who-user-count" ,
216+ HashMap :: from( [ ( "count" . to_string( ) , users. len( ) . to_string( ) ) ] )
217+ )
218+ ) ;
212219 } else {
213220 let records = Utmpx :: iter_all_records_from ( f) ;
214221
@@ -252,8 +259,17 @@ impl Who {
252259 fn print_runlevel ( & self , ut : & Utmpx ) {
253260 let last = ( ut. pid ( ) / 256 ) as u8 as char ;
254261 let curr = ( ut. pid ( ) % 256 ) as u8 as char ;
255- let runlvline = format ! ( "run-level {curr}" ) ;
256- let comment = format ! ( "last={}" , if last == 'N' { 'S' } else { 'N' } ) ;
262+ let runlvline = get_message_with_args (
263+ "who-runlevel" ,
264+ HashMap :: from ( [ ( "level" . to_string ( ) , curr. to_string ( ) ) ] ) ,
265+ ) ;
266+ let comment = get_message_with_args (
267+ "who-runlevel-last" ,
268+ HashMap :: from ( [ (
269+ "last" . to_string ( ) ,
270+ ( if last == 'N' { 'S' } else { 'N' } ) . to_string ( ) ,
271+ ) ] ) ,
272+ ) ;
257273
258274 self . print_line (
259275 "" ,
@@ -269,15 +285,27 @@ impl Who {
269285
270286 #[ inline]
271287 fn print_clockchange ( & self , ut : & Utmpx ) {
272- self . print_line ( "" , ' ' , "clock change" , & time_string ( ut) , "" , "" , "" , "" ) ;
288+ self . print_line (
289+ "" ,
290+ ' ' ,
291+ & get_message ( "who-clock-change" ) ,
292+ & time_string ( ut) ,
293+ "" ,
294+ "" ,
295+ "" ,
296+ "" ,
297+ ) ;
273298 }
274299
275300 #[ inline]
276301 fn print_login ( & self , ut : & Utmpx ) {
277- let comment = format ! ( "id={}" , ut. terminal_suffix( ) ) ;
302+ let comment = get_message_with_args (
303+ "who-login-id" ,
304+ HashMap :: from ( [ ( "id" . to_string ( ) , ut. terminal_suffix ( ) . to_string ( ) ) ] ) ,
305+ ) ;
278306 let pidstr = format ! ( "{}" , ut. pid( ) ) ;
279307 self . print_line (
280- "LOGIN" ,
308+ & get_message ( "who-login" ) ,
281309 ' ' ,
282310 & ut. tty_device ( ) ,
283311 & time_string ( ut) ,
@@ -290,10 +318,19 @@ impl Who {
290318
291319 #[ inline]
292320 fn print_deadprocs ( & self , ut : & Utmpx ) {
293- let comment = format ! ( "id={}" , ut. terminal_suffix( ) ) ;
321+ let comment = get_message_with_args (
322+ "who-login-id" ,
323+ HashMap :: from ( [ ( "id" . to_string ( ) , ut. terminal_suffix ( ) . to_string ( ) ) ] ) ,
324+ ) ;
294325 let pidstr = format ! ( "{}" , ut. pid( ) ) ;
295326 let e = ut. exit_status ( ) ;
296- let exitstr = format ! ( "term={} exit={}" , e. 0 , e. 1 ) ;
327+ let exitstr = get_message_with_args (
328+ "who-dead-exit-status" ,
329+ HashMap :: from ( [
330+ ( "term" . to_string ( ) , e. 0 . to_string ( ) ) ,
331+ ( "exit" . to_string ( ) , e. 1 . to_string ( ) ) ,
332+ ] ) ,
333+ ) ;
297334 self . print_line (
298335 "" ,
299336 ' ' ,
@@ -308,7 +345,10 @@ impl Who {
308345
309346 #[ inline]
310347 fn print_initspawn ( & self , ut : & Utmpx ) {
311- let comment = format ! ( "id={}" , ut. terminal_suffix( ) ) ;
348+ let comment = get_message_with_args (
349+ "who-login-id" ,
350+ HashMap :: from ( [ ( "id" . to_string ( ) , ut. terminal_suffix ( ) . to_string ( ) ) ] ) ,
351+ ) ;
312352 let pidstr = format ! ( "{}" , ut. pid( ) ) ;
313353 self . print_line (
314354 "" ,
@@ -324,7 +364,16 @@ impl Who {
324364
325365 #[ inline]
326366 fn print_boottime ( & self , ut : & Utmpx ) {
327- self . print_line ( "" , ' ' , "system boot" , & time_string ( ut) , "" , "" , "" , "" ) ;
367+ self . print_line (
368+ "" ,
369+ ' ' ,
370+ & get_message ( "who-system-boot" ) ,
371+ & time_string ( ut) ,
372+ "" ,
373+ "" ,
374+ "" ,
375+ "" ,
376+ ) ;
328377 }
329378
330379 fn print_user ( & self , ut : & Utmpx ) -> UResult < ( ) > {
@@ -352,18 +401,22 @@ impl Who {
352401 }
353402
354403 let idle = if last_change == 0 {
355- " ?" . into ( )
404+ get_message ( "who-idle-unknown" ) . into ( )
356405 } else {
357406 idle_string ( last_change, 0 )
358407 } ;
359408
360409 let s = if self . do_lookup {
361410 ut. canon_host ( ) . map_err_context ( || {
362411 let host = ut. host ( ) ;
363- format ! (
364- "failed to canonicalize {}" ,
365- host. split( ':' ) . next( ) . unwrap_or( & host) . quote( )
412+ get_message_with_args (
413+ "who-canonicalize-error" ,
414+ HashMap :: from ( [ (
415+ "host" . to_string ( ) ,
416+ host. split ( ':' ) . next ( ) . unwrap_or ( & host) . quote ( ) . to_string ( ) ,
417+ ) ] ) ,
366418 )
419+ . to_string ( )
367420 } ) ?
368421 } else {
369422 ut. host ( )
@@ -424,7 +477,14 @@ impl Who {
424477 #[ inline]
425478 fn print_heading ( & self ) {
426479 self . print_line (
427- "NAME" , ' ' , "LINE" , "TIME" , "IDLE" , "PID" , "COMMENT" , "EXIT" ,
480+ & get_message ( "who-heading-name" ) ,
481+ ' ' ,
482+ & get_message ( "who-heading-line" ) ,
483+ & get_message ( "who-heading-time" ) ,
484+ & get_message ( "who-heading-idle" ) ,
485+ & get_message ( "who-heading-pid" ) ,
486+ & get_message ( "who-heading-comment" ) ,
487+ & get_message ( "who-heading-exit" ) ,
428488 ) ;
429489 }
430490}
0 commit comments