xgettext.pl 1.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
#!/usr/bin/perl

use strict;
use Locale::Maketext::Extract;
use Cwd;
use Getopt::Long;
use Time::Local;

sub help {
    die "unknown option";
}

my %opts;
Getopt::Long::Configure("no_ignore_case");
Getopt::Long::GetOptions( \%opts,
			  'f|files-from:s@',
			  'D|directory:s',
			  'd|default-domain:s',
			  'c|add-comments:s',
			  'v|version',
			  'msgid-bugs-address:s',
			  'copyright-holder:s',
			  'h|help',
			  ) or help();
help() if $opts{h};

if ($opts{v}) {
    print "xgettext pve\n";
    exit 0;
}

my $sources = [];

my $cwd = getcwd();

my $dir = $opts{D} || $cwd;

foreach my $file (@{$opts{f}||[]}) {
    open FILE, $file or die "Cannot open $file: $!";
    while (<FILE>) {
	chomp;
	s/\s+$//;
	s/^\s+//;
	next if !$_;
	next if m/^#/;
	push @$sources, $_;
    }
}

my $filename = "messages.pot";

$filename = "$opts{d}.pot" if $opts{d};

my $Ext = Locale::Maketext::Extract->new();

my $ctime = scalar localtime;

my $header = << '.';
# SOME DESCRIPTIVE TITLE.
# Copyright (C) 2008 Proxmox Server Solutions GmbH
# This file is distributed under the same license as the pve-manager package.
# Proxmox Support Team <support@proxmox.com>, 2008.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
.

$header .= "\"Report-Msgid-Bugs-To: $opts{'msgid-bugs-address'}\\n\"\n" if  $opts{'msgid-bugs-address'};
$header .= "\"POT-Creation-Date: $ctime\\n\"\n";

$header .= << '.';
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <support@proxmox.com>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"
.

$Ext->set_header ($header);

#$Ext->read_po($po, $opts{u}) if -r $po;

chdir $dir;

foreach my $s (@$sources) {
    $Ext->extract_file($s);

}

#$Ext->compile($opts{u});
$Ext->compile() or die "compile error";

#$Ext->write_po($filename, $opts{g});

chdir $cwd;

$Ext->write_po($filename);