renaming translation files to conform to our standard convention. Moving stats.pl...
[koha.git] / misc / translator / update.pl
1 #!/usr/bin/perl
2
3 # Convenience script to update two po files at once
4 # This emulates the GNOME "update.pl" script
5
6 use strict;
7 use integer;
8 use Getopt::Long;
9
10 use vars qw( $pot_p );
11
12 GetOptions(
13    '--pot' => \$pot_p,
14 ) || exit(1);
15
16 my $lang = $ARGV[0];
17 die <<EOF unless $pot_p || $lang =~ /^[a-z]{2}(?:_[A-Z]{2})?$/;
18 Usage: $0 LANG
19        $0 --pot
20 EOF
21
22 # Remember whether we see the "po" directory; this is used later to guess
23 # whether the current directory is translator/po or translator.
24 my $chdir_needed_p = 1 unless -d('po');
25
26 # Go through the theme/module combinations we need to update. There can be
27 # more than two; e.g., if we want ['default', 'opac'] too we can put it in
28 for my $spec (
29       ['css',     'opac'    ],
30       ['default', 'intranet']
31 ) {
32    my($theme, $module) = @$spec;
33    my $pid = fork;
34    die "fork: $!\n" unless defined $pid;
35    if (!$pid) {
36
37       # If current directory is translator/po instead of translator,
38       # then go back to the parent
39       if ($chdir_needed_p) {
40          chdir('..') || die "..: cd: $!\n";
41       }
42
43       # Now call tmpl_process3.pl to do the real work
44       #
45       # Traditionally, the pot file should be named PACKAGE.pot
46       # (for Koha probably something like koha_intranet_css.pot),
47       # but this is not Koha's convention.
48       #
49       my $target = "po/${theme}_${module}" . ($pot_p? ".pot": "_$lang.po");
50       rename($target, "$target~") if $pot_p;
51       exec('./tmpl_process3.pl', ($pot_p? 'create': 'update'),
52             '-i', "../../koha-tmpl/$module-tmpl/$theme/en/",
53             '-s', $target, '-r');
54
55       die "tmpl_process3.pl: exec: $!\n";
56    }
57    wait;
58 }
59