From 442ea2db71a15666ba4937c5a73bbff2169cf63f Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Thu, 14 Jul 2022 06:33:14 +0200 Subject: [PATCH 1/8] Fix handling of plural strings Properly use ngettext() to translate strings with singular/plural forms, instead of hardcoding a n==1 check for any language. Add an inline fallback ngettext() implementation for the "no i18n" case. --- defaults.h | 6 ------ linux_logo.c | 20 +++++++++----------- 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/defaults.h b/defaults.h index 3c661d6..dbcffad 100644 --- a/defaults.h +++ b/defaults.h @@ -7,12 +7,6 @@ \* information on how to configure this option. */ char DEFAULT_BANNER_FORMAT[]= S_("#O Version #V, Compiled #C\n#N #M #X #T #P, #R RAM, #B\n#H\n"); char DEFAULT_CLASSIC_FORMAT[]= S_("#O Version #V\nCompiled #C\n#N #M #X #T #P, #R RAM\n#B\n#H\n"); -/* Plural. With the coming of i18n you really can't assume plurals can */ -/* be made by adding a string to the end. Hopefully this can fix it for*/ -/* most languages. If they require significant word-order changes then */ -/* we'll have even more problems */ -char PROCESSOR_SINGULAR[]= S_("Processor"); -char PROCESSOR_PLURAL[]= S_("Processors"); /* This option picks the default mode of the linux_logo program. *\ \* If a 1 is picked, banner mode will be the default mode. */ diff --git a/linux_logo.c b/linux_logo.c index b166180..e55bb4e 100644 --- a/linux_logo.c +++ b/linux_logo.c @@ -31,6 +31,10 @@ #define _(String) gettext((String)) #else #define _(String) (String) +static const char *ngettext(const char *__msgid1, const char *__msgid2, + unsigned long int __n) { + return __n == 1 ? __msgid1:__msgid2; +} #endif /* Change the values in the below file to alter default behavior */ @@ -385,17 +389,11 @@ static int generate_sysinfo( case 'O': vmw_strcat(temp_line,os_info.os_name, BUFSIZ-strlen(temp_line)); break; - /* #P prints "Processor" or its plural. Sort of a hack */ - /* This probably doesn't work with all languages */ - case 'P': if (cpu_info.num_cpus!=1) { - vmw_strcat(temp_line,_(PROCESSOR_PLURAL), - BUFSIZ-strlen(temp_line)); - } - else { - vmw_strcat(temp_line,_(PROCESSOR_SINGULAR), - BUFSIZ-strlen(temp_line)); - } - break; + /* #P prints "Processor" or its plural */ + case 'P': vmw_strcat(temp_line, + ngettext("Processor","Processors",cpu_info.num_cpus), + BUFSIZ-strlen(temp_line)); + break; /* #R prints the amount of memory */ case 'R': mem_size=get_mem_size(); From cf46d70d0f5fbf4a60fac98f6cb9cff03ed03fa2 Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Thu, 14 Jul 2022 06:44:58 +0200 Subject: [PATCH 2/8] po: drop messages.po Remove messages.po, which is the default output file name of xgettext; there is already linux_logo.pot as template. --- .gitignore | 1 + po/messages.po | 89 -------------------------------------------------- 2 files changed, 1 insertion(+), 89 deletions(-) create mode 100644 .gitignore delete mode 100644 po/messages.po diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c11a27d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/po/messages.po diff --git a/po/messages.po b/po/messages.po deleted file mode 100644 index dfbccfb..0000000 --- a/po/messages.po +++ /dev/null @@ -1,89 +0,0 @@ -# SOME DESCRIPTIVE TITLE. -# Copyright (C) YEAR Free Software Foundation, Inc. -# FIRST AUTHOR , YEAR. -# -#, fuzzy -msgid "" -msgstr "" -"Project-Id-Version: PACKAGE VERSION\n" -"POT-Creation-Date: 2001-03-16 17:23-0500\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: ENCODING\n" - -#: ../linux_logo.c:38 -msgid "Zero" -msgstr "" - -#: ../linux_logo.c:39 -msgid "One" -msgstr "" - -#: ../linux_logo.c:40 -msgid "Two" -msgstr "" - -#: ../linux_logo.c:41 -msgid "Three" -msgstr "" - -#: ../linux_logo.c:42 -msgid "Four" -msgstr "" - -#: ../linux_logo.c:43 -msgid "Five" -msgstr "" - -#: ../linux_logo.c:44 -msgid "Six" -msgstr "" - -#: ../linux_logo.c:45 -msgid "Seven" -msgstr "" - -#: ../linux_logo.c:46 -msgid "Eight" -msgstr "" - -#: ../linux_logo.c:47 -msgid "Nine" -msgstr "" - -#: ../linux_logo.c:48 -msgid "Many" -msgstr "" - -#. This is the default format of the output file. See the README for more *\ -#. \* information on how to configure this option. -#: ../defaults.h:7 -msgid "" -"#O Version #V, Compiled #C\n" -"#N #M #X #T #P, #R RAM, #B\n" -"#H\n" -msgstr "" - - -#: ../defaults.h:8 -msgid "" -"#O Version #V\n" -"Compiled #C\n" -"#N #M #X #T #P, #R RAM\n" -"#B\n" -"#H\n" -msgstr "" - -#: ../defaults.h:9 -msgid "" -"Processor" -msgstr "" - -#: ../defaults.h:10 -msgid "" -"Processors" -msgstr "" - From 1f71700978b9ddd1a41dd8c80d39331586e51856 Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Thu, 14 Jul 2022 06:55:15 +0200 Subject: [PATCH 3/8] po: simplify rules for gettext files Use makefile functions to get the list of available translations, instead of hardcoding them. Build the list of languages, and expected mo files from that as well. Iterate on languages, as it is easier (no need to drop the suffix manually every time). --- po/Makefile | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/po/Makefile b/po/Makefile index ce732f9..bdc82eb 100644 --- a/po/Makefile +++ b/po/Makefile @@ -3,7 +3,9 @@ include ../Makefile.default PACKAGE=linux_logo INSTALL_LOCALEPATH=$(PREFIX)/share/locale -CATALOGS = da.mo de.mo es.mo fr.mo nb.mo nl.mo it.mo pl.mo pt_BR.mo ru.mo sv.mo uk.mo zh_TW.mo +PO_FILES = $(wildcard *.po) +LINGUAS = $(basename $(PO_FILES)) +CATALOGS = $(addsuffix .mo,$(LINGUAS)) POTFILES= ../*.c ../*.h @@ -21,19 +23,17 @@ clean: rm -f *mo *~ *.bac install: $(CATALOGS) - for n in $(CATALOGS); do \ - l=`basename $$n .mo`; \ + for l in $(LINGUAS); do \ $(INSTALL) -c -m 755 -d $(INSTALL_LOCALEPATH)/$$l; \ $(INSTALL) -c -m 755 -d $(INSTALL_LOCALEPATH)/$$l/LC_MESSAGES; \ - $(INSTALL) -c -m 644 $$n $(INSTALL_LOCALEPATH)/$$l/LC_MESSAGES/$(PACKAGE).mo; \ + $(INSTALL) -c -m 644 $$l.mo $(INSTALL_LOCALEPATH)/$$l/LC_MESSAGES/$(PACKAGE).mo; \ done %.mo: %.po msgfmt -o $@ $< update: $(PACKAGE).pot - for n in $(CATALOGS); do \ - l=`basename $$n .mo`; \ + for l in $(LINGUAS); do \ l=$$l".po"; \ mv -f $$l $$l".bac"; \ msgmerge -o $$l $$l".bac" $(PACKAGE).pot; \ From 55d32970ec4c7d1875b1f19bafd6293bd4d1bc4a Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Thu, 14 Jul 2022 06:58:41 +0200 Subject: [PATCH 4/8] po: check translations on conversions Pass -c/--check to msgfmt, so it checks the validity of the po files, rejecting invalid files. There are no invalid translations in the current sources, so this is a no-op change that will prevent mistakes in the future. --- po/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/po/Makefile b/po/Makefile index bdc82eb..73e766a 100644 --- a/po/Makefile +++ b/po/Makefile @@ -30,7 +30,7 @@ install: $(CATALOGS) done %.mo: %.po - msgfmt -o $@ $< + msgfmt -c -o $@ $< update: $(PACKAGE).pot for l in $(LINGUAS); do \ From 2b0e7a46afa792985d37f711ce762666bcbc7fd8 Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Thu, 14 Jul 2022 07:05:28 +0200 Subject: [PATCH 5/8] po: use --previous for msgmerge This way, the old msgid are preserved when a message is changed and becomes fuzzy; this helps translators as they can easily see how the msgid changed. --- po/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/po/Makefile b/po/Makefile index 73e766a..1707d79 100644 --- a/po/Makefile +++ b/po/Makefile @@ -36,5 +36,5 @@ update: $(PACKAGE).pot for l in $(LINGUAS); do \ l=$$l".po"; \ mv -f $$l $$l".bac"; \ - msgmerge -o $$l $$l".bac" $(PACKAGE).pot; \ + msgmerge --previous -o $$l $$l".bac" $(PACKAGE).pot; \ done From 7e3b8d3c2e6ad2051317eee6b93a5fdb9c815a7a Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Thu, 14 Jul 2022 07:12:33 +0200 Subject: [PATCH 6/8] build: add DESTDIR support also to translations Followup of commit e0a39f76720bbb9c424503e8069f35466782eb17. --- po/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/po/Makefile b/po/Makefile index 1707d79..a65a9c6 100644 --- a/po/Makefile +++ b/po/Makefile @@ -1,7 +1,7 @@ include ../Makefile.default PACKAGE=linux_logo -INSTALL_LOCALEPATH=$(PREFIX)/share/locale +INSTALL_LOCALEPATH=$(DESTDIR)$(PREFIX)/share/locale PO_FILES = $(wildcard *.po) LINGUAS = $(basename $(PO_FILES)) From 003127c9699a531b41cdc68ec01582730fa49cfb Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Thu, 14 Jul 2022 07:17:00 +0200 Subject: [PATCH 7/8] po: simplify xgettext rule Every time xgettext is run, the generated template has its own POT-Creation-Date field with the runtime timestamp; because of this, the comparison between the existing template and the new one (using `cmp`) always results as "different". Hence, simply run xgettext with the wanted output file, as the result is the same; make use of the automatic make variables to avoid repeating variables in the command invocation. --- po/Makefile | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/po/Makefile b/po/Makefile index a65a9c6..89b0b74 100644 --- a/po/Makefile +++ b/po/Makefile @@ -12,12 +12,7 @@ POTFILES= ../*.c ../*.h all: $(PACKAGE).pot $(CATALOGS) $(PACKAGE).pot: $(POTFILES) - $(XGETTEXT) --default-domain=$(PACKAGE) --add-comments --keyword=_ --keyword=S_ $(POTFILES); - if cmp -s $(PACKAGE).po $(PACKAGE).pot; then \ - rm -f $(PACKAGE).po; \ - else \ - mv $(PACKAGE).po $(PACKAGE).pot; \ - fi + $(XGETTEXT) --output=$@ --default-domain=$(PACKAGE) --add-comments --keyword=_ --keyword=S_ $^ clean: rm -f *mo *~ *.bac From 933333ddc34a801ea32c2ae056c8cfcb9e00212c Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Thu, 14 Jul 2022 07:22:31 +0200 Subject: [PATCH 8/8] build: stop updating the catalog on 'all' While it can be useful to keep the translation catalog up-to-date, updating it every time a file is changed is a bit wasteful. Hence, do not ensure that the pot file is updated on 'all'. This will likely require some manual update from time to time to make sure that the translatable messages are still up-to-date, however they do not change that often in linuxlogo. --- po/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/po/Makefile b/po/Makefile index 89b0b74..440ca13 100644 --- a/po/Makefile +++ b/po/Makefile @@ -9,7 +9,7 @@ CATALOGS = $(addsuffix .mo,$(LINGUAS)) POTFILES= ../*.c ../*.h -all: $(PACKAGE).pot $(CATALOGS) +all: $(CATALOGS) $(PACKAGE).pot: $(POTFILES) $(XGETTEXT) --output=$@ --default-domain=$(PACKAGE) --add-comments --keyword=_ --keyword=S_ $^