Commit 660fe2ae authored by Dietmar Maurer's avatar Dietmar Maurer

implement our own tool to extract gettext - jsgettext.pl

parent 482fa9b4
......@@ -8,8 +8,8 @@ all: $(patsubst %, pve-lang-%.js, $(LINGUAS))
.PHONY: update-po
update-po:
../xgettext.pl -f POTFILES
for i in $(LINGUAS); do echo -n "$$i: ";msgmerge -v $$i.po messages.pot >$$i.po.tmp; mv $$i.po.tmp $$i.po; done
./jsgettext.pl ../www/manager
for i in $(LINGUAS); do echo -n "$$i: ";msgmerge -s -v $$i.po messages.pot >$$i.po.tmp; mv $$i.po.tmp $$i.po; done
pve-lang-%.js: %.po
./po2js.pl $< >$@.tmp
......
../www/manager/window/LoginWindow.js
../www/manager/qemu/Config.js
#!/usr/bin/perl
use strict;
use Time::Local;
use PVE::Tools;
use Locale::PO;
my $dir = shift;
die "no such directory\n" if ! -d $dir;
my $sources = [];
my $findcmd = ['find', $dir, '-name', '*.js'];
PVE::Tools::run_command($findcmd, outfunc => sub {
my $line = shift;
next if $line =~ m|/pvemanagerlib.js$|;
push @$sources, $line;
});
my $filename = "messages.pot";
my $header = <<__EOD;
SOME DESCRIPTIVE TITLE.
Copyright (C) 20011 Proxmox Server Solutions GmbH
This file is distributed under the same license as the pve-manager package.
Proxmox Support Team <support\@proxmox.com>, 2011.
__EOD
my $ctime = scalar localtime;
my $href = {};
my $po = new Locale::PO(-msgid=> '',
-comment=> $header,
-fuzzy=> 1,
-msgstr=>
"Project-Id-Version: pve-manager 2.0\\n" .
"Report-Msgid-Bugs-To: <support\@proxmox.com>\\n" .
"POT-Creation-Date: $ctime\\n" .
"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");
$href->{''} = $po;
sub extract_msg {
my ($filename, $linenr, $line) = @_;
my $text;
if ($line =~ m/\Wgettext\s*\("((?:[^"\\]++|\\.)*+)"\)/) {
$text = $1;
} elsif ($line =~ m/\Wgettext\s*\('((?:[^'\\]++|\\.)*+)'\)/) {
$text = $1;
} else {
die "can't extract gettext message in '$filename' line $linenr\n";
}
my $ref = "$filename:$linenr";
if (my $po = $href->{$text}) {
$po->reference($po->reference() . " $ref");
return;
}
my $po = new Locale::PO(-msgid=> $text, -reference=> $ref, -msgstr=> '');
$href->{$text} = $po;
}
foreach my $s (@$sources) {
open(SRC, $s) || die "unable to open file '$s' - $!\n";
while(defined(my $line = <SRC>)) {
if ($line =~ m/gettext/) {
extract_msg($s, $., $line);
}
}
close(SRC);
}
Locale::PO->save_file_fromhash($filename, $href);
Ext.onReady(function() {
// fixme: how do we implement i18n?
//alert("LOADED LANG DE");
});
\ No newline at end of file
#!/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) 2011 Proxmox Server Solutions GmbH
# This file is distributed under the same license as the pve-manager package.
# Proxmox Support Team <support@proxmox.com>, 2011.
#
msgid ""
msgstr ""
"Project-Id-Version: pve-manager 2\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 .= << '.';
"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);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment