source: git/lib/generate-po-todo @ 1b69705

RELEASE/1.2debug-cidebug-ci-sanitiserswalls-data
Last change on this file since 1b69705 was 1d9c2df, checked in by Olly Betts <olly@…>, 9 years ago

lib/generate-po-todo: Add code to update the todo files on the
website.

  • Property mode set to 100755
File size: 2.0 KB
Line 
1#!/usr/bin/perl -w
2require 5.008;
3use bytes;
4use strict;
5use POSIX;
6use Locale::PO;
7
8use integer;
9
10if (@ARGV == 0 || $ARGV[0] eq '--help') {
11  print STDERR "Syntax: $0 PO_FILE...\n";
12  exit (@ARGV != 0);
13}
14
15my @nonempty;
16for my $po_file (@ARGV) {
17  my $todo = $po_file;
18  if (!($todo =~ s/\.po$/.todo/)) {
19    print STDERR "$po_file: doesn't end '.po'\n";
20    next;
21  }
22  my $po = Locale::PO->load_file_asarray($po_file);
23  if (!defined $po) {
24    print STDERR "$po_file: Bad!\n";
25    next;
26  }
27  my $c = 0;
28  open TODO, '>', $todo or die $!;
29  foreach my $po_entry (@{$po}) {
30    my $msgid = $po_entry->msgid;
31    my $msgstr = $po_entry->msgstr;
32    ($msgid eq '""' || $msgstr eq '""' || $po_entry->fuzzy) or next;
33    $msgstr =~ s/\\n(..)/\\n"\n"$1/g;
34    if ($msgid eq '""') {
35      print TODO "msgid $msgid\n";
36      print TODO "msgstr \"\"\n$msgstr\n";
37      next;
38    }
39    if (defined $po_entry->automatic) {
40      my $automatic = "\n" . $po_entry->automatic;
41      $automatic =~ s/\n/\n#. /g;
42      while ($automatic =~ s/\n#. \n/\n#.\n/g) { }
43      print TODO $automatic;
44    }
45    my $ref = $po_entry->reference;
46    if (defined $ref) {
47      $ref = "\n" . $ref;
48      $ref =~ s/\n/\n#: /mg;
49      print TODO $ref;
50    }
51    my $fuzzy = $po_entry->fuzzy;
52    my $c_format = $po_entry->c_format;
53    if ($fuzzy || $c_format) {
54      print TODO "\n#";
55      print TODO ", fuzzy" if $fuzzy;
56      print TODO ", c-format" if $c_format;
57    }
58    print TODO "\n";
59    print TODO "#~ " if $po_entry->obsolete;
60    print TODO "msgid $msgid\n";
61    print TODO "#~ " if $po_entry->obsolete;
62    print TODO "msgstr $msgstr\n";
63    ++$c;
64  }
65  close TODO or die $!;
66  if ($c > 0) {
67      push @nonempty, $todo;
68  } else {
69      unlink $todo;
70  }
71}
72
73my $host = 'atreus.tartarus.org';
74my $webpath = '/srv/www/survex.com/software.i18n';
75
76print "To update the files on the webserver:\n";
77if (@nonempty) {
78    print "rsync -av --delete-after *.todo '$host:$webpath/'\n";
79} else {
80    print "ssh $host rm '$webpath/*.todo'\n";
81}
Note: See TracBrowser for help on using the repository browser.