Cups support language idependent
This commit is contained in:
59
settings.pl
59
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<TR BGCOLOR="#ece0cf">\n\t\t<TD COLSPAN=2><B>CUPS printers detected on host</B></TD>\n\t</TR>\n\t<TR BGCOLOR="#fbf7f1">\n\t\t<TD COLSPAN=2><SMALL>CUPS support is enabled, but no printers were returned by lpstat.</SMALL></TD>\n\t</TR>\n|;
|
||||
}
|
||||
|
||||
$html .= qq|\t<TR BGCOLOR="#ece0cf">\n\t\t<TD COLSPAN=2><B>CUPS printers detected on host</B></TD>\n\t</TR>\n|;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user