# Copyright (C) 1996-2002 Robert H”hne, see COPYING.RH for details 
# This file is part of RHIDE. 

# Current used languages with the corresponding translators.
# Not all of them are complete!! The only one which will be
# definitely complete is 'de' (maintained by me) :-)
#
# cs - Czech - 
# da - Danish -
# de - German - 
# es - Spanish - Salavador Eduardo Tropea <ice@inti.edu.ar>
# fi - Finnish -
# fr - French -
# it - Italian -
# nl - Dutch -
# no - Norwegian - Trond Endrestol <endrestol@hotmail.com>
# pl - Polish -
# pt - Portuguese -
# sv - Swedish -

CURRENT_LANGUAGES=cs da de es fi fr it nl no pl pt sv
FUTURE_LANGUAGES=ee ru # they were not ready when releasing RHIDE
LANGUAGES=$(CURRENT_LANGUAGES)
ADDITIONAL_LANG_es=$(wildcard $(REAL_SETSRC)/internac/es.po)

srcdir=$(RHIDESRC)/po
VPATH=$(srcdir)

project=msgcat
po_files=
src_files=$(po_files) msgcat.cc msgcat.gpr msgcat.mak Makefile \
	$(addsuffix .po,$(LANGUAGES)) \
	readme.lan makefile.src rhide.env rhide.var \
	$(addsuffix .cat,$(LANGUAGES))

projects=msgcat
cfg_files=

subdirs=
po_subdirs=..

include $(RHIDESRC)/common.mak

ifeq ($(msgfmt),)
msgfmt=msgfmt
endif

ifeq ($(xgettext),)
xgettext=xgettext
endif

MSGCAT=./msgcat.exe

_po_list: po_list
	@sed -e 's,^../,,' -e 's, ../, ,g' po_list > _po_list

potfiles.po: _po_list
	@echo $(xgettext) ....
	@$(xgettext) --default-domain=potfiles --add-comments --keyword=_ \
	  --keyword=__ --directory=$(RHIDESRC) --omit-header \
	  --add-location $(shell cat _po_list)
	@touch $@
	@rm -f _po_list

T=$(subst /,\,$@)

# I'm using now my own program to merge previous translations
# the rule here translates only the exact matchings. If you 
# want translate all the needed strings, look in the file
# msgcat.c for a description of it's usage
MSGCAT_OPTIONS=-s

CURRENT_LANG=$(subst .po,,$(notdir $@))
ADDITIONAL_LANG=$(ADDITIONAL_LANG_$(CURRENT_LANG))

po_deps=
ifeq ($(update_po_files),yes)
po_deps=potfiles.po $(MSGCAT)
endif

$(addsuffix .po,$(LANGUAGES)): $(po_deps)
	echo updating $@
	-cp -f $@ $(subst .po,.bak,$@)
	$(MSGCAT) $(MSGCAT_OPTIONS) -directory $(RHIDESRC) \
	  -cat $(subst .po,.cat,$@) \
	  -ocat __cat__ $(wildcard $@) $(ADDITIONAL_LANG) \
	  -po $< -o __po__
	$(move-if-change) __cat__ $(subst .po,.cat,$@)
	$(move-if-change) __po__ $@
	
%.mo: %.po
	@echo creating $@
	@-$(msgfmt) -o $@ $<
	@touch $@

languages: $(addsuffix .mo,$(LANGUAGES))

languages.src: $(addsuffix .po,$(LANGUAGES))

%.ins: %.mo
	$(INSTALL_DIR) $(prefix)/$(install_localedir)/$*/LC_MESSAGES
	$(INSTALL_DATA) $< $(prefix)/$(install_localedir)/$*/LC_MESSAGES/$(PACKAGE).mo
	echo $(install_localedir)/$*/LC_MESSAGES/$(PACKAGE).mo >> $(logfile)

install.languages.start:
	rm -f $(logfile)

install.languages: languages install.languages.start \
	  $(addsuffix .ins,$(LANGUAGES))

install:: install.languages

%.zip: %.po
	rm -f $@
	zip -9j $@ $< $(subst .po,.cat,$<) potfiles.po $(MSGCAT) $(msgfmt) \
	  $(srcdir)/readme.lan
	
$(addsuffix .zip,$(LANGUAGES)): $(MSGCAT)

translate:
ifeq ($(TRANS_LANG),)
	@echo Please run \"make translate TRANS_LANG=de\", where
	@echo you should replace \"de\" with the language you
	@echo want to translate
else
	$(MAKE) $(TRANS_LANG).po MSGCAT_OPTIONS=
endif

lang_packages: $(addsuffix .zip,$(LANGUAGES))

