Pino Toscano
2013-Dec-05 15:30 UTC
[Libguestfs] [PATCH 0/3] Small improvements to i18n extraction/handling
Hi, here there are few patches to improve the extraction of translatable messages, and the usage of messages with plural forms. Pino Toscano (3): po: fix broken message extraction po: fix dependencies for libguestfs.pot extraction fish: improve the command error messages generator/fish.ml | 20 ++++++++++++++++---- po/Makefile.am | 24 +++++++----------------- 2 files changed, 23 insertions(+), 21 deletions(-) Thanks, -- Pino Toscano -- 1.8.3.1
Pino Toscano
2013-Dec-05 15:30 UTC
[Libguestfs] [PATCH 1/3] po: fix broken message extraction
Extracting separately the pot for the various languages and then creating manually the global pot (by manually joining the above ones after having stripped their headers) is wrong, since other than being an hack it can create an invalid pot when the same message appears in sources written in different languages. Instead, a cleaner and safer solution is to first let ocaml-gettext (if available) extract the messages for the ml files, and then use xgettext to extract the messages for the other languages, joining the new messages to the existing (or not) pot file. --- po/Makefile.am | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/po/Makefile.am b/po/Makefile.am index e2bfe45..b0a8038 100644 --- a/po/Makefile.am +++ b/po/Makefile.am @@ -66,24 +66,14 @@ XGETTEXT_ARGS = \ --directory=$(top_srcdir) $(DOMAIN).pot: Makefile $(POTFILES) $(POTFILES-pl) $(POTFILES-ml) - rm -f $@-t $@-pl $@-ml - $(XGETTEXT) -o $@-t $(XGETTEXT_ARGS) \ - --files-from=$(abs_srcdir)/POTFILES - $(XGETTEXT) -o $@-pl $(XGETTEXT_ARGS) --language=Perl \ - --files-from=$(abs_srcdir)/POTFILES-pl -# Don't trust msgcat since it will definitely screw up. Instead, chop -# the head from the second file and append it to the first. - echo >> $@-t - awk '/^#:/{i++}i{print}' < $@-pl >> $@-t - rm $@-pl + rm -f $@-t if HAVE_OCAML_GETTEXT - $(OCAML_GETTEXT) --action extract --extract-pot $@-ml $(POTFILES_ML) -# Don't trust msgcat since it will definitely screw up. Instead, chop -# the head from the second file and append it to the first. - echo >> $@-t - awk '/^#:/{i++}i{print}' < $@-ml >> $@-t - rm $@-ml + $(OCAML_GETTEXT) --action extract --extract-pot $@-t $(POTFILES_ML) endif + $(XGETTEXT) -j -o $@-t $(XGETTEXT_ARGS) \ + --files-from=$(abs_srcdir)/POTFILES + $(XGETTEXT) -j -o $@-t $(XGETTEXT_ARGS) --language=Perl \ + --files-from=$(abs_srcdir)/POTFILES-pl mv $@-t $@ %.po: $(DOMAIN).pot -- 1.8.3.1
Pino Toscano
2013-Dec-05 15:30 UTC
[Libguestfs] [PATCH 2/3] po: fix dependencies for libguestfs.pot extraction
Fix the dependencies of the libguestfs.pot target: other than using the right make variables holding the contents of the POTFILES, depend also on the POTFILES themselves. --- po/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/po/Makefile.am b/po/Makefile.am index b0a8038..a8343ec 100644 --- a/po/Makefile.am +++ b/po/Makefile.am @@ -65,7 +65,7 @@ XGETTEXT_ARGS = \ --msgid-bugs-address="$(MSGID_BUGS_ADDRESS)" \ --directory=$(top_srcdir) -$(DOMAIN).pot: Makefile $(POTFILES) $(POTFILES-pl) $(POTFILES-ml) +$(DOMAIN).pot: Makefile POTFILES $(POTFILES) POTFILES-pl $(POTFILES_PL) POTFILES-ml $(POTFILES_ML) rm -f $@-t if HAVE_OCAML_GETTEXT $(OCAML_GETTEXT) --action extract --extract-pot $@-t $(POTFILES_ML) -- 1.8.3.1
Pino Toscano
2013-Dec-05 15:30 UTC
[Libguestfs] [PATCH 3/3] fish: improve the command error messages
- when a command needs no parameters, tell that explicitly instead of "command should have 0 parameters" - use gettext's plural form when printing the number of required arguments - improve the error message for a variable number of parameters limited only in the maximum number of them, using also a plural form --- generator/fish.ml | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/generator/fish.ml b/generator/fish.ml index 65f1acb..da0584b 100644 --- a/generator/fish.ml +++ b/generator/fish.ml @@ -362,12 +362,24 @@ Guestfish will prompt for these separately." if argc_minimum = argc_maximum then ( pr " if (argc != %d) {\n" argc_minimum; - pr " fprintf (stderr, _(\"%%s should have %%d parameter(s)\\n\"), cmd, %d);\n" - argc_minimum; + if argc_minimum = 0 then ( + pr " fprintf (stderr, _(\"%%s should have no parameters\\n\"), cmd);\n"; + ) else ( + pr " fprintf (stderr, ngettext(\"%%s should have %%d parameter\\n\",\n"; + pr " \"%%s should have %%d parameters\\n\",\n"; + pr " %d),\n" + argc_minimum; + pr " cmd, %d);\n" + argc_minimum; + ) ) else if argc_minimum = 0 then ( pr " if (argc > %d) {\n" argc_maximum; - pr " fprintf (stderr, _(\"%%s should have %%d-%%d parameter(s)\\n\"), cmd, %d, %d);\n" - argc_minimum argc_maximum; + pr " fprintf (stderr, ngettext(\"%%s should have at most %%d parameter\\n\",\n"; + pr " \"%%s should have at most %%d parameters\\n\",\n"; + pr " %d),\n" + argc_maximum; + pr " cmd, %d);\n" + argc_maximum; ) else ( pr " if (argc < %d || argc > %d) {\n" argc_minimum argc_maximum; pr " fprintf (stderr, _(\"%%s should have %%d-%%d parameter(s)\\n\"), cmd, %d, %d);\n" -- 1.8.3.1
Richard W.M. Jones
2013-Dec-05 15:53 UTC
Re: [Libguestfs] [PATCH 2/3] po: fix dependencies for libguestfs.pot extraction
On Thu, Dec 05, 2013 at 04:30:05PM +0100, Pino Toscano wrote:> Fix the dependencies of the libguestfs.pot target: other than using the > right make variables holding the contents of the POTFILES, depend also > on the POTFILES themselves. > --- > po/Makefile.am | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/po/Makefile.am b/po/Makefile.am > index b0a8038..a8343ec 100644 > --- a/po/Makefile.am > +++ b/po/Makefile.am > @@ -65,7 +65,7 @@ XGETTEXT_ARGS = \ > --msgid-bugs-address="$(MSGID_BUGS_ADDRESS)" \ > --directory=$(top_srcdir) > > -$(DOMAIN).pot: Makefile $(POTFILES) $(POTFILES-pl) $(POTFILES-ml) > +$(DOMAIN).pot: Makefile POTFILES $(POTFILES) POTFILES-pl $(POTFILES_PL) POTFILES-ml $(POTFILES_ML) > rm -f $@-t > if HAVE_OCAML_GETTEXT > $(OCAML_GETTEXT) --action extract --extract-pot $@-t $(POTFILES_ML)So I agree that $(POTFILES-pl) is definitely wrong. Not sure exactly what we were thinking about there ... But, won't the addition of the literal file names break separate compilation? In particular, $(POTFILES_PL) is supposed to be the correct path to the file POTFILES-pl (and correspondingly for the other files), so it shouldn't be necessary to list both POTFILES-pl and $(POTFILES_PL). Separate compilation is something that Debian cares about a lot because they have to rebuild libguestfs several times in series for different python versions etc. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Fedora Windows cross-compiler. Compile Windows programs, test, and build Windows installers. Over 100 libraries supported. http://fedoraproject.org/wiki/MinGW
Richard W.M. Jones
2013-Dec-05 15:58 UTC
Re: [Libguestfs] [PATCH 3/3] fish: improve the command error messages
On Thu, Dec 05, 2013 at 04:30:06PM +0100, Pino Toscano wrote:> - when a command needs no parameters, tell that explicitly instead of > "command should have 0 parameters" > - use gettext's plural form when printing the number of required > arguments > - improve the error message for a variable number of parameters limited > only in the maximum number of them, using also a plural form > --- > generator/fish.ml | 20 ++++++++++++++++---- > 1 file changed, 16 insertions(+), 4 deletions(-) > > diff --git a/generator/fish.ml b/generator/fish.ml > index 65f1acb..da0584b 100644 > --- a/generator/fish.ml > +++ b/generator/fish.ml > @@ -362,12 +362,24 @@ Guestfish will prompt for these separately." > > if argc_minimum = argc_maximum then ( > pr " if (argc != %d) {\n" argc_minimum; > - pr " fprintf (stderr, _(\"%%s should have %%d parameter(s)\\n\"), cmd, %d);\n" > - argc_minimum; > + if argc_minimum = 0 then ( > + pr " fprintf (stderr, _(\"%%s should have no parameters\\n\"), cmd);\n"; > + ) else ( > + pr " fprintf (stderr, ngettext(\"%%s should have %%d parameter\\n\",\n"; > + pr " \"%%s should have %%d parameters\\n\",\n"; > + pr " %d),\n" > + argc_minimum; > + pr " cmd, %d);\n" > + argc_minimum; > + ) > ) else if argc_minimum = 0 then ( > pr " if (argc > %d) {\n" argc_maximum; > - pr " fprintf (stderr, _(\"%%s should have %%d-%%d parameter(s)\\n\"), cmd, %d, %d);\n" > - argc_minimum argc_maximum; > + pr " fprintf (stderr, ngettext(\"%%s should have at most %%d parameter\\n\",\n"; > + pr " \"%%s should have at most %%d parameters\\n\",\n"; > + pr " %d),\n" > + argc_maximum; > + pr " cmd, %d);\n" > + argc_maximum; > ) else ( > pr " if (argc < %d || argc > %d) {\n" argc_minimum argc_maximum; > pr " fprintf (stderr, _(\"%%s should have %%d-%%d parameter(s)\\n\"), cmd, %d, %d);\n" > -- > 1.8.3.1ACK. I tested this with various combinations of commands: $ ./run ./fish/guestfish version foo version should have no parameters type 'help version' for help on version $ ./run ./fish/guestfish set-qemu foo bar set-qemu should have 1 parameter type 'help set-qemu' for help on set-qemu $ ./run ./fish/guestfish set-qemu foo bar baz set-qemu should have 1 parameter type 'help set-qemu' for help on set-qemu $ ./run ./fish/guestfish lvcreate foo lvcreate should have 3 parameters type 'help lvcreate' for help on lvcreate $ ./run ./fish/guestfish umount-local foo bar umount-local should have at most 1 parameter type 'help umount-local' for help on umount-local [Apparently only umount-local uses the argc > argc_maximum case] Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Fedora Windows cross-compiler. Compile Windows programs, test, and build Windows installers. Over 100 libraries supported. http://fedoraproject.org/wiki/MinGW
Richard W.M. Jones
2013-Dec-05 16:01 UTC
Re: [Libguestfs] [PATCH 1/3] po: fix broken message extraction
On Thu, Dec 05, 2013 at 04:30:04PM +0100, Pino Toscano wrote:> Extracting separately the pot for the various languages and then > creating manually the global pot (by manually joining the above ones > after having stripped their headers) is wrong, since other than being > an hack it can create an invalid pot when the same message appears in > sources written in different languages. > > Instead, a cleaner and safer solution is to first let ocaml-gettext > (if available) extract the messages for the ml files, and then use > xgettext to extract the messages for the other languages, joining the > new messages to the existing (or not) pot file. > --- > po/Makefile.am | 22 ++++++---------------- > 1 file changed, 6 insertions(+), 16 deletions(-) > > diff --git a/po/Makefile.am b/po/Makefile.am > index e2bfe45..b0a8038 100644 > --- a/po/Makefile.am > +++ b/po/Makefile.am > @@ -66,24 +66,14 @@ XGETTEXT_ARGS = \ > --directory=$(top_srcdir) > > $(DOMAIN).pot: Makefile $(POTFILES) $(POTFILES-pl) $(POTFILES-ml) > - rm -f $@-t $@-pl $@-ml > - $(XGETTEXT) -o $@-t $(XGETTEXT_ARGS) \ > - --files-from=$(abs_srcdir)/POTFILES > - $(XGETTEXT) -o $@-pl $(XGETTEXT_ARGS) --language=Perl \ > - --files-from=$(abs_srcdir)/POTFILES-pl > -# Don't trust msgcat since it will definitely screw up. Instead, chop > -# the head from the second file and append it to the first. > - echo >> $@-t > - awk '/^#:/{i++}i{print}' < $@-pl >> $@-t > - rm $@-pl > + rm -f $@-t > if HAVE_OCAML_GETTEXT > - $(OCAML_GETTEXT) --action extract --extract-pot $@-ml $(POTFILES_ML) > -# Don't trust msgcat since it will definitely screw up. Instead, chop > -# the head from the second file and append it to the first. > - echo >> $@-t > - awk '/^#:/{i++}i{print}' < $@-ml >> $@-t > - rm $@-ml > + $(OCAML_GETTEXT) --action extract --extract-pot $@-t $(POTFILES_ML) > endif > + $(XGETTEXT) -j -o $@-t $(XGETTEXT_ARGS) \ > + --files-from=$(abs_srcdir)/POTFILES > + $(XGETTEXT) -j -o $@-t $(XGETTEXT_ARGS) --language=Perl \ > + --files-from=$(abs_srcdir)/POTFILES-pl > mv $@-t $@ > > %.po: $(DOMAIN).pot > -- > 1.8.3.1ACK. This appears to be OK, and the results look sane: $ ll po/libguestfs.pot* -rw-rw-r--. 1 rjones rjones 180001 Dec 5 15:52 po/libguestfs.pot -rw-rw-r--. 1 rjones rjones 178207 Dec 5 15:40 po/libguestfs.pot-backup and I also checked the pot file (which is basically impossible) but it doesn't look as if messages are being dropped. Thanks, I'm going to push 1/3 and 3/3 for now. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones libguestfs lets you edit virtual machines. Supports shell scripting, bindings from many languages. http://libguestfs.org
Reasonably Related Threads
- Re: [PATCH 2/3] po: fix dependencies for libguestfs.pot extraction
- [PATCH 1/3] Fix manpage generation in out-of-tree builds
- Re: [PATCH 2/3] po: fix dependencies for libguestfs.pot extraction
- [v2v PATCH 00/14] Adaptations to Weblate
- [PATCH 0/9] Adaptations to Weblate