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
15 # GETTEXT_FLAGS -- (optional) list of gettext --flag arguments to mark
16 # function arguments that contain C format strings
17 # (functions must be listed in TRIGGERS and FLAGS)
19 # That's all, the rest is done here, if --enable-nls was specified.
21 # The only user-visible targets here are 'init-po', to make an initial
22 # "blank" catalog from program sources, and 'update-po', which is to
23 # be called if the messages in the program source have changed, in
24 # order to merge the changes into the existing .po files.
27 # existence checked by Makefile.global; otherwise we won't get here
28 include $(srcdir)/nls.mk
30 # If user specified the languages he wants in --enable-nls=LANGUAGES,
31 # filter out the rest. Else use all available ones.
32 ifdef WANTED_LANGUAGES
33 LANGUAGES = $(filter $(WANTED_LANGUAGES), $(AVAIL_LANGUAGES))
35 LANGUAGES = $(AVAIL_LANGUAGES)
38 PO_FILES = $(addprefix po/, $(addsuffix .po, $(LANGUAGES)))
39 ALL_PO_FILES = $(addprefix po/, $(addsuffix .po, $(AVAIL_LANGUAGES)))
40 MO_FILES = $(addprefix po/, $(addsuffix .mo, $(LANGUAGES)))
43 XGETTEXT += -ctranslator --copyright-holder='PostgreSQL Global Development Group' --msgid-bugs-address=pgsql-bugs@postgresql.org --no-wrap --sort-by-file --package-name='$(CATALOG_NAME) (PostgreSQL)' --package-version='$(MAJORVERSION)'
47 MSGMERGE += --no-wrap --sort-by-file
50 # _ is defined in c.h, so it's global
52 GETTEXT_FLAGS += _:1:pass-c-format
55 # common settings that apply to backend and all backend modules
56 BACKEND_COMMON_GETTEXT_TRIGGERS = \
57 errmsg errmsg_plural:1,2 \
58 errdetail errdetail_log errdetail_plural:1,2 \
61 BACKEND_COMMON_GETTEXT_FLAGS = \
62 errmsg:1:c-format errmsg_plural:1:c-format errmsg_plural:2:c-format \
63 errdetail:1:c-format errdetail_log:1:c-format errdetail_plural:1:c-format errdetail_plural:2:c-format \
73 ifeq ($(word 1,$(GETTEXT_FILES)),+)
74 po/$(CATALOG_NAME).pot: $(word 2, $(GETTEXT_FILES)) $(MAKEFILE_LIST)
76 $(XGETTEXT) -D $(srcdir) -n $(addprefix -k, $(GETTEXT_TRIGGERS)) $(addprefix --flag=, $(GETTEXT_FLAGS)) -f $<
78 @echo "You don't have 'xgettext'."; exit 1
81 po/$(CATALOG_NAME).pot: $(GETTEXT_FILES) $(MAKEFILE_LIST)
82 # Change to srcdir explicitly, don't rely on $^. That way we get
83 # consistent #: file references in the po files.
85 $(XGETTEXT) -D $(srcdir) -n $(addprefix -k, $(GETTEXT_TRIGGERS)) $(addprefix --flag=, $(GETTEXT_FLAGS)) $(GETTEXT_FILES)
87 @echo "You don't have 'xgettext'."; exit 1
91 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 >$@
95 # catalog name extensions must match behavior of PG_TEXTDOMAIN() in c.h
96 install-po: all-po installdirs-po
98 for lang in $(LANGUAGES); do \
99 $(INSTALL_DATA) po/$$lang.mo '$(DESTDIR)$(localedir)'/$$lang/LC_MESSAGES/$(CATALOG_NAME)$(SO_MAJOR_VERSION)-$(MAJORVERSION).mo || exit 1; \
104 $(if $(LANGUAGES),$(MKDIR_P) $(foreach lang, $(LANGUAGES), '$(DESTDIR)$(localedir)'/$(lang)/LC_MESSAGES),:)
107 $(if $(LANGUAGES),rm -f $(foreach lang, $(LANGUAGES), '$(DESTDIR)$(localedir)'/$(lang)/LC_MESSAGES/$(CATALOG_NAME)$(SO_MAJOR_VERSION)-$(MAJORVERSION).mo),:)
111 $(if $(MO_FILES),rm -f $(MO_FILES))
112 @$(if $(wildcard po/*.po.new),rm -f po/*.po.new)
113 rm -f po/$(CATALOG_NAME).pot
116 maintainer-check-po: $(ALL_PO_FILES)
118 $(MSGFMT) -c -v -o /dev/null $$file || exit 1; \
122 init-po: po/$(CATALOG_NAME).pot
125 # For performance reasons, only calculate these when the user actually
126 # requested update-po or a specific file.
127 ifneq (,$(filter update-po %.po.new,$(MAKECMDGOALS)))
128 ALL_LANGUAGES := $(shell find $(top_srcdir) -name '*.po' -print | sed 's,^.*/\([^/]*\).po$$,\1,' | LC_ALL=C sort -u)
129 all_compendia := $(shell find $(top_srcdir) -name '*.po' -print | LC_ALL=C sort)
131 ALL_LANGUAGES = $(AVAIL_LANGUAGES)
132 all_compendia = FORCE
136 ifdef WANTED_LANGUAGES
137 ALL_LANGUAGES := $(filter $(WANTED_LANGUAGES), $(ALL_LANGUAGES))
140 update-po: $(ALL_LANGUAGES:%=po/%.po.new)
142 $(AVAIL_LANGUAGES:%=po/%.po.new): po/%.po.new: po/%.po po/$(CATALOG_NAME).pot $(all_compendia)
143 $(MSGMERGE) --lang=$* $(word 1, $^) $(word 2,$^) -o $@ $(addprefix --compendium=,$(filter %/$*.po,$(wordlist 3,$(words $^),$^)))
145 # For languages not yet available, merge against oneself, to pick
146 # up translations from the compendia. (Merging against /dev/null
147 # doesn't work so well; it inserts the headers from the first-named
149 po/%.po.new: po/$(CATALOG_NAME).pot $(all_compendia)
150 $(MSGMERGE) --lang=$* $(word 1,$^) $(word 1,$^) -o $@ $(addprefix --compendium=,$(filter %/$*.po,$(wordlist 2,$(words $^),$^)))
155 installdirs: installdirs-po
156 uninstall: uninstall-po
157 clean distclean maintainer-clean: clean-po
158 maintainer-check: maintainer-check-po
160 .PHONY: all-po install-po installdirs-po uninstall-po clean-po \
161 maintainer-check-po init-po update-po