diff --git a/.gitignore b/.gitignore index 0cb00dca..d4fb5e6d 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ settings.toml .secrets.toml /rhc*.tar.* /vendor/ +*.mo diff --git a/Makefile b/Makefile index e9565e46..a5c4d575 100644 --- a/Makefile +++ b/Makefile @@ -1,13 +1,20 @@ .ONESHELL: .SHELLFLAGS := -e -c -VERSION := $(shell rpmspec rhc.spec --query --queryformat '%{version}') +VERSION := $(shell rpmspec rhc.spec --query --queryformat '%{version}\n' | head -n 1) # The 'build' target is not used during packaging; it is present for upstream development purposes. .PHONY: build build: go build -ldflags "-X main.Version=$(VERSION)" -o rhc ./cmd/rhc +# Compile translation files (.po -> .mo) +.PHONY: i18n +i18n: + @for file in po/*/LC_MESSAGES/*.po; do \ + msgfmt --check -o $${file%.po}.mo $$file; \ + done + .PHONY: archive archive: git archive --prefix rhc-$(VERSION)/ --format tar.gz HEAD > rhc-$(VERSION).tar.gz @@ -22,3 +29,4 @@ srpm: archive clean: rm -f rhc rm -f rhc-*.tar* + find po -name "*.mo" -type f -delete diff --git a/rhc.spec b/rhc.spec index df77361c..8dece130 100644 --- a/rhc.spec +++ b/rhc.spec @@ -19,6 +19,7 @@ Source2: go-vendor-tools.toml BuildRequires: go-vendor-tools BuildRequires: systemd-rpm-macros +BuildRequires: gettext %if 0%{?with_check} BuildRequires: /usr/bin/dbus-launch %endif @@ -49,6 +50,9 @@ export GO_LDFLAGS="-X main.Version=%{version} -X main.ServiceName=yggdrasil" # Generate man page %{gobuilddir}/bin/rhc --generate-man-page > rhc.1 +# Compile translation files (.po -> .mo)รง +make i18n + %install # Licenses %go_vendor_license_install -c %{S:2} @@ -73,6 +77,14 @@ install -m 0755 -vd %{buildroot}%{_sysconfdir}/%{name}/ install -m 0755 -vd %{buildroot}%{_unitdir}/yggdrasil.service.d/ install -m 0644 -vp %{buildroot}%{_unitdir}/yggdrasil.service.d/rhcd.conf %{buildroot}%{_unitdir}/yggdrasil.service.d/ %endif +# Localization files +for mo_file in po/*/LC_MESSAGES/*.mo; do + if [ -f "$mo_file" ]; then + lang=$(echo $mo_file | sed 's|po/\(.*\)/LC_MESSAGES/.*|\1|') + install -m 0755 -vd %{buildroot}%{_prefix}/local/share/locale/$lang/LC_MESSAGES + install -m 0644 -vp $mo_file %{buildroot}%{_prefix}/local/share/locale/$lang/LC_MESSAGES/rhc.mo + fi +done %check %go_vendor_license_check -c %{S:2} @@ -113,6 +125,8 @@ fi %if 0%{?with_rhcd_compat} %{_unitdir}/yggdrasil.service.d/rhcd.conf %endif +# Localization +%{_prefix}/local/share/locale/*/LC_MESSAGES/rhc.mo %changelog %autochangelog