[pve-devel] [PATCH i18n v2] make only one po file per language

Dominik Csapak d.csapak at proxmox.com
Fri Jan 19 14:28:19 CET 2018


instead of creating a po file per source package
(that are: pmg-gui, proxmox-widget-toolkit and pve-manager),
but combine the messages from them and create one
po file per language.

to not include unneeded strings in the (pve|pmg)-lang-*.js files,
we use the references value in po2js.pl to filter out unwanted strings

also include a git submodule update in the 'update' target, so that
we get the newest version when updating the po file

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
changes from v1:
* move the pot updating into a function
* put the git commit as version instead of x.y
 Makefile | 41 ++++++++++++++++++++++-------------------
 po2js.pl | 11 +++++++++--
 2 files changed, 31 insertions(+), 21 deletions(-)

diff --git a/Makefile b/Makefile
index 63a3a7f..7d379a1 100644
--- a/Makefile
+++ b/Makefile
@@ -39,32 +39,35 @@ install: ${PMG_LANG_FILES} ${PVE_LANG_FILES}
 	install -m 0644 ${PVE_LANG_FILES} ${PVELOCALEDIR}
 
 
-pmg-lang-%.js: proxmox-widget-toolkit-%.po proxmox-mailgateway-%.po
-	./po2js.pl -o pmg-lang-$*.js $?
+pmg-lang-%.js: %.po
+	./po2js.pl -t pmg -v "${VERSION}-${PKGREL}" -o pmg-lang-$*.js $?
 
-pve-lang-%.js: proxmox-widget-toolkit-%.po pve-manager-%.po
-	./po2js.pl -o pve-lang-$*.js $?
+pve-lang-%.js: %.po
+	./po2js.pl -t pve -v "${VERSION}-${PKGREL}" -o pve-lang-$*.js $?
+
+# parameter 1 is the name
+# parameter 2 is the directory
+define potupdate
+    ./jsgettext.pl -p "$(1) $(shell cd $(2);git rev-parse HEAD)" -o $(1).pot $(2)
+endef
 
 .PHONY: update
 update:
-	./jsgettext.pl -p "proxmox-widget-toolkit 1.0" -o proxmox-widget-toolkit.pot proxmox-widget-toolkit/ 
-	./jsgettext.pl -p "proxmox-mailgateway 5.0" -o proxmox-mailgateway.pot -b proxmox-widget-toolkit.pot pmg-gui/js/
-	./jsgettext.pl -p "pve-manager 5.0" -o pve-manager.pot -b proxmox-widget-toolkit.pot pve-manager/www/manager6/
-	for j in proxmox-widget-toolkit proxmox-mailgateway pve-manager; do for i in $(LINGUAS); do echo -n "$$j-$$i: ";msgmerge -s -v $$j-$$i.po $$j.pot >$$j-$$i.po.tmp && mv $$j-$$i.po.tmp $$j-$$i.po; done; done
+	git submodule foreach 'git pull --ff-only origin master'
+	$(call potupdate,proxmox-widget-toolkit,proxmox-widget-toolkit/)
+	$(call potupdate,pve-manager,pve-manager/www/manager6/)
+	$(call potupdate,proxmox-mailgateway,pmg-gui/js/)
+	msgcat proxmox-widget-toolkit.pot proxmox-mailgateway.pot pve-manager.pot > messages.pot.tmp
+	mv messages.pot.tmp messages.pot
+	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;
+	rm messages.pot
 
 # try to generate po files when someone add a new language
 .SECONDARY: # do not delete generated intermediate file
-proxmox-widget-toolkit-%.po: proxmox-widget-toolkit.pot
-	msginit -i proxmox-widget-toolkit.pot -l $* -o proxmox-widget-toolkit-$*.po
-
-.SECONDARY: # do not delete generated intermediate file
-proxmox-mailgateway-%.po: proxmox-mailgateway.pot
-	msginit -i proxmox-mailgateway.pot -l $* -o proxmox-mailgateway-$*.po
-
-.SECONDARY: # do not delete generated intermediate file
-pve-manager-%.po: pve-manager.pot
-	msginit -i pve-manager.pot -l $* -o pve-manager-$*.po
-
+%.po: proxmox-widget-toolkit.pot proxmox-mailgateway.pot pve-manager.pot
+	msgcat $^ > $*.pot
+	msginit -i $*.pot -l $* -o $*.po
+	rm $*.pot
 
 .PHONY: distclean
 distclean: clean
diff --git a/po2js.pl b/po2js.pl
index 8a00e6c..f4060aa 100755
--- a/po2js.pl
+++ b/po2js.pl
@@ -13,7 +13,7 @@ use Encode;
 
 my $options = {};
 
-getopts('o:', $options) ||
+getopts('t:o:v:', $options) ||
     die "unable to parse options\n";
 
 die "no files specified\n" if !scalar(@ARGV);
@@ -59,6 +59,13 @@ foreach my $filename (@ARGV) {
 	my $po = $href->{$k};
 	next if $po->fuzzy(); # skip fuzzy entries
 	my $ref = $po->reference();
+
+	# skip unused entries
+	next if !$ref;
+
+	# skip entries if t is defined (pve/pmg) and the string is
+	# not used there or in the widget toolkit
+	next if $options->{t} && $ref !~ m/($options->{t}|proxmox)\-/;
     
 	my $qmsgid = decode($charset, $po->msgid);
 	my $msgid = $po->dequote($qmsgid);
@@ -81,7 +88,7 @@ foreach my $filename (@ARGV) {
 
 my $json = to_json($catalog, {canonical => 1, utf8 => 1});
 
-my $content = '';
+my $content = "// $options->{v}\n"; # write version to beginning
 
 my $outfile = $options->{o};
 
-- 
2.11.0





More information about the pve-devel mailing list