##----------------------------------------------------------------------
## The following part defines rules for i18n.
## See https://github.com/besport/ocsigen-i18n for more information.

I18N_CHECKER            := ocsigen-i18n-checker
I18N_GENERATOR          := ocsigen-i18n-generator

## The i18n generated file.
## IMPROVEME: Due to %%%PROJECT_NAME%%%_language, the module
## defining all translations must be static.
I18N_ELIOM_FILE         := $(PROJECT_NAME)_i18n.eliom

## PPX extension to rewrite each file while compiling.
I18N_PPX_REWRITER       := "ocsigen-i18n-rewriter --prefix '%%%MODULE_NAME%%%_' --suffix '_i18n' --default-module %%%MODULE_NAME%%%_i18n"

## This rule will update the primary I18N module
$(I18N_ELIOM_FILE): $(I18N_PRIMARY_FILE)
# use LC_ALL=C so that all $(I18N_ELIOM_FILE) files are generated the same
# way.
	LC_ALL=C $(I18N_GENERATOR) \
	--languages $(I18N_LANGUAGES) \
	--default-language $(I18N_DEFAULT_LANGUAGE) \
	< $(I18N_PRIMARY_FILE) \
	> $(I18N_ELIOM_FILE)

## This rule will update all other I18N modules
$(PROJECT_NAME)_%_i18n.eliom: $(I18N_TSV_DIR)$(PROJECT_NAME)_%_i18n.tsv
# use LC_ALL=C so that all I18N files are generated the same
# way.
	LC_ALL=C $(I18N_GENERATOR) \
	--languages $(I18N_LANGUAGES) \
	--default-language $(I18N_DEFAULT_LANGUAGE) \
	--primary $(notdir $(I18N_PRIMARY_FILE)) \
	< $< \
	> $@


i18n-check:
	$(I18N_CHECKER) ./*.eliom < $(I18N_TSV_FILE)

.PHONY: i18n-clean
i18n-clean:
	-rm -f $(notdir $(patsubst %.tsv,%.eliom,$(I18N_PRIMARY_FILE)	\
						 $(I18N_EXTRA_FILES)))

## end of i18n
##----------------------------------------------------------------------
