Hi, (Javier, embedded question for you)
On Sat, Feb 14, 2009 at 06:44:12PM +0900, os...@debian.org wrote: > Hi, > > On Wed, Feb 11, 2009 at 12:43:10AM +0100, Nicolas François wrote: > > Hello, > > > > On Wed, Feb 11, 2009 at 01:04:50AM +0900, Osamu Aoki wrote: > > > > [talking about Javier's script which allows to see differences based on > > the strings added by --previous] > > > > > I think this should be inclided as an example helper script or even > > > integrated > > > into additional --previous functionality. wdiff makes good sense in many > > > cases! > > I would prefer this feature to be included in PO editors. > > I also know that editors are working on supporting the previous string > > (lokalize does it, it is planned for virtaal, see also > > http://techbase.kde.org/Localization/Tools/Pology/PO_Embedded_Diffing) > > That is certainly clean and nice approach but old furt like me are stack > with using vim to edit po files :-) Please do not forget us. > > > Also, it is not directly related to po4a. > > Well it is directly related to data generated and used by po4a. It is not only po4a, because it's a gettext feature. It could be used by any PO file generated by gettext (just add --previous to msgmerge). But since it's useful, let's package it. > > On the other hand, if this script is useful for others, I can package it > > (either in po4a, po-debconf, or translate-toolkit) > > This may be part of translate-toolkit if this can be integrated into it. > (but I think this is not something you ship as normal Debian command and > more appropriate as user script) I will try to hack something in pofilter. It might be even more useful (I mean for old furt who use vim;), since you will see this in your editor while editing the message. > This is po4a specific and appropriate as example script for user. Let's package it as an example (and this will probably be much faster than my pofilter patch) I made some changes to the last Javier's script: * Add a Copyright and GPL header Javier, do you agree? * Support plurals (well, not really useful for po4a, but it's not so difficult). (Note that context may also have to be diffed) * Use File::Temp * Support single lines (mesage on the msgid line) * Do not output the translation. (Was it intended?) * Do not send the diff to less (should I allow passing options to wdiff, like -a ?) New version attached. Best Regards, -- Nekral
#!/usr/bin/perl -w use strict; use warnings; # Copyright 2009 by Javier Fernández-Sanguino Peña <j...@debian.org> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA # Quick and dirty script to compare two msgids (when using PO files # generated with --previous) with wdiff to find the differences between # them. # Usage: perl compare-msgids.pl < XX.po use File::Temp; my $DIFF1 = new File::Temp(TEMPLATE => "compare-msgids.XXXXXX"); my $DIFF2 = new File::Temp(TEMPLATE => "compare-msgids.XXXXXX"); my $fileh=""; my $diffblock = 0; # Does the current block has a --previous string? my $nowrap = 0; # Can the current be rewrapped? my $ref = ""; # Line reference for the current block while (my $line = <STDIN>) { $fileh=""; chomp $line; $ref .= $line."\n" if $line =~ /^#: /; $ref = "" if ($line eq ""); if ( $diffblock and $line =~ /^msgstr/ ) { $diffblock = 0; $nowrap = 0; print $DIFF1 "\n\n"; print $DIFF2 "\n\n"; } $diffblock = 1 if ( $line =~ /^\#\| msgid/ ) ; $nowrap = 1 if ( $line =~ /^#,.*no-wrap/ ) ; if ($diffblock) { if (length $ref) { print $DIFF1 $ref."\n"; print $DIFF1 $ref."\n"; print $DIFF2 $ref."\n"; $ref = ""; } $fileh = $DIFF1 if ( $line =~ /^\#\| msgid/ ) ; $fileh = $DIFF1 if ( $line =~ /^\#\| "/ ) ; $fileh = $DIFF2 if ( $line =~ /^msgid/ ) ; $fileh = $DIFF2 if ( $line =~ /^"/ ) ; if ($fileh ne "") { $line =~ s/^\#\| //; print $fileh "\n" if ( $line =~ /^msgid_plural "/); $line =~ s/^"//; $line =~ s/^msgid "//; $line =~ s/^msgid_plural "//; $line =~ s/"$//; print $fileh $line; print $fileh "\n" if ($nowrap and $line =~ m/\\n$/); } } } close $DIFF1; close $DIFF2; system ("wdiff", "-3", $DIFF1->filename, $DIFF2->filename) or die "Failed to run wdiff."; exit;