From 660fe2aeb3b21ac3237313564b9d7921a6fd8eb0 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Mon, 21 Nov 2011 14:12:35 +0100 Subject: [PATCH] implement our own tool to extract gettext - jsgettext.pl --- po/Makefile | 4 +- po/POTFILES | 3 -- po/jsgettext.pl | 85 ++++++++++++++++++++++++++++++++ www/manager/pve-lang-de.js | 4 -- xgettext.pl | 99 -------------------------------------- 5 files changed, 87 insertions(+), 108 deletions(-) delete mode 100644 po/POTFILES create mode 100755 po/jsgettext.pl delete mode 100644 www/manager/pve-lang-de.js delete mode 100755 xgettext.pl diff --git a/po/Makefile b/po/Makefile index b3afeeca7..926675c79 100644 --- a/po/Makefile +++ b/po/Makefile @@ -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 diff --git a/po/POTFILES b/po/POTFILES deleted file mode 100644 index 1b7ae1c04..000000000 --- a/po/POTFILES +++ /dev/null @@ -1,3 +0,0 @@ -../www/manager/window/LoginWindow.js -../www/manager/qemu/Config.js - diff --git a/po/jsgettext.pl b/po/jsgettext.pl new file mode 100755 index 000000000..e1bb944a5 --- /dev/null +++ b/po/jsgettext.pl @@ -0,0 +1,85 @@ +#!/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 , 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: \\n" . + "POT-Creation-Date: $ctime\\n" . + "PO-Revision-Date: YEAR-MO-DA HO:MI +ZONE\\n" . + "Last-Translator: FULL NAME \\n" . + "Language-Team: LANGUAGE \\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 = )) { + if ($line =~ m/gettext/) { + extract_msg($s, $., $line); + } + } + close(SRC); +} + +Locale::PO->save_file_fromhash($filename, $href); + diff --git a/www/manager/pve-lang-de.js b/www/manager/pve-lang-de.js deleted file mode 100644 index a81dad91a..000000000 --- a/www/manager/pve-lang-de.js +++ /dev/null @@ -1,4 +0,0 @@ -Ext.onReady(function() { - // fixme: how do we implement i18n? - //alert("LOADED LANG DE"); -}); \ No newline at end of file diff --git a/xgettext.pl b/xgettext.pl deleted file mode 100755 index 9f55a6f17..000000000 --- a/xgettext.pl +++ /dev/null @@ -1,99 +0,0 @@ -#!/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 () { - 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 , 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 \n" -"Language-Team: LANGUAGE \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); -