3 # Common rules for Native Language Support (NLS)
5 # If some subdirectory of the source tree wants to provide NLS, it
6 # needs to contain a file 'nls.mk' with the following make variable
9 # CATALOG_NAME -- name of the message catalog (xxx.po); probably
11 # AVAIL_LANGUAGES -- list of languages that are provided/supported
12 # GETTEXT_FILES -- list of source files that contain message strings
13 # GETTEXT_TRIGGERS -- (optional) list of functions that contain
14 # translatable strings
16 # That's all, the rest is done here, if --enable-nls was specified.
18 # The only user-visible targets here are 'init-po', to make an initial
19 # "blank" catalog from program sources, and 'update-po', which is to
20 # be called if the messages in the program source have changed, in
21 # order to merge the changes into the existing .po files.
24 # existence checked by Makefile.global; otherwise we won't get here
25 include $(srcdir)/nls.mk
27 # If user specified the languages he wants in --enable-nls=LANGUAGES,
28 # filter out the rest. Else use all available ones.
29 ifdef WANTED_LANGUAGES
30 LANGUAGES = $(filter $(WANTED_LANGUAGES), $(AVAIL_LANGUAGES))
32 LANGUAGES = $(AVAIL_LANGUAGES)
35 PO_FILES = $(addprefix po/, $(addsuffix .po, $(LANGUAGES)))
36 MO_FILES = $(addprefix po/, $(addsuffix .mo, $(LANGUAGES)))
39 XGETTEXT += -ctranslator --copyright-holder='PostgreSQL Global Development Group' --msgid-bugs-address=pgsql-bugs@postgresql.org
42 # _ is defined in c.h, so it's global
51 ifeq ($(word 1,$(GETTEXT_FILES)),+)
52 po/$(CATALOG_NAME).pot: $(word 2, $(GETTEXT_FILES)) $(MAKEFILE_LIST)
54 $(XGETTEXT) -D $(srcdir) -n $(addprefix -k, $(GETTEXT_TRIGGERS)) -f $<
56 @echo "You don't have 'xgettext'."; exit 1
59 po/$(CATALOG_NAME).pot: $(GETTEXT_FILES) $(MAKEFILE_LIST)
60 # Change to srcdir explicitly, don't rely on $^. That way we get
61 # consistent #: file references in the po files.
63 $(XGETTEXT) -D $(srcdir) -n $(addprefix -k, $(GETTEXT_TRIGGERS)) $(GETTEXT_FILES)
65 @echo "You don't have 'xgettext'."; exit 1
69 sed -e '1,18 { s/SOME DESCRIPTIVE TITLE./LANGUAGE message translation file for $(CATALOG_NAME)/;s/PACKAGE/PostgreSQL/g;s/VERSION/$(MAJORVERSION)/g;s/YEAR/'`date +%Y`'/g; }' messages.po >$@
73 # catalog name extentions must match behavior of PG_TEXTDOMAIN() in c.h
74 install-po: all-po installdirs-po
76 for lang in $(LANGUAGES); do \
77 $(INSTALL_DATA) po/$$lang.mo '$(DESTDIR)$(localedir)'/$$lang/LC_MESSAGES/$(CATALOG_NAME)$(SO_MAJOR_VERSION)-$(MAJORVERSION).mo || exit 1; \
82 $(if $(LANGUAGES),$(MKDIR_P) $(foreach lang, $(LANGUAGES), '$(DESTDIR)$(localedir)'/$(lang)/LC_MESSAGES),:)
85 $(if $(LANGUAGES),rm -f $(foreach lang, $(LANGUAGES), '$(DESTDIR)$(localedir)'/$(lang)/LC_MESSAGES/$(CATALOG_NAME)$(SO_MAJOR_VERSION)-$(MAJORVERSION).mo),:)
89 $(if $(MO_FILES),rm -f $(MO_FILES))
90 @$(if $(wildcard po/*.po.new),rm -f po/*.po.new)
91 rm -f po/$(CATALOG_NAME).pot
94 maintainer-check-po: $(PO_FILES)
96 $(MSGFMT) -c -v -o /dev/null $$file || exit 1; \
100 init-po: po/$(CATALOG_NAME).pot
103 # For performance reasons, only calculate these when the user actually
104 # requested update-po or a specific file.
105 ifneq (,$(filter update-po %.po.new,$(MAKECMDGOALS)))
106 ALL_LANGUAGES := $(shell find $(top_srcdir) -name '*.po' -print | sed 's,^.*/\([^/]*\).po$$,\1,' | sort -u)
107 all_compendia := $(shell find $(top_srcdir) -name '*.po' -print)
109 ALL_LANGUAGES = $(AVAIL_LANGUAGES)
110 all_compendia = FORCE
114 ifdef WANTED_LANGUAGES
115 ALL_LANGUAGES := $(filter $(WANTED_LANGUAGES), $(ALL_LANGUAGES))
118 update-po: $(ALL_LANGUAGES:%=po/%.po.new)
120 $(AVAIL_LANGUAGES:%=po/%.po.new): po/%.po.new: po/%.po po/$(CATALOG_NAME).pot $(all_compendia)
121 $(MSGMERGE) $(word 1, $^) $(word 2,$^) -o $@ $(addprefix --compendium=,$(filter %/$*.po,$(wordlist 3,$(words $^),$^)))
123 # For languages not yet available, merge against oneself, to pick
124 # up translations from the compendia. (Merging against /dev/null
125 # doesn't work so well; it inserts the headers from the first-named
127 po/%.po.new: po/$(CATALOG_NAME).pot $(all_compendia)
128 $(MSGMERGE) $(word 1,$^) $(word 1,$^) -o $@ $(addprefix --compendium=,$(filter %/$*.po,$(wordlist 2,$(words $^),$^)))
133 installdirs: installdirs-po
134 uninstall: uninstall-po
135 clean distclean maintainer-clean: clean-po
136 maintainer-check: maintainer-check-po
138 .PHONY: all-po install-po installdirs-po uninstall-po clean-po \
139 maintainer-check-po init-po update-po