#!/usr/bin/perl -W # # A script that adds timestameps to PO (gettext) files. # # Copyright (C) 2010 Bogdan 'bogdro' Drozdowski, http://rudy.mif.pg.gda.pl/~bogdro/inne/ # (bogdandr AT op.pl, bogdro AT rudy.mif.pg.gda.pl) # # Licence: # GNU General Public Licence v3+ # # Last modified : 2010-03-17 # # Usage: # add-po-timestamps.pl file.po # # # 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 3 # 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 Foudation: # Free Software Foundation # 51 Franklin Street, Fifth Floor # Boston, MA 02110-1301 # USA # use strict; use warnings; use Tie::File; if ( @ARGV == 0 ) { print "Syntax: $0 file.po\n"; exit 1; } my ($out, @input); if ( ! tie (@input, 'Tie::File', $ARGV[0]) ) { # $! is the error message print "$0: $ARGV[0]: $!\n"; exit 2; } if ( ! open ( $out, "> $ARGV[0].tmp" ) ) { print "$0: $ARGV[0].tmp: $!\n"; untie @input; exit 3; } my $datetime = localtime; $datetime =~ s/(\w+)\s+(\w+)\s+(\d+)\s+(\d{1,2}:\d{1,2}:\d{1,2})\s+(\d{4})(.*)/$1, $2 $3 $5 $4 $6/; chop ($datetime); my $datedone = 0; # flag foreach (@input) { if ( /^msgid/o && ! $datedone ) { print $out "#: Last-Modified: $datetime\n"; print $out "$_\n"; $datedone = 0; } elsif ( /^#: Last-Modified/o ) { print $out "#: Last-Modified: $datetime\n"; $datedone = 1; } else { print $out "$_\n"; $datedone = 0; } } close $out; untie @input; #rename "$ARGV[0].tmp", $ARGV[0];