OSDN Git Service

784e69a8ed079f7a22ee5fb8142550b0144d7170
[pg-rex/syncrep.git] / src / nls-global.mk
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 #
16 # That's all, the rest is done here, if --enable-nls was specified.
17 #
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.
22
23
24 # existence checked by Makefile.global; otherwise we won't get here
25 include $(srcdir)/nls.mk
26
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))
31 else
32 LANGUAGES = $(AVAIL_LANGUAGES)
33 endif
34
35 PO_FILES = $(addprefix po/, $(addsuffix .po, $(LANGUAGES)))
36 MO_FILES = $(addprefix po/, $(addsuffix .mo, $(LANGUAGES)))
37
38 ifdef XGETTEXT
39 XGETTEXT += -ctranslator --copyright-holder='PostgreSQL Global Development Group' --msgid-bugs-address=pgsql-bugs@postgresql.org
40 endif
41
42 # _ is defined in c.h, so it's global
43 GETTEXT_TRIGGERS += _
44
45
46 all-po: $(MO_FILES)
47
48 %.mo: %.po
49         $(MSGFMT) -o $@ $<
50
51 ifeq ($(word 1,$(GETTEXT_FILES)),+)
52 po/$(CATALOG_NAME).pot: $(word 2, $(GETTEXT_FILES)) $(MAKEFILE_LIST)
53 ifdef XGETTEXT
54         $(XGETTEXT) -D $(srcdir) -n $(addprefix -k, $(GETTEXT_TRIGGERS)) -f $<
55 else
56         @echo "You don't have 'xgettext'."; exit 1
57 endif
58 else # GETTEXT_FILES
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.
62 ifdef XGETTEXT
63         $(XGETTEXT) -D $(srcdir) -n $(addprefix -k, $(GETTEXT_TRIGGERS)) $(GETTEXT_FILES)
64 else
65         @echo "You don't have 'xgettext'."; exit 1
66 endif
67 endif # GETTEXT_FILES
68         @$(MKDIR_P) $(dir $@)
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 >$@
70         rm messages.po
71
72
73 # catalog name extentions must match behavior of PG_TEXTDOMAIN() in c.h
74 install-po: all-po installdirs-po
75 ifneq (,$(LANGUAGES))
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; \
78         done
79 endif
80
81 installdirs-po:
82         $(if $(LANGUAGES),$(MKDIR_P) $(foreach lang, $(LANGUAGES), '$(DESTDIR)$(localedir)'/$(lang)/LC_MESSAGES),:)
83
84 uninstall-po:
85         $(if $(LANGUAGES),rm -f $(foreach lang, $(LANGUAGES), '$(DESTDIR)$(localedir)'/$(lang)/LC_MESSAGES/$(CATALOG_NAME)$(SO_MAJOR_VERSION)-$(MAJORVERSION).mo),:)
86
87
88 clean-po:
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
92
93
94 maintainer-check-po: $(PO_FILES)
95         for file in $^; do \
96           $(MSGFMT) -c -v -o /dev/null $$file || exit 1; \
97         done
98
99
100 init-po: po/$(CATALOG_NAME).pot
101
102
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)
108 else
109 ALL_LANGUAGES = $(AVAIL_LANGUAGES)
110 all_compendia = FORCE
111 FORCE:
112 endif
113
114 ifdef WANTED_LANGUAGES
115 ALL_LANGUAGES := $(filter $(WANTED_LANGUAGES), $(ALL_LANGUAGES))
116 endif
117
118 update-po: $(ALL_LANGUAGES:%=po/%.po.new)
119
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 $^),$^)))
122
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
126 # compendium.)
127 po/%.po.new: po/$(CATALOG_NAME).pot $(all_compendia)
128         $(MSGMERGE) $(word 1,$^) $(word 1,$^) -o $@ $(addprefix --compendium=,$(filter %/$*.po,$(wordlist 2,$(words $^),$^)))
129
130
131 all: all-po
132 install: install-po
133 installdirs: installdirs-po
134 uninstall: uninstall-po
135 clean distclean maintainer-clean: clean-po
136 maintainer-check: maintainer-check-po
137
138 .PHONY: all-po install-po installdirs-po uninstall-po clean-po \
139         maintainer-check-po init-po update-po