package = PACKAGE
module = MODULE
version = VERSION
locale = LOCALE

# override with e.g. htmltemplate when handling non-Markdown files
fileformat = text

# Percentage of l10n completed to be acceptable
threshold = 100

# l10nfiles: relative paths to localizable files

# Invoke from inside basedir of master files
# potfile: path to POT file
mkpot:
	po4a-gettextize -M UTF-8 -L UTF-8 -f "$(fileformat)" -o markdown $(patsubst %,-m %,$(l10nfiles)) -p "$(potfile)"
	sed -i \
	  -e 's/^# SOME DESCRIPTIVE TITLE/# $(locale) translation of $(module) pages for $(package)./' \
	  -e '/^# This file/ s/PACKAGE/$(package)/' \
	  -e '/^"Project-Id-Version:/ s/PACKAGE/$(package) $(module)/' \
	  -e '/^"Project-Id-Version:/ s/VERSION/$(version)/' \
	  -e '/^"Content-Type:/ s/CHARSET/UTF-8/' \
	  -e '/^"Content-Transfer-Encoding:/ s/ENCODING/8bit/' \
	  "$(potfile)"

# Invoke from root dir of translated files
# masterdir: path to dir containing untranslated files
# pofile: path to PO file
mkpo:
	po4a-gettextize -M UTF-8 -L UTF-8 -f "$(fileformat)" -o markdown $(patsubst %,-m %,$(l10nfiles)) $(patsubst %,-l $(masterdir)/%,$(l10nfiles)) -p "$(pofile)"

# Invoke from inside basedir of master files
# pofile: path to PO file
updatepo:
	po4a-updatepo -M UTF-8 -f "$(fileformat)" -o markdown $(patsubst %,-m %,$(l10nfiles)) -p "$(pofile)"

# Invoke from root dir of translated files
# masterdir: path to dir containing untranslated files
# pofile: path to PO file
$(l10nfiles): % : $(masterdir)/%
	po4a-translate -M UTF-8 -L UTF-8 -k "$(threshold)" -f "$(fileformat)" -o markdown $(patsubst %,-m $(masterdir)/%,$@) -p "$(pofile)" -l "$@"

.PHONY: mkpot mkpo $(l10nfiles)