1# src/nls-global.mk 2 3# Common rules for Native Language Support (NLS) 4# 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 7# assignments: 8# 9# CATALOG_NAME -- name of the message catalog (xxx.po); probably 10# name of the program 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) 18# 19# That's all, the rest is done here, if --enable-nls was specified. 20# 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. 25 26 27# existence checked by Makefile.global; otherwise we won't get here 28include $(srcdir)/nls.mk 29 30# If user specified the languages he wants in --enable-nls=LANGUAGES, 31# filter out the rest. Else use all available ones. 32ifdef WANTED_LANGUAGES 33LANGUAGES = $(filter $(WANTED_LANGUAGES), $(AVAIL_LANGUAGES)) 34else 35LANGUAGES = $(AVAIL_LANGUAGES) 36endif 37 38PO_FILES = $(addprefix po/, $(addsuffix .po, $(LANGUAGES))) 39ALL_PO_FILES = $(addprefix po/, $(addsuffix .po, $(AVAIL_LANGUAGES))) 40MO_FILES = $(addprefix po/, $(addsuffix .mo, $(LANGUAGES))) 41 42ifdef XGETTEXT 43XGETTEXT += -ctranslator --copyright-holder='PostgreSQL Global Development Group' --msgid-bugs-address=pgsql-bugs@lists.postgresql.org --no-wrap --sort-by-file --package-name='$(CATALOG_NAME) (PostgreSQL)' --package-version='$(MAJORVERSION)' 44endif 45 46ifdef MSGMERGE 47MSGMERGE += --no-wrap --previous --sort-by-file 48endif 49 50# _ is defined in c.h, so it's global 51GETTEXT_TRIGGERS += _ 52GETTEXT_FLAGS += _:1:pass-c-format 53 54 55# common settings that apply to backend and all backend modules 56BACKEND_COMMON_GETTEXT_TRIGGERS = \ 57 $(FRONTEND_COMMON_GETTEXT_TRIGGERS) \ 58 errmsg errmsg_plural:1,2 \ 59 errdetail errdetail_log errdetail_plural:1,2 \ 60 errhint \ 61 errcontext \ 62 XactLockTableWait:4 \ 63 MultiXactIdWait:6 \ 64 ConditionalMultiXactIdWait:6 65BACKEND_COMMON_GETTEXT_FLAGS = \ 66 $(FRONTEND_COMMON_GETTEXT_FLAGS) \ 67 errmsg:1:c-format errmsg_plural:1:c-format errmsg_plural:2:c-format \ 68 errdetail:1:c-format errdetail_log:1:c-format errdetail_plural:1:c-format errdetail_plural:2:c-format \ 69 errhint:1:c-format \ 70 errcontext:1:c-format 71 72FRONTEND_COMMON_GETTEXT_FILES = $(top_srcdir)/src/common/logging.c 73 74FRONTEND_COMMON_GETTEXT_TRIGGERS = \ 75 pg_log_fatal pg_log_error pg_log_warning pg_log_info pg_log_generic:2 pg_log_generic_v:2 76 77FRONTEND_COMMON_GETTEXT_FLAGS = \ 78 pg_log_fatal:1:c-format pg_log_error:1:c-format pg_log_warning:1:c-format pg_log_info:1:c-format pg_log_generic:2:c-format pg_log_generic_v:2:c-format 79 80 81all-po: $(MO_FILES) 82 83%.mo: %.po 84 $(MSGFMT) $(MSGFMT_FLAGS) -o $@ $< 85 86ifeq ($(word 1,$(GETTEXT_FILES)),+) 87po/$(CATALOG_NAME).pot: $(word 2, $(GETTEXT_FILES)) $(MAKEFILE_LIST) 88ifdef XGETTEXT 89 $(XGETTEXT) -D $(srcdir) -D . -n $(addprefix -k, $(GETTEXT_TRIGGERS)) $(addprefix --flag=, $(GETTEXT_FLAGS)) -f $< 90else 91 @echo "You don't have 'xgettext'."; exit 1 92endif 93else # GETTEXT_FILES 94po/$(CATALOG_NAME).pot: $(GETTEXT_FILES) $(MAKEFILE_LIST) 95# Change to srcdir explicitly, don't rely on $^. That way we get 96# consistent #: file references in the po files. 97ifdef XGETTEXT 98 $(XGETTEXT) -D $(srcdir) -D . -n $(addprefix -k, $(GETTEXT_TRIGGERS)) $(addprefix --flag=, $(GETTEXT_FLAGS)) $(GETTEXT_FILES) 99else 100 @echo "You don't have 'xgettext'."; exit 1 101endif 102endif # GETTEXT_FILES 103 @$(MKDIR_P) $(dir $@) 104 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 >$@ 105 rm messages.po 106 107 108# catalog name extensions must match behavior of PG_TEXTDOMAIN() in c.h 109install-po: all-po installdirs-po 110ifneq (,$(LANGUAGES)) 111 for lang in $(LANGUAGES); do \ 112 $(INSTALL_DATA) po/$$lang.mo '$(DESTDIR)$(localedir)'/$$lang/LC_MESSAGES/$(CATALOG_NAME)$(SO_MAJOR_VERSION)-$(MAJORVERSION).mo || exit 1; \ 113 done 114endif 115 116installdirs-po: 117 $(if $(LANGUAGES),$(MKDIR_P) $(foreach lang, $(LANGUAGES), '$(DESTDIR)$(localedir)'/$(lang)/LC_MESSAGES),:) 118 119uninstall-po: 120 $(if $(LANGUAGES),rm -f $(foreach lang, $(LANGUAGES), '$(DESTDIR)$(localedir)'/$(lang)/LC_MESSAGES/$(CATALOG_NAME)$(SO_MAJOR_VERSION)-$(MAJORVERSION).mo),:) 121 122 123clean-po: 124 $(if $(MO_FILES),rm -f $(MO_FILES)) 125 @$(if $(wildcard po/*.po.new),rm -f po/*.po.new) 126 rm -f po/$(CATALOG_NAME).pot 127 128 129init-po: po/$(CATALOG_NAME).pot 130 131 132# For performance reasons, only calculate these when the user actually 133# requested update-po or a specific file. 134ifneq (,$(filter update-po %.po.new,$(MAKECMDGOALS))) 135ALL_LANGUAGES := $(shell find $(top_srcdir) -name '*.po' -print | sed 's,^.*/\([^/]*\).po$$,\1,' | LC_ALL=C sort -u) 136all_compendia := $(shell find $(top_srcdir) -name '*.po' -print | LC_ALL=C sort) 137else 138ALL_LANGUAGES = $(AVAIL_LANGUAGES) 139all_compendia = FORCE 140FORCE: 141endif 142 143ifdef WANTED_LANGUAGES 144ALL_LANGUAGES := $(filter $(WANTED_LANGUAGES), $(ALL_LANGUAGES)) 145endif 146 147update-po: $(ALL_LANGUAGES:%=po/%.po.new) 148 149$(AVAIL_LANGUAGES:%=po/%.po.new): po/%.po.new: po/%.po po/$(CATALOG_NAME).pot $(all_compendia) 150 $(MSGMERGE) --lang=$* $(word 1, $^) $(word 2,$^) -o $@ $(addprefix --compendium=,$(filter %/$*.po,$(wordlist 3,$(words $^),$^))) 151 152# For languages not yet available, merge against oneself, to pick 153# up translations from the compendia. (Merging against /dev/null 154# doesn't work so well; it inserts the headers from the first-named 155# compendium.) 156po/%.po.new: po/$(CATALOG_NAME).pot $(all_compendia) 157 $(MSGMERGE) --lang=$* $(word 1,$^) $(word 1,$^) -o $@ $(addprefix --compendium=,$(filter %/$*.po,$(wordlist 2,$(words $^),$^))) 158 159 160all: all-po 161install: install-po 162installdirs: installdirs-po 163uninstall: uninstall-po 164clean distclean maintainer-clean: clean-po 165 166.PHONY: all-po install-po installdirs-po uninstall-po clean-po \ 167 init-po update-po 168