po: merge translations for metainfo file

When installing the module, instead of copying the metainfo file to the
destination, merge the available translations for it. Since this is done
at install time, add gettext as BuildRequires for the RPM packaging;
add libappstream-glib-devel as well only on RHEL/CentOS 8, since it
contains the metainfo.its for gettext in order to handle .metainfo.xml
files.

This requires a LINGUAS file with the list of translations currently
available: this is the way msgfmt picks the available languages to
merge. Generate it dynamically from the list of available .po files.
This commit is contained in:
Pino Toscano 2022-03-08 19:07:20 +01:00 committed by Martin Pitt
parent b5969c1c9b
commit 4377c4fe19
3 changed files with 13 additions and 2 deletions

1
.gitignore vendored
View file

@ -15,3 +15,4 @@ src/lib/
*.pot *.pot
POTFILES* POTFILES*
tmp/ tmp/
/po/LINGUAS

View file

@ -46,6 +46,9 @@ po/$(PACKAGE_NAME).metainfo.pot: org.cockpit-project.$(PACKAGE_NAME).metainfo.xm
po/$(PACKAGE_NAME).pot: po/$(PACKAGE_NAME).html.pot po/$(PACKAGE_NAME).js.pot po/$(PACKAGE_NAME).manifest.pot po/$(PACKAGE_NAME).metainfo.pot po/$(PACKAGE_NAME).pot: po/$(PACKAGE_NAME).html.pot po/$(PACKAGE_NAME).js.pot po/$(PACKAGE_NAME).manifest.pot po/$(PACKAGE_NAME).metainfo.pot
msgcat --sort-output --output-file=$@ $^ msgcat --sort-output --output-file=$@ $^
po/LINGUAS:
echo $(LINGUAS) | tr ' ' '\n' > $@
# Update translations against current PO template # Update translations against current PO template
update-po: po/$(PACKAGE_NAME).pot update-po: po/$(PACKAGE_NAME).pot
for lang in $(LINGUAS); do \ for lang in $(LINGUAS); do \
@ -68,12 +71,15 @@ watch:
clean: clean:
rm -rf dist/ rm -rf dist/
rm -f $(SPEC) rm -f $(SPEC)
rm -f po/LINGUAS
install: $(WEBPACK_TEST) install: $(WEBPACK_TEST) po/LINGUAS
mkdir -p $(DESTDIR)/usr/share/cockpit/$(PACKAGE_NAME) mkdir -p $(DESTDIR)/usr/share/cockpit/$(PACKAGE_NAME)
cp -r dist/* $(DESTDIR)/usr/share/cockpit/$(PACKAGE_NAME) cp -r dist/* $(DESTDIR)/usr/share/cockpit/$(PACKAGE_NAME)
mkdir -p $(DESTDIR)/usr/share/metainfo/ mkdir -p $(DESTDIR)/usr/share/metainfo/
cp org.cockpit-project.$(PACKAGE_NAME).metainfo.xml $(DESTDIR)/usr/share/metainfo/ msgfmt --xml -d po \
--template org.cockpit-project.$(PACKAGE_NAME).metainfo.xml \
-o $(DESTDIR)/usr/share/metainfo/org.cockpit-project.$(PACKAGE_NAME).metainfo.xml
# this requires a built source tree and avoids having to install anything system-wide # this requires a built source tree and avoids having to install anything system-wide
devel-install: $(WEBPACK_TEST) devel-install: $(WEBPACK_TEST)

View file

@ -10,6 +10,10 @@ BuildArch: noarch
BuildRequires: nodejs BuildRequires: nodejs
BuildRequires: make BuildRequires: make
BuildRequires: libappstream-glib BuildRequires: libappstream-glib
BuildRequires: gettext
%if 0%{?rhel} && 0%{?rhel} <= 8
BuildRequires: libappstream-glib-devel
%endif
Requires: cockpit-system Requires: cockpit-system