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

Thomas Lamprecht t.lamprecht at proxmox.com
Fri Jan 19 13:14:18 CET 2018


On 1/19/18 12:13 PM, Dominik Csapak wrote:
> 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
> 

The idea seems good to me! One nit below.

> Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
> ---
>  Makefile | 35 ++++++++++++++++-------------------
>  po2js.pl | 11 +++++++++--
>  2 files changed, 25 insertions(+), 21 deletions(-)
> 
> diff --git a/Makefile b/Makefile
> index 63a3a7f..94b66f1 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -39,32 +39,29 @@ 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 $?
>  
>  .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'
> +	./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 pmg-gui/js/
> +	./jsgettext.pl -p "pve-manager 5.0" -o pve-manager.pot pve-manager/www/manager6/

The versions may not be hardcoded, as we have no tags we could
maybe use the respective git revision hash?

> +	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};
>  
> 





More information about the pve-devel mailing list