|
Line 0
Link Here
|
| 0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
| 3 |
use Modern::Perl; |
| 4 |
use Data::Dumper; |
| 5 |
use FindBin qw($Bin); |
| 6 |
|
| 7 |
my $localedir = $Bin; |
| 8 |
my $installdir = "$localedir/.."; |
| 9 |
|
| 10 |
# Directories are not scanned recursively |
| 11 |
my @directories_to_scan = qw( |
| 12 |
. C4 acqui admin authorities basket catalogue cataloguing circ errors |
| 13 |
Koha labels members misc offline_circ opac patroncards reports |
| 14 |
reserve reviews rotating_collections serials services sms suggestion tags |
| 15 |
tools virtualshelves |
| 16 |
); |
| 17 |
|
| 18 |
# Build files list |
| 19 |
my @files_to_scan; |
| 20 |
foreach my $dir (@directories_to_scan) { |
| 21 |
opendir DIR, "$installdir/$dir" or die "Unable to open $dir: $!"; |
| 22 |
while (readdir DIR) { |
| 23 |
next unless ( -f "$installdir/$dir/$_" ); |
| 24 |
next unless ( $_ =~ /(\.pl|\.pm)$/ ); |
| 25 |
push @files_to_scan, "$dir/$_"; |
| 26 |
} |
| 27 |
closedir DIR; |
| 28 |
} |
| 29 |
|
| 30 |
# Build languages list |
| 31 |
my @langs; |
| 32 |
opendir DIR, $localedir; |
| 33 |
while (readdir DIR) { |
| 34 |
next unless ( -d "$localedir/$_" ); |
| 35 |
next if ($_ eq '.' or $_ eq '..'); |
| 36 |
push @langs, $_; |
| 37 |
} |
| 38 |
close DIR; |
| 39 |
|
| 40 |
my $xgettext = `which xgettext`; |
| 41 |
chomp $xgettext; |
| 42 |
my $xgettext_cmd = "$xgettext -L Perl --from-code=UTF-8 -kmaketext -o messages.pot"; |
| 43 |
$xgettext_cmd .= " -D $installdir/$_" foreach (@directories_to_scan); |
| 44 |
$xgettext_cmd .= " $_" foreach (@files_to_scan); |
| 45 |
|
| 46 |
say "Extracting strings from source..."; |
| 47 |
if (system($xgettext_cmd) != 0) { |
| 48 |
die "system call failed : $xgettext_cmd"; |
| 49 |
} |
| 50 |
|
| 51 |
foreach my $lang (@langs) { |
| 52 |
if ( -f "$localedir/$lang/messages.po" ) { |
| 53 |
say "Updating $lang..."; |
| 54 |
system("msgmerge -U $localedir/$lang/messages.po messages.pot"); |
| 55 |
} else { |
| 56 |
say "No PO file for $lang. Creating one..."; |
| 57 |
system("cp messages.pot $localedir/$lang/messages.po"); |
| 58 |
} |
| 59 |
} |
| 60 |
|
| 61 |
unlink "messages.pot"; |