po: Use xgettext over msgcat for POT-files

`msgcat` gives a warning nowadays stating that it is more for PO-files
and shouldn't be used for merging POT-files. Instead it recommends that
we use `xgettext` for that as `msgcat` could produce output that isn't
intended.

As a caveat to using `xgettext` for concatenating POT-files it also
throws errors when the set charset for the source POT-files differ from
each other. Some of the POT-files, namely `po/cockpit.js.pot` and
`po/cockpit.appstream.pot`, don't get charset configured correctly and
instead shows `charset=CHARSET` by default.

While this now includes `sed` replace for the charsets as a way to
force-configure it as UTF-8, efforts were made to solve the issue
using supported means. With the research I did I found that there are
`--from-code=UTF-8` which we already utilize and should tell `xgettext`
about the charset. If it detects anything that isn't UTF-8 it will
ignore the `--from-code` value AFAICT and therefore won't set the
charset. There has been attempts to find other solutions but non were found.

See-also: https://www.gnu.org/software/gettext/manual/html_node/msgcat-Invocation.html#Invoking-the-msgcat-Program
See-also: https://www.gnu.org/software/gettext/manual/html_node/Combining-POTs.html
Introduced-in: df13e4104f
Fixes: https://github.com/cockpit-project/cockpit/issues/23757
Signed-off-by: Freya Gustavsson <freya@venefilyn.se>
This commit is contained in:
Freya Gustavsson 2026-09-18 16:14:04 +02:00
parent b1c58b672f
commit 709aac3638

View file

@ -8,6 +8,7 @@ po/cockpit.html.pot: $(srcdir)/package-lock.json
$$(cd $(srcdir) && find pkg/ -name '*.html')
# Extract cockpit style javascript translations
# Recommended to have appstream installed as it includes the newest metadata its files
po/cockpit.js.pot:
$(AM_V_GEN) mkdir -p $(dir $@) && \
xgettext --default-domain=cockpit --output=- --language=C --keyword= \
@ -18,7 +19,8 @@ po/cockpit.js.pot:
--keyword=gettextCatalog.getString:1,3c --keyword=gettextCatalog.getPlural:2,3,4c \
--from-code=UTF-8 --directory=$(srcdir) \
$$( cd $(srcdir) && find pkg/ ! -name 'test-*' -name '*.[jt]s' -o -name '*.[jt]sx') | \
sed '/^#/ s/, c-format//' > $@
sed '/^#/ s/, c-format//' > $@ && \
sed -i 's/charset=CHARSET/charset=UTF-8/g' $@
po/cockpit.manifest.pot:
$(AM_V_GEN) mkdir -p $(dir $@) && \
@ -28,17 +30,19 @@ po/cockpit.manifest.pot:
po/cockpit.appstream.pot:
$(AM_V_GEN) mkdir -p $(dir $@) && \
GETTEXTDATADIRS=$(srcdir)/po xgettext --output=$@ --directory=$(srcdir) \
$$(cd $(srcdir) && find pkg/ src/ -name '*.appdata.xml.in' -o -name '*.metainfo.xml.in')
$$(cd $(srcdir) && find pkg/ src/ -name '*.appdata.xml.in' -o -name '*.metainfo.xml.in') && \
sed -i 's/charset=CHARSET/charset=UTF-8/g' $@
po/cockpit.polkit.pot:
$(AM_V_GEN) mkdir -p $(dir $@) && \
GETTEXTDATADIRS=$(srcdir)/po xgettext --output=$@ --directory=$(srcdir) \
$$(cd $(srcdir) && find src/ -name '*.policy.in')
$$(cd $(srcdir) && find src/ -name '*.policy.in') && \
sed -i 's/charset=CHARSET/charset=UTF-8/g' $@
# Combine the above pot files into one
po/cockpit.pot: po/cockpit.html.pot po/cockpit.js.pot po/cockpit.manifest.pot po/cockpit.appstream.pot po/cockpit.polkit.pot
$(AM_V_GEN) mkdir -p $(dir $@) && \
msgcat --sort-output --output-file=$@ $^
xgettext --output=$@ $^
CLEANFILES += \
dist/shell/*.po \