• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Example for use of GNU gettext.
2# This file is in the public domain.
3#
4# Makefile configuration - processed by automake.
5
6# List of files which contain translatable strings.
7POTFILES = \
8  hello.cc
9
10# Usually the message domain is the same as the package name.
11DOMAIN = $(PACKAGE)
12
13# These options get passed to xgettext.
14XGETTEXT_OPTIONS = \
15  --keyword=wxGetTranslation:1 --keyword=wxGetTranslation:1,2 \
16  --flag=wxGetTranslation:1:pass-c-format --flag=wxGetTranslation:2:pass-c-format \
17  --keyword=wxTRANSLATE --flag=wxTRANSLATE:1:pass-c-format \
18  --keyword=wxPLURAL:1,2 --flag=wxPLURAL:1:pass-c-format --flag=wxPLURAL:2:pass-c-format \
19  --keyword=_ --flag=_:1:pass-c-format \
20  --keyword=N_ --flag=N_:1:pass-c-format
21
22# This is the copyright holder that gets inserted into the header of the
23# $(DOMAIN).pot file.  Set this to the copyright holder of the surrounding
24# package.  (Note that the msgstr strings, extracted from the package's
25# sources, belong to the copyright holder of the package.)  Translators are
26# expected to transfer the copyright for their translations to this person
27# or entity, or to disclaim their copyright.  The empty string stands for
28# the public domain; in this case the translators are expected to disclaim
29# their copyright.
30COPYRIGHT_HOLDER = Yoyodyne, Inc.
31
32# This tells whether or not to prepend "GNU " prefix to the package
33# name that gets inserted into the header of the $(DOMAIN).pot file.
34# Possible values are "yes", "no", or empty.  If it is empty, try to
35# detect it automatically by scanning the files in $(top_srcdir) for
36# "GNU packagename" string.
37PACKAGE_GNU = no
38
39# This is the email address or URL to which the translators shall report
40# bugs in the untranslated strings:
41# - Strings which are not entire sentences, see the maintainer guidelines
42#   in the GNU gettext documentation, section 'Preparing Strings'.
43# - Strings which use unclear terms or require additional context to be
44#   understood.
45# - Strings which make invalid assumptions about notation of date, time or
46#   money.
47# - Pluralisation problems.
48# - Incorrect English spelling.
49# - Incorrect formatting.
50# It can be your email address, or a mailing list address where translators
51# can write to without being subscribed, or the URL of a web page through
52# which the translators can contact you.
53MSGID_BUGS_ADDRESS = bug-gettext@gnu.org
54
55# This is the list of locale categories, beyond LC_MESSAGES, for which the
56# message catalogs shall be used.  It is usually empty.
57EXTRA_LOCALE_CATEGORIES =
58
59# These options get passed to msgmerge.
60# Useful options are in particular:
61#   --previous            to keep previous msgids of translated messages,
62#   --quiet               to reduce the verbosity.
63MSGMERGE_OPTIONS = --quiet
64
65# These options get passed to msginit.
66# If you want to disable line wrapping when writing PO files, add
67# --no-wrap to MSGMERGE_OPTIONS, XGETTEXT_OPTIONS, and
68# MSGINIT_OPTIONS.
69MSGINIT_OPTIONS =
70
71MSGMERGE = @MSGMERGE@
72MSGMERGE_UPDATE = @MSGMERGE@ --update
73MSGMERGE_FOR_MSGFMT_OPTION = @MSGMERGE_FOR_MSGFMT_OPTION@
74MSGINIT = msginit
75MSGCONV = msgconv
76MSGFILTER = msgfilter
77
78# This is computed as $(foreach file, $(POTFILES), $(top_srcdir)/$(file))
79POTFILES_DEPS = @POTFILES_DEPS@
80
81# This is computed as $(foreach lang, $(LINGUAS), $(srcdir)/$(lang).po)
82POFILES = @POFILES@
83# This is computed as $(foreach lang, $(LINGUAS), $(srcdir)/$(lang).gmo)
84GMOFILES = @GMOFILES@
85# This is computed as $(foreach lang, $(LINGUAS), $(lang).po-update)
86UPDATEPOFILES = @UPDATEPOFILES@
87# This is computed as $(foreach lang, $(LINGUAS), $(lang).nop)
88DUMMYPOFILES = @DUMMYPOFILES@
89
90# This is computed as
91# $(foreach lang, user-specified subset of $(LINGUAS), $(lang).gmo)
92CATALOGS = @CATALOGS@
93
94SUFFIXES = .po .gmo .sed .sin .nop .po-create .po-update
95
96# The .pot file, stamp-po, .po files, and .gmo files appear in release tarballs.
97# The GNU Coding Standards say in
98# <https://www.gnu.org/prep/standards/html_node/Makefile-Basics.html>:
99#   "GNU distributions usually contain some files which are not source files
100#    ... . Since these files normally appear in the source directory, they
101#    should always appear in the source directory, not in the build directory.
102#    So Makefile rules to update them should put the updated files in the
103#    source directory."
104# Therefore we put these files in the source directory, not the build directory.
105
106# During .po -> .gmo conversion, take into account the most recent changes to
107# the .pot file. This eliminates the need to update the .po files when the
108# .pot file has changed, which would be troublesome if the .po files are put
109# under version control.
110$(GMOFILES): $(srcdir)/$(DOMAIN).pot
111.po.gmo:
112	@lang=`echo $* | sed -e 's,.*/,,'`; \
113	test "$(srcdir)" = . && cdcmd="" || cdcmd="cd $(srcdir) && "; \
114	echo "$${cdcmd}rm -f $${lang}.gmo && $(MSGMERGE) $(MSGMERGE_FOR_MSGFMT_OPTION) -o $${lang}.1po $${lang}.po $(DOMAIN).pot && $(GMSGFMT) -c --statistics --verbose -o $${lang}.gmo $${lang}.1po && rm -f $${lang}.1po"; \
115	cd $(srcdir) && \
116	rm -f $${lang}.gmo && \
117	$(MSGMERGE) $(MSGMERGE_FOR_MSGFMT_OPTION) -o $${lang}.1po $${lang}.po $(DOMAIN).pot && \
118	$(GMSGFMT) -c --statistics --verbose -o t-$${lang}.gmo $${lang}.1po && \
119	mv t-$${lang}.gmo $${lang}.gmo && \
120	rm -f $${lang}.1po
121
122.sin.sed:
123	sed -e '/^#/d' $< > t-$@
124	mv t-$@ $@
125
126
127all-local: all-local-@USE_NLS@
128
129all-local-yes: $(srcdir)/stamp-po
130all-local-no:
131
132# $(srcdir)/$(DOMAIN).pot is only created when needed. When xgettext finds no
133# internationalized messages, no $(srcdir)/$(DOMAIN).pot is created (because
134# we don't want to bother translators with empty POT files). We assume that
135# LINGUAS is empty in this case, i.e. $(POFILES) and $(GMOFILES) are empty.
136# In this case, $(srcdir)/stamp-po is a nop (i.e. a phony target).
137
138# $(srcdir)/stamp-po is a timestamp denoting the last time at which the CATALOGS
139# have been loosely updated. Its purpose is that when a developer or translator
140# checks out the package from a version control system, and the $(DOMAIN).pot
141# file is not under version control, "make" will update the $(DOMAIN).pot and
142# the $(CATALOGS), but subsequent invocations of "make" will do nothing. This
143# timestamp would not be necessary if updating the $(CATALOGS) would always
144# touch them; however, the rule for $(POFILES) has been designed to not touch
145# files that don't need to be changed.
146$(srcdir)/stamp-po: $(srcdir)/$(DOMAIN).pot
147	test ! -f $(srcdir)/$(DOMAIN).pot || \
148	  test -z "$(GMOFILES)" || $(MAKE) $(GMOFILES)
149	@test ! -f $(srcdir)/$(DOMAIN).pot || { \
150	  echo "touch $(srcdir)/stamp-po" && \
151	  echo timestamp > $(srcdir)/stamp-poT && \
152	  mv $(srcdir)/stamp-poT $(srcdir)/stamp-po; \
153	}
154
155# Note: Target 'all' must not depend on target '$(DOMAIN).pot-update',
156# otherwise packages like GCC can not be built if only parts of the source
157# have been downloaded.
158
159# This target rebuilds $(DOMAIN).pot; it is an expensive operation.
160# Note that $(DOMAIN).pot is not touched if it doesn't need to be changed.
161# The determination of whether the package xyz is a GNU one is based on the
162# heuristic whether some file in the top level directory mentions "GNU xyz".
163# If GNU 'find' is available, we avoid grepping through monster files.
164$(DOMAIN).pot-update: $(POTFILES_DEPS) remove-potcdate.sed
165	package_gnu="$(PACKAGE_GNU)"; \
166	test -n "$$package_gnu" || { \
167	  if { if (LC_ALL=C find --version) 2>/dev/null | grep GNU >/dev/null; then \
168	         LC_ALL=C find -L $(top_srcdir) -maxdepth 1 -type f -size -10000000c -exec grep -i 'GNU $(PACKAGE)' /dev/null '{}' ';' 2>/dev/null; \
169	       else \
170	         LC_ALL=C grep -i 'GNU $(PACKAGE)' $(top_srcdir)/* 2>/dev/null; \
171	       fi; \
172	     } | grep -v 'libtool:' >/dev/null; then \
173	     package_gnu=yes; \
174	   else \
175	     package_gnu=no; \
176	   fi; \
177	}; \
178	if test "$$package_gnu" = "yes"; then \
179	  package_prefix='GNU '; \
180	else \
181	  package_prefix=''; \
182	fi; \
183	if test -n '$(MSGID_BUGS_ADDRESS)'; then \
184	  msgid_bugs_address='$(MSGID_BUGS_ADDRESS)'; \
185	else \
186	  msgid_bugs_address='$(PACKAGE_BUGREPORT)'; \
187	fi; \
188	case `$(XGETTEXT) --version | sed 1q | sed -e 's,^[^0-9]*,,'` in \
189	  '' | 0.[0-9] | 0.[0-9].* | 0.1[0-5] | 0.1[0-5].* | 0.16 | 0.16.[0-1]*) \
190	    $(XGETTEXT) --default-domain=$(DOMAIN) --directory=$(top_srcdir) \
191	      --add-comments=TRANSLATORS: \
192	      --copyright-holder='$(COPYRIGHT_HOLDER)' \
193	      --msgid-bugs-address="$$msgid_bugs_address" \
194	      $(XGETTEXT_OPTIONS) @XGETTEXT_EXTRA_OPTIONS@ \
195	      $(POTFILES) \
196	    ;; \
197	  *) \
198	    $(XGETTEXT) --default-domain=$(DOMAIN) --directory=$(top_srcdir) \
199	      --add-comments=TRANSLATORS: \
200	      --copyright-holder='$(COPYRIGHT_HOLDER)' \
201	      --package-name="$${package_prefix}$(PACKAGE)" \
202	      --package-version='$(VERSION)' \
203	      --msgid-bugs-address="$$msgid_bugs_address" \
204	      $(XGETTEXT_OPTIONS) @XGETTEXT_EXTRA_OPTIONS@ \
205	      $(POTFILES) \
206	    ;; \
207	esac
208	test ! -f $(DOMAIN).po || { \
209	  if test -f $(srcdir)/$(DOMAIN).pot-header; then \
210	    sed -e '1,/^#$$/d' < $(DOMAIN).po > $(DOMAIN).1po && \
211	    cat $(srcdir)/$(DOMAIN).pot-header $(DOMAIN).1po > $(DOMAIN).po && \
212	    rm -f $(DOMAIN).1po \
213	    || exit 1; \
214	  fi; \
215	  if test -f $(srcdir)/$(DOMAIN).pot; then \
216	    sed -f remove-potcdate.sed < $(srcdir)/$(DOMAIN).pot > $(DOMAIN).1po && \
217	    sed -f remove-potcdate.sed < $(DOMAIN).po > $(DOMAIN).2po && \
218	    if cmp $(DOMAIN).1po $(DOMAIN).2po >/dev/null 2>&1; then \
219	      rm -f $(DOMAIN).1po $(DOMAIN).2po $(DOMAIN).po; \
220	    else \
221	      rm -f $(DOMAIN).1po $(DOMAIN).2po $(srcdir)/$(DOMAIN).pot && \
222	      mv $(DOMAIN).po $(srcdir)/$(DOMAIN).pot; \
223	    fi; \
224	  else \
225	    mv $(DOMAIN).po $(srcdir)/$(DOMAIN).pot; \
226	  fi; \
227	}
228
229# This rule has no dependencies: we don't need to update $(DOMAIN).pot at
230# every "make" invocation, only create it when it is missing.
231# Only "make $(DOMAIN).pot-update" or "make dist" will force an update.
232$(srcdir)/$(DOMAIN).pot:
233	$(MAKE) $(DOMAIN).pot-update
234
235# This target rebuilds a PO file if $(DOMAIN).pot has changed.
236# Note that a PO file is not touched if it doesn't need to be changed.
237$(POFILES): $(srcdir)/$(DOMAIN).pot
238	@lang=`echo $@ | sed -e 's,.*/,,' -e 's/\.po$$//'`; \
239	if test -f "$(srcdir)/$${lang}.po"; then \
240	  test "$(srcdir)" = . && cdcmd="" || cdcmd="cd $(srcdir) && "; \
241	  echo "$${cdcmd}$(MSGMERGE_UPDATE) $(MSGMERGE_OPTIONS) --lang=$${lang} --previous $${lang}.po $(DOMAIN).pot"; \
242	  cd $(srcdir) \
243	    && { case `$(MSGMERGE_UPDATE) --version | sed 1q | sed -e 's,^[^0-9]*,,'` in \
244	           '' | 0.[0-9] | 0.[0-9].* | 0.1[0-5] | 0.1[0-5].*) \
245	             $(MSGMERGE_UPDATE) $(MSGMERGE_OPTIONS) $${lang}.po $(DOMAIN).pot;; \
246	           0.1[6-7] | 0.1[6-7].*) \
247	             $(MSGMERGE_UPDATE) $(MSGMERGE_OPTIONS) --previous $${lang}.po $(DOMAIN).pot;; \
248	           *) \
249	             $(MSGMERGE_UPDATE) $(MSGMERGE_OPTIONS) --lang=$${lang} --previous $${lang}.po $(DOMAIN).pot;; \
250	         esac; \
251	       }; \
252	else \
253	  $(MAKE) $${lang}.po-create; \
254	fi
255
256
257install-data-local: install-data-local-@USE_NLS@
258install-data-local-no: all-local
259install-data-local-yes: all-local
260	@catalogs='$(CATALOGS)'; \
261	for cat in $$catalogs; do \
262	  cat=`basename $$cat`; \
263	  lang=`echo $$cat | sed -e 's/\.gmo$$//'`; \
264	  dir=$(localedir)/$$lang/LC_MESSAGES; \
265	  $(MKDIR_P) $(DESTDIR)$$dir; \
266	  if test -r $$cat; then realcat=$$cat; else realcat=$(srcdir)/$$cat; fi; \
267	  $(INSTALL_DATA) $$realcat $(DESTDIR)$$dir/$(DOMAIN).mo; \
268	  echo "installing $$realcat as $(DESTDIR)$$dir/$(DOMAIN).mo"; \
269	  for lc in '' $(EXTRA_LOCALE_CATEGORIES); do \
270	    if test -n "$$lc"; then \
271	      if (cd $(DESTDIR)$(localedir)/$$lang && LC_ALL=C ls -l -d $$lc 2>/dev/null) | grep ' -> ' >/dev/null; then \
272	        link=`cd $(DESTDIR)$(localedir)/$$lang && LC_ALL=C ls -l -d $$lc | sed -e 's/^.* -> //'`; \
273	        mv $(DESTDIR)$(localedir)/$$lang/$$lc $(DESTDIR)$(localedir)/$$lang/$$lc.old; \
274	        mkdir $(DESTDIR)$(localedir)/$$lang/$$lc; \
275	        (cd $(DESTDIR)$(localedir)/$$lang/$$lc.old && \
276	         for file in *; do \
277	           if test -f $$file; then \
278	             ln -s ../$$link/$$file $(DESTDIR)$(localedir)/$$lang/$$lc/$$file; \
279	           fi; \
280	         done); \
281	        rm -f $(DESTDIR)$(localedir)/$$lang/$$lc.old; \
282	      else \
283	        if test -d $(DESTDIR)$(localedir)/$$lang/$$lc; then \
284	          :; \
285	        else \
286	          rm -f $(DESTDIR)$(localedir)/$$lang/$$lc; \
287	          mkdir $(DESTDIR)$(localedir)/$$lang/$$lc; \
288	        fi; \
289	      fi; \
290	      rm -f $(DESTDIR)$(localedir)/$$lang/$$lc/$(DOMAIN).mo; \
291	      ln -s ../LC_MESSAGES/$(DOMAIN).mo $(DESTDIR)$(localedir)/$$lang/$$lc/$(DOMAIN).mo 2>/dev/null || \
292	      ln $(DESTDIR)$(localedir)/$$lang/LC_MESSAGES/$(DOMAIN).mo $(DESTDIR)$(localedir)/$$lang/$$lc/$(DOMAIN).mo 2>/dev/null || \
293	      cp -p $(DESTDIR)$(localedir)/$$lang/LC_MESSAGES/$(DOMAIN).mo $(DESTDIR)$(localedir)/$$lang/$$lc/$(DOMAIN).mo; \
294	      echo "installing $$realcat link as $(DESTDIR)$(localedir)/$$lang/$$lc/$(DOMAIN).mo"; \
295	    fi; \
296	  done; \
297	done
298
299installdirs-local: installdirs-local-@USE_NLS@
300installdirs-local-no:
301installdirs-local-yes:
302	@catalogs='$(CATALOGS)'; \
303	for cat in $$catalogs; do \
304	  cat=`basename $$cat`; \
305	  lang=`echo $$cat | sed -e 's/\.gmo$$//'`; \
306	  dir=$(localedir)/$$lang/LC_MESSAGES; \
307	  $(MKDIR_P) $(DESTDIR)$$dir; \
308	  for lc in '' $(EXTRA_LOCALE_CATEGORIES); do \
309	    if test -n "$$lc"; then \
310	      if (cd $(DESTDIR)$(localedir)/$$lang && LC_ALL=C ls -l -d $$lc 2>/dev/null) | grep ' -> ' >/dev/null; then \
311	        link=`cd $(DESTDIR)$(localedir)/$$lang && LC_ALL=C ls -l -d $$lc | sed -e 's/^.* -> //'`; \
312	        mv $(DESTDIR)$(localedir)/$$lang/$$lc $(DESTDIR)$(localedir)/$$lang/$$lc.old; \
313	        mkdir $(DESTDIR)$(localedir)/$$lang/$$lc; \
314	        (cd $(DESTDIR)$(localedir)/$$lang/$$lc.old && \
315	         for file in *; do \
316	           if test -f $$file; then \
317	             ln -s ../$$link/$$file $(DESTDIR)$(localedir)/$$lang/$$lc/$$file; \
318	           fi; \
319	         done); \
320	        rm -f $(DESTDIR)$(localedir)/$$lang/$$lc.old; \
321	      else \
322	        if test -d $(DESTDIR)$(localedir)/$$lang/$$lc; then \
323	          :; \
324	        else \
325	          rm -f $(DESTDIR)$(localedir)/$$lang/$$lc; \
326	          mkdir $(DESTDIR)$(localedir)/$$lang/$$lc; \
327	        fi; \
328	      fi; \
329	    fi; \
330	  done; \
331	done
332
333uninstall-local: uninstall-local-@USE_NLS@
334uninstall-local-no:
335uninstall-local-yes:
336	catalogs='$(CATALOGS)'; \
337	for cat in $$catalogs; do \
338	  cat=`basename $$cat`; \
339	  lang=`echo $$cat | sed -e 's/\.gmo$$//'`; \
340	  for lc in LC_MESSAGES $(EXTRA_LOCALE_CATEGORIES); do \
341	    rm -f $(DESTDIR)$(localedir)/$$lang/$$lc/$(DOMAIN).mo; \
342	  done; \
343	done
344
345html ID:
346
347MOSTLYCLEANFILES =
348MOSTLYCLEANFILES += remove-potcdate.sed
349MOSTLYCLEANFILES += stamp-poT
350MOSTLYCLEANFILES += core core.* *.stackdump $(DOMAIN).po $(DOMAIN).1po $(DOMAIN).2po *.new.po
351MOSTLYCLEANFILES += *.o
352
353MAINTAINERCLEANFILES = $(DOMAIN).pot stamp-po $(GMOFILES)
354
355EXTRA_DIST = remove-potcdate.sin LINGUAS $(POFILES) $(GMOFILES)
356
357# Hidden from automake, but really activated. Works around an automake-1.5 bug.
358#distdir: distdir1
359distdir1:
360	$(MAKE) update-po
361	$(MAKE) $(srcdir)/stamp-po
362	@if test -f $(srcdir)/$(DOMAIN).pot; then \
363	  for file in $(DOMAIN).pot stamp-po; do \
364	    if test -f $$file; then d=.; else d=$(srcdir); fi; \
365	    cp -p $$d/$$file $(distdir)/$$file || exit 1; \
366	  done; \
367	else \
368	  case $(XGETTEXT) in \
369	    :) echo "Warning: Creating a tarball without '$(DOMAIN).pot', because a suitable 'xgettext' program was not found in PATH." 1>&2;; \
370	    *) echo "Warning: Creating a tarball without '$(DOMAIN).pot', because 'xgettext' found no strings to extract. Check the POTFILES and the XGETTEXT_OPTIONS in the Makefile.am file." 1>&2;; \
371	  esac; \
372	fi
373
374update-po: Makefile
375	$(MAKE) $(DOMAIN).pot-update
376	test -z "$(UPDATEPOFILES)" || $(MAKE) $(UPDATEPOFILES)
377	$(MAKE) update-gmo
378
379# General rule for creating PO files.
380
381.nop.po-create:
382	@lang=`echo $@ | sed -e 's/\.po-create$$//'`; \
383	echo "File $$lang.po does not exist. If you are a translator, you can create it through 'msginit'." 1>&2; \
384	exit 1
385
386# General rule for updating PO files.
387
388.nop.po-update:
389	@lang=`echo $@ | sed -e 's/\.po-update$$//'`; \
390	tmpdir=`pwd`; \
391	echo "$$lang:"; \
392	test "$(srcdir)" = . && cdcmd="" || cdcmd="cd $(srcdir) && "; \
393	echo "$${cdcmd}$(MSGMERGE) $(MSGMERGE_OPTIONS) --lang=$$lang --previous $$lang.po $(DOMAIN).pot -o $$lang.new.po"; \
394	cd $(srcdir); \
395	if { case `$(MSGMERGE) --version | sed 1q | sed -e 's,^[^0-9]*,,'` in \
396	       '' | 0.[0-9] | 0.[0-9].* | 0.1[0-5] | 0.1[0-5].*) \
397	         $(MSGMERGE) $(MSGMERGE_OPTIONS) -o $$tmpdir/$$lang.new.po $$lang.po $(DOMAIN).pot;; \
398	       0.1[6-7] | 0.1[6-7].*) \
399	         $(MSGMERGE) $(MSGMERGE_OPTIONS) --previous -o $$tmpdir/$$lang.new.po $$lang.po $(DOMAIN).pot;; \
400	       *) \
401	         $(MSGMERGE) $(MSGMERGE_OPTIONS) --lang=$$lang --previous -o $$tmpdir/$$lang.new.po $$lang.po $(DOMAIN).pot;; \
402	     esac; \
403	   }; then \
404	  if cmp $$lang.po $$tmpdir/$$lang.new.po >/dev/null 2>&1; then \
405	    rm -f $$tmpdir/$$lang.new.po; \
406	  else \
407	    if mv -f $$tmpdir/$$lang.new.po $$lang.po; then \
408	      :; \
409	    else \
410	      echo "msgmerge for $$lang.po failed: cannot move $$tmpdir/$$lang.new.po to $$lang.po" 1>&2; \
411	      exit 1; \
412	    fi; \
413	  fi; \
414	else \
415	  echo "msgmerge for $$lang.po failed!" 1>&2; \
416	  rm -f $$tmpdir/$$lang.new.po; \
417	fi
418
419$(DUMMYPOFILES):
420
421update-gmo: Makefile $(GMOFILES)
422	@:
423