| 1 | #! /usr/bin/perl -w
|
|---|
| 2 |
|
|---|
| 3 | #####################################################################
|
|---|
| 4 | ### http://www.perl.com/doc/manual/html/utils/pod2man.html
|
|---|
| 5 | ### http://search.cpan.org/dist/perl/pod/perlpod.pod
|
|---|
| 6 |
|
|---|
| 7 | =head1 NAME
|
|---|
| 8 |
|
|---|
| 9 | read_lang.pl - Read a binary JOSM language file.
|
|---|
| 10 |
|
|---|
| 11 | =head1 SYNOPSIS
|
|---|
| 12 |
|
|---|
| 13 | B<read_lang.pl> [B<--help>] [B<--man>] [B<--output> I<outfile>] I<lang.lang>
|
|---|
| 14 |
|
|---|
| 15 | =head1 DESCRIPTION
|
|---|
| 16 |
|
|---|
| 17 | Read a binary JOSM language file and print the strings.
|
|---|
| 18 |
|
|---|
| 19 | =head1 OPTIONS
|
|---|
| 20 |
|
|---|
| 21 | =over 4
|
|---|
| 22 |
|
|---|
| 23 | =item B<--help>
|
|---|
| 24 |
|
|---|
| 25 | Prints a brief help message and exits.
|
|---|
| 26 |
|
|---|
| 27 | =item B<--man>
|
|---|
| 28 |
|
|---|
| 29 | Prints the manual page and exits.
|
|---|
| 30 |
|
|---|
| 31 | =item B<--output>, B<-o>
|
|---|
| 32 |
|
|---|
| 33 | Write the strings into the specified file. Default is to print the string to
|
|---|
| 34 | standard output.
|
|---|
| 35 |
|
|---|
| 36 | =item B<--statistics>, B<-s>
|
|---|
| 37 |
|
|---|
| 38 | Print statistics about the language file instead of the strings.
|
|---|
| 39 |
|
|---|
| 40 | =back
|
|---|
| 41 |
|
|---|
| 42 | =cut
|
|---|
| 43 | #####################################################################
|
|---|
| 44 |
|
|---|
| 45 | use strict;
|
|---|
| 46 | use File::Basename;
|
|---|
| 47 | use Getopt::Long;
|
|---|
| 48 | use Pod::Usage;
|
|---|
| 49 | push(@INC, dirname($0));
|
|---|
| 50 | require i18nlib;
|
|---|
| 51 |
|
|---|
| 52 | my $showhelp = 0; ### Show help screen.
|
|---|
| 53 | my $showman = 0; ### Show manual page of this script.
|
|---|
| 54 | my $outfile; ### Name of output file.
|
|---|
| 55 | my $langfile; ### Name of language file.
|
|---|
| 56 | my $statistics = 0; ### Print statistics.
|
|---|
| 57 | my $separator = "\n\n"; ### String separator.
|
|---|
| 58 |
|
|---|
| 59 | GetOptions('help|?|h' => \$showhelp,
|
|---|
| 60 | 'man' => \$showman,
|
|---|
| 61 | 'output|o=s' => \$outfile,
|
|---|
| 62 | 'statistics|s' => \$statistics,
|
|---|
| 63 | ) or pod2usage(2);
|
|---|
| 64 |
|
|---|
| 65 | pod2usage(1) if $showhelp;
|
|---|
| 66 | pod2usage(-exitstatus => 0, -verbose => 2) if $showman;
|
|---|
| 67 |
|
|---|
| 68 | ### Check for arguments. The only supported argument is the language file.
|
|---|
| 69 | if ($#ARGV == 0) {
|
|---|
| 70 | $langfile = $ARGV[0];
|
|---|
| 71 | }
|
|---|
| 72 | elsif ($#ARGV > 0) {
|
|---|
| 73 | die "This script accepts only one argument.\n";
|
|---|
| 74 | }
|
|---|
| 75 |
|
|---|
| 76 | die "Please specify a language file.\n" unless ($langfile);
|
|---|
| 77 |
|
|---|
| 78 | my @strings = loadLangFile($langfile);
|
|---|
| 79 | if ($statistics) {
|
|---|
| 80 | my $empty = 0;
|
|---|
| 81 | my $sametrans = 0;
|
|---|
| 82 | foreach my $string (@strings) {
|
|---|
| 83 | if ($string eq "") {
|
|---|
| 84 | $empty++;
|
|---|
| 85 | }
|
|---|
| 86 | elsif ($string eq "(see original string)") {
|
|---|
| 87 | $sametrans++;
|
|---|
| 88 | }
|
|---|
| 89 | }
|
|---|
| 90 | printf("Total strings: %d\n", $#strings + 1);
|
|---|
| 91 | print "Strings without translation: $empty\n";
|
|---|
| 92 | print "Strings with equal translation: $sametrans\n";
|
|---|
| 93 | }
|
|---|
| 94 | else {
|
|---|
| 95 | if ($outfile) {
|
|---|
| 96 | open(my $outFd, ">", $outfile) or die "Cannot open output file $outfile: $!";
|
|---|
| 97 | print $outFd join($separator, @strings), "\n";
|
|---|
| 98 | close($outFd);
|
|---|
| 99 | }
|
|---|
| 100 | else {
|
|---|
| 101 | print join($separator, @strings), "\n";
|
|---|
| 102 | }
|
|---|
| 103 | }
|
|---|