# po/Makefile — build/install lxtaz-ctrl translations (.po -> .mo).
#
#   make              build every lang in LINGUAS
#   make install      install .mo files (honors DESTDIR + PREFIX)
#   make update-pot   regenerate lxtaz-ctrl.pot from POTFILES.in (maintainer)
#   make check        validate .po files (format strings, headers)
#   make clean        drop built .mo files (never the .po sources)
#
# New language: copy fr.po -> <lang>.po, translate msgstr, add <lang> to LINGUAS.
#
# Copyright (C) 2026 SliTaz GNU/Linux - BSD License
# Author: Christophe Lincoln <pankso@slitaz.org>
# AI assistant: OpenCode
# Reviewer: Claude (Anthropic)

DOMAIN    := lxtaz-ctrl
# LINGUAS holds bare ISO-639 codes (whitespace separated, no comments).
LINGUAS   := $(shell cat LINGUAS)
MO_FILES  := $(LINGUAS:%=%.mo)
PREFIX    ?= /usr
LOCALEDIR ?= $(PREFIX)/share/locale

all: $(MO_FILES)

%.mo: %.po
	msgfmt --check -o $@ $<

install: all
	for l in $(LINGUAS); do \
		install -Dm644 $$l.mo $(DESTDIR)$(LOCALEDIR)/$$l/LC_MESSAGES/$(DOMAIN).mo; \
	done

update-pot:
	xgettext --from-code=UTF-8 \
		--keyword=_ --keyword=N_ --keyword=ngettext:1,2 \
		--language=C --add-comments \
		--package-name=$(DOMAIN) \
		-o $(DOMAIN).pot -f POTFILES.in

check: all
	for p in $(LINGUAS:%=%.po); do \
		msgfmt --check --statistics $$p -o /dev/null; \
	done

clean:
	rm -f $(MO_FILES)

.PHONY: all install update-pot check clean
