1#!/usr/bin/perl 2 3# print-po.pl - print translations in the order in which they appear in sources 4# Copyright (C) 2010 Free Software Foundation, Inc. 5# 2010 Martin von Gagern 6# 7# This program is free software: you can redistribute it and/or modify 8# it under the terms of the GNU General Public License as published by 9# the Free Software Foundation, either version 3 of the License, or 10# (at your option) any later version. 11# 12# This program is distributed in the hope that it will be useful, 13# but WITHOUT ANY WARRANTY; without even the implied warranty of 14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15# GNU General Public License for more details. 16# 17# You should have received a copy of the GNU General Public License 18# along with this program. If not, see <http://www.gnu.org/licenses/>. 19 20=pod 21 22=head1 NAME 23 24print-po.pl - print translations in the order in which they appear in sources 25 26=head1 SYNOPSIS 27 28B<build-aux/print-po.pl> I<po/*.po> 29 30=head1 DESCRIPTION 31 32The script expects a list of po or pot files as command line 33arguments. For every source file mentioned in the C<#:> comments it 34prints all messages in the order in which they appear in the source 35file. The first column of the output gives the number of times a 36message was used, so that one can adjust the less-often used messages 37to match the style of the more often used ones. An C<X> indicates a 38missing translation string, a C<-> a continuation line and a C<+> more 39than 9 occurrences of a message. Output will always be in UTF-8. 40 41=head1 HISTORY 42 43This script was originally written for GNU wdiff. 44Its main application is to check formatting of usage help screens. 45 46=head1 AUTHOR 47 48Written 2010 by Martin von Gagern 49 50=head1 COPYRIGHT 51 52Copyright (C) 2010 Free Software Foundation, Inc. 53 54Licensed under the GNU General Public License version 3 or later. 55 56=cut 57 58use strict; 59use warnings; 60 61use Encode; 62 63BEGIN { 64 my $incdir = __FILE__; 65 $incdir = '.' unless $incdir =~ s:/[^/]+$::; 66 unshift @INC, $incdir; 67} 68 69use msgitm; 70 71binmode STDOUT, ':utf8'; 72for my $pofile (@ARGV) { 73 my @po = msgitm->parse($pofile); 74 print "========== $pofile ==========\n"; 75 my %src = (); 76 my %cnt = (); 77 my $encoding = "utf8"; 78 for my $itm (@po) { 79 my $id = $itm->msgid; 80 my $str = $itm->msgstr; 81 $encoding = $1 if $id eq '' && $str =~ /; charset=(.*?)\\n/; 82 $str = $id if $pofile =~ /\.pot$/; 83 my @refs = $itm->srcrefs; 84 my $cnt = scalar(@refs); 85 for my $ref (@refs) { 86 next unless $ref =~ /^(.*):(\d+)$/; 87 my $file = $1; 88 my $line = $2; 89 push @{$src{$file}}, { line => $line, cnt => $cnt, 90 id => $id, str => $str }; 91 } 92 } 93 for my $file (sort keys %src) { 94 print "---------- $file ($pofile) ----------\n"; 95 for my $m (sort { $a->{line} <=> $b->{line} } @{$src{$file}}) { 96 my $str = $m->{str}; 97 my $cnt = $m->{cnt}; 98 my $id = $m->{id}; 99 $_ = $str; 100 $_ = $id if $_ eq ''; 101 $_ = decode($encoding, $_); 102 s/(\\[\\nt"])/eval qq{"$1"}/eg; 103 s/\n?$/\n/; 104 s/^([^\n]{79})([^\n])/$1| !!! |$2/mg; 105 s/^/-|/mg; 106 s/^-/X/ if $str eq ''; 107 $cnt = '+' if $cnt > 9; 108 s/^-/$cnt/; 109 print; 110 } 111 } 112} 113