source: osm/applications/editors/josm/plugins/photoadjust/i18n/read_lang.pl@ 35624

Last change on this file since 35624 was 31960, checked in by holgermappt, 9 years ago

Added scripts that read the JOSM *.lang language files.

  • Property svn:executable set to *
File size: 2.4 KB
Line 
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
9read_lang.pl - Read a binary JOSM language file.
10
11=head1 SYNOPSIS
12
13B<read_lang.pl> [B<--help>] [B<--man>] [B<--output> I<outfile>] I<lang.lang>
14
15=head1 DESCRIPTION
16
17Read a binary JOSM language file and print the strings.
18
19=head1 OPTIONS
20
21=over 4
22
23=item B<--help>
24
25Prints a brief help message and exits.
26
27=item B<--man>
28
29Prints the manual page and exits.
30
31=item B<--output>, B<-o>
32
33Write the strings into the specified file. Default is to print the string to
34standard output.
35
36=item B<--statistics>, B<-s>
37
38Print statistics about the language file instead of the strings.
39
40=back
41
42=cut
43#####################################################################
44
45use strict;
46use File::Basename;
47use Getopt::Long;
48use Pod::Usage;
49push(@INC, dirname($0));
50require i18nlib;
51
52my $showhelp = 0; ### Show help screen.
53my $showman = 0; ### Show manual page of this script.
54my $outfile; ### Name of output file.
55my $langfile; ### Name of language file.
56my $statistics = 0; ### Print statistics.
57my $separator = "\n\n"; ### String separator.
58
59GetOptions('help|?|h' => \$showhelp,
60 'man' => \$showman,
61 'output|o=s' => \$outfile,
62 'statistics|s' => \$statistics,
63 ) or pod2usage(2);
64
65pod2usage(1) if $showhelp;
66pod2usage(-exitstatus => 0, -verbose => 2) if $showman;
67
68### Check for arguments. The only supported argument is the language file.
69if ($#ARGV == 0) {
70 $langfile = $ARGV[0];
71}
72elsif ($#ARGV > 0) {
73 die "This script accepts only one argument.\n";
74}
75
76die "Please specify a language file.\n" unless ($langfile);
77
78my @strings = loadLangFile($langfile);
79if ($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}
94else {
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}
Note: See TracBrowser for help on using the repository browser.