You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

nls-global.mk 6.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. # src/nls-global.mk
  2. # Common rules for Native Language Support (NLS)
  3. #
  4. # If some subdirectory of the source tree wants to provide NLS, it
  5. # needs to contain a file 'nls.mk' with the following make variable
  6. # assignments:
  7. #
  8. # CATALOG_NAME -- name of the message catalog (xxx.po); probably
  9. # name of the program
  10. # AVAIL_LANGUAGES -- list of languages that are provided/supported
  11. # GETTEXT_FILES -- list of source files that contain message strings
  12. # GETTEXT_TRIGGERS -- (optional) list of functions that contain
  13. # translatable strings
  14. # GETTEXT_FLAGS -- (optional) list of gettext --flag arguments to mark
  15. # function arguments that contain C format strings
  16. # (functions must be listed in TRIGGERS and FLAGS)
  17. #
  18. # That's all, the rest is done here, if --enable-nls was specified.
  19. #
  20. # The only user-visible targets here are 'init-po', to make an initial
  21. # "blank" catalog from program sources, and 'update-po', which is to
  22. # be called if the messages in the program source have changed, in
  23. # 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
  26. # If user specified the languages he wants in --enable-nls=LANGUAGES,
  27. # filter out the rest. Else use all available ones.
  28. ifdef WANTED_LANGUAGES
  29. LANGUAGES = $(filter $(WANTED_LANGUAGES), $(AVAIL_LANGUAGES))
  30. else
  31. LANGUAGES = $(AVAIL_LANGUAGES)
  32. endif
  33. PO_FILES = $(addprefix po/, $(addsuffix .po, $(LANGUAGES)))
  34. ALL_PO_FILES = $(addprefix po/, $(addsuffix .po, $(AVAIL_LANGUAGES)))
  35. MO_FILES = $(addprefix po/, $(addsuffix .mo, $(LANGUAGES)))
  36. ifdef XGETTEXT
  37. XGETTEXT += -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)'
  38. endif
  39. ifdef MSGMERGE
  40. MSGMERGE += --no-wrap --previous --sort-by-file
  41. endif
  42. # _ is defined in c.h, so it's global
  43. GETTEXT_TRIGGERS += _
  44. GETTEXT_FLAGS += _:1:pass-c-format
  45. # common settings that apply to backend and all backend modules
  46. BACKEND_COMMON_GETTEXT_TRIGGERS = \
  47. $(FRONTEND_COMMON_GETTEXT_TRIGGERS) \
  48. errmsg errmsg_plural:1,2 \
  49. errdetail errdetail_log errdetail_plural:1,2 \
  50. errhint \
  51. errcontext \
  52. XactLockTableWait:4 \
  53. MultiXactIdWait:6 \
  54. ConditionalMultiXactIdWait:6
  55. BACKEND_COMMON_GETTEXT_FLAGS = \
  56. $(FRONTEND_COMMON_GETTEXT_FLAGS) \
  57. errmsg:1:c-format errmsg_plural:1:c-format errmsg_plural:2:c-format \
  58. errdetail:1:c-format errdetail_log:1:c-format errdetail_plural:1:c-format errdetail_plural:2:c-format \
  59. errhint:1:c-format \
  60. errcontext:1:c-format
  61. FRONTEND_COMMON_GETTEXT_FILES = $(top_srcdir)/src/common/logging.c
  62. FRONTEND_COMMON_GETTEXT_TRIGGERS = \
  63. pg_log_fatal pg_log_error pg_log_warning pg_log_info pg_log_generic:2 pg_log_generic_v:2
  64. FRONTEND_COMMON_GETTEXT_FLAGS = \
  65. 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
  66. all-po: $(MO_FILES)
  67. %.mo: %.po
  68. $(MSGFMT) $(MSGFMT_FLAGS) -o $@ $<
  69. ifeq ($(word 1,$(GETTEXT_FILES)),+)
  70. po/$(CATALOG_NAME).pot: $(word 2, $(GETTEXT_FILES)) $(MAKEFILE_LIST)
  71. ifdef XGETTEXT
  72. $(XGETTEXT) -D $(srcdir) -D . -n $(addprefix -k, $(GETTEXT_TRIGGERS)) $(addprefix --flag=, $(GETTEXT_FLAGS)) -f $<
  73. else
  74. @echo "You don't have 'xgettext'."; exit 1
  75. endif
  76. else # GETTEXT_FILES
  77. po/$(CATALOG_NAME).pot: $(GETTEXT_FILES) $(MAKEFILE_LIST)
  78. # Change to srcdir explicitly, don't rely on $^. That way we get
  79. # consistent #: file references in the po files.
  80. ifdef XGETTEXT
  81. $(XGETTEXT) -D $(srcdir) -D . -n $(addprefix -k, $(GETTEXT_TRIGGERS)) $(addprefix --flag=, $(GETTEXT_FLAGS)) $(GETTEXT_FILES)
  82. else
  83. @echo "You don't have 'xgettext'."; exit 1
  84. endif
  85. endif # GETTEXT_FILES
  86. @$(MKDIR_P) $(dir $@)
  87. 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 >$@
  88. rm messages.po
  89. # catalog name extensions must match behavior of PG_TEXTDOMAIN() in c.h
  90. install-po: all-po installdirs-po
  91. ifneq (,$(LANGUAGES))
  92. for lang in $(LANGUAGES); do \
  93. $(INSTALL_DATA) po/$$lang.mo '$(DESTDIR)$(localedir)'/$$lang/LC_MESSAGES/$(CATALOG_NAME)$(SO_MAJOR_VERSION)-$(MAJORVERSION).mo || exit 1; \
  94. done
  95. endif
  96. installdirs-po:
  97. $(if $(LANGUAGES),$(MKDIR_P) $(foreach lang, $(LANGUAGES), '$(DESTDIR)$(localedir)'/$(lang)/LC_MESSAGES),:)
  98. uninstall-po:
  99. $(if $(LANGUAGES),rm -f $(foreach lang, $(LANGUAGES), '$(DESTDIR)$(localedir)'/$(lang)/LC_MESSAGES/$(CATALOG_NAME)$(SO_MAJOR_VERSION)-$(MAJORVERSION).mo),:)
  100. clean-po:
  101. $(if $(MO_FILES),rm -f $(MO_FILES))
  102. @$(if $(wildcard po/*.po.new),rm -f po/*.po.new)
  103. rm -f po/$(CATALOG_NAME).pot
  104. init-po: po/$(CATALOG_NAME).pot
  105. # For performance reasons, only calculate these when the user actually
  106. # requested update-po or a specific file.
  107. ifneq (,$(filter update-po %.po.new,$(MAKECMDGOALS)))
  108. ALL_LANGUAGES := $(shell find $(top_srcdir) -name '*.po' -print | sed 's,^.*/\([^/]*\).po$$,\1,' | LC_ALL=C sort -u)
  109. all_compendia := $(shell find $(top_srcdir) -name '*.po' -print | LC_ALL=C sort)
  110. else
  111. ALL_LANGUAGES = $(AVAIL_LANGUAGES)
  112. all_compendia = FORCE
  113. FORCE:
  114. endif
  115. ifdef WANTED_LANGUAGES
  116. ALL_LANGUAGES := $(filter $(WANTED_LANGUAGES), $(ALL_LANGUAGES))
  117. endif
  118. update-po: $(ALL_LANGUAGES:%=po/%.po.new)
  119. $(AVAIL_LANGUAGES:%=po/%.po.new): po/%.po.new: po/%.po po/$(CATALOG_NAME).pot $(all_compendia)
  120. $(MSGMERGE) --lang=$* $(word 1, $^) $(word 2,$^) -o $@ $(addprefix --compendium=,$(filter %/$*.po,$(wordlist 3,$(words $^),$^)))
  121. # For languages not yet available, merge against oneself, to pick
  122. # up translations from the compendia. (Merging against /dev/null
  123. # doesn't work so well; it inserts the headers from the first-named
  124. # compendium.)
  125. po/%.po.new: po/$(CATALOG_NAME).pot $(all_compendia)
  126. $(MSGMERGE) --lang=$* $(word 1,$^) $(word 1,$^) -o $@ $(addprefix --compendium=,$(filter %/$*.po,$(wordlist 2,$(words $^),$^)))
  127. all: all-po
  128. install: install-po
  129. installdirs: installdirs-po
  130. uninstall: uninstall-po
  131. clean distclean maintainer-clean: clean-po
  132. .PHONY: all-po install-po installdirs-po uninstall-po clean-po \
  133. init-po update-po