From 544afcd2966c307a22b09b52b5dfa7084a37675c Mon Sep 17 00:00:00 2001 From: Mario Fetka Date: Thu, 21 May 2026 19:12:55 +0200 Subject: [PATCH] Cups support language idependent --- settings.pl | 59 +++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 50 insertions(+), 9 deletions(-) diff --git a/settings.pl b/settings.pl index fb38a30..c12d79a 100644 --- a/settings.pl +++ b/settings.pl @@ -254,20 +254,50 @@ sub cups_printers() return () if $lpstat eq ''; - if( open( my $fh, '-|', $lpstat, '-v' ) ) + # Prefer lpstat -e: it prints one destination name per line and is + # independent of translated words like "printer" / "Drucker". + if( open( my $fh, '-|', $lpstat, '-e' ) ) { while( my $line = <$fh> ) { chomp( $line ); - if( $line =~ /^device\s+for\s+([^:\s]+):/i ) - { - my $printer = sanitize_cups_printer_name( $1 ); - $printers{$printer} = 1 if $printer ne ''; - } + $line =~ s/^\s+//; + $line =~ s/\s+$//; + next if $line eq ''; + + my $printer = sanitize_cups_printer_name( ( split( /\s+/, $line ) )[0] ); + $printers{$printer} = 1 if $printer ne ''; } close( $fh ); } + # Fallback: English "device for NAME:" and German "Gerät für NAME:". + if( scalar( keys( %printers ) ) == 0 ) + { + if( open( my $fh, '-|', $lpstat, '-v' ) ) + { + while( my $line = <$fh> ) + { + chomp( $line ); + + my $printer = ''; + if( $line =~ /^device\s+for\s+([^:\s]+):/i ) + { + $printer = $1; + } + elsif( $line =~ /^ger\S*\s+f\S*r\s+([^:\s]+):/i ) + { + $printer = $1; + } + + $printer = sanitize_cups_printer_name( $printer ); + $printers{$printer} = 1 if $printer ne ''; + } + close( $fh ); + } + } + + # Fallback: English "printer NAME ..." and German "Drucker NAME ...". if( scalar( keys( %printers ) ) == 0 ) { if( open( my $fh, '-|', $lpstat, '-p' ) ) @@ -275,11 +305,19 @@ sub cups_printers() while( my $line = <$fh> ) { chomp( $line ); + + my $printer = ''; if( $line =~ /^printer\s+(\S+)/i ) { - my $printer = sanitize_cups_printer_name( $1 ); - $printers{$printer} = 1 if $printer ne ''; + $printer = $1; } + elsif( $line =~ /^drucker\s+(\S+)/i ) + { + $printer = $1; + } + + $printer = sanitize_cups_printer_name( $printer ); + $printers{$printer} = 1 if $printer ne ''; } close( $fh ); } @@ -293,7 +331,10 @@ sub cups_import_rows() my $html = ''; my @printers = cups_printers(); - return '' if scalar( @printers ) == 0; + if( scalar( @printers ) == 0 ) + { + return qq|\t\n\t\tCUPS printers detected on host\n\t\n\t\n\t\tCUPS support is enabled, but no printers were returned by lpstat.\n\t\n|; + } $html .= qq|\t\n\t\tCUPS printers detected on host\n\t\n|;