• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Example for use of GNU gettext.
2# This file is in the public domain.
3#
4# Makefile - processed by GNU make.
5
6# NLS is enabled by default.
7USE_NLS = yes
8
9# List of files which contain translatable strings.
10POTFILES = \
11  Hello.m
12
13# Usually the message domain is the same as the package name in lower case.
14DOMAIN = hello-objc-gnustep
15
16# These options get passed to xgettext.
17XGETTEXT_OPTIONS =
18
19# This is the copyright holder that gets inserted into the header of the
20# $(DOMAIN).pot file.  Set this to the copyright holder of the surrounding
21# package.  (Note that the msgstr strings, extracted from the package's
22# sources, belong to the copyright holder of the package.)  Translators are
23# expected to transfer the copyright for their translations to this person
24# or entity, or to disclaim their copyright.  The empty string stands for
25# the public domain; in this case the translators are expected to disclaim
26# their copyright.
27COPYRIGHT_HOLDER = Yoyodyne, Inc.
28
29# This tells whether or not to prepend "GNU " prefix to the package
30# name that gets inserted into the header of the $(DOMAIN).pot file.
31# Possible values are "yes", "no", or empty.  If it is empty, try to
32# detect it automatically by scanning the files in $(top_srcdir) for
33# "GNU packagename" string.
34PACKAGE_GNU = no
35
36# This is the email address or URL to which the translators shall report
37# bugs in the untranslated strings:
38# - Strings which are not entire sentences, see the maintainer guidelines
39#   in the GNU gettext documentation, section 'Preparing Strings'.
40# - Strings which use unclear terms or require additional context to be
41#   understood.
42# - Strings which make invalid assumptions about notation of date, time or
43#   money.
44# - Pluralisation problems.
45# - Incorrect English spelling.
46# - Incorrect formatting.
47# It can be your email address, or a mailing list address where translators
48# can write to without being subscribed, or the URL of a web page through
49# which the translators can contact you.
50MSGID_BUGS_ADDRESS = bug-gettext@gnu.org
51
52# These options get passed to msgmerge.
53# Useful options are in particular:
54#   --previous            to keep previous msgids of translated messages,
55#   --quiet               to reduce the verbosity.
56MSGMERGE_OPTIONS = --quiet
57
58# These options get passed to msginit.
59# If you want to disable line wrapping when writing PO files, add
60# --no-wrap to MSGMERGE_OPTIONS, XGETTEXT_OPTIONS, and
61# MSGINIT_OPTIONS.
62MSGINIT_OPTIONS =
63
64-include $(GNUSTEP_MAKEFILES)/rules.make
65
66# Main application
67PACKAGE_NAME = Hello
68PACKAGE_VERSION = 0
69
70XGETTEXT = xgettext
71MSGMERGE = msgmerge
72MSGMERGE_UPDATE = msgmerge --update
73MSGMERGE_FOR_MSGFMT_OPTION = --for-msgfmt
74MSGINIT = msginit
75MSGCONV = msgconv
76MSGFILTER = msgfilter
77
78# Set of available languages.
79LINGUAS := $(shell sed -e "/^\#/d" LINGUAS)
80# Set of languages which use msgen.
81ENLINGUAS := $(filter-out $(LINGUAS), en)
82
83top_srcdir = ..
84
85include LocaleAliases
86
87POTFILES_DEPS = $(foreach file, $(POTFILES), $(top_srcdir)/$(file))
88POFILES = $(foreach lang, $(LINGUAS), $(lang).po)
89UPDATEPOFILES = $(foreach lang, $(LINGUAS), $(lang).po-update)
90DUMMYPOFILES = $(foreach lang, $(LINGUAS), $(lang).nop)
91STRINGSFILES = $(foreach lang, $(LINGUAS), $(top_srcdir)/$(NSLOCALE_$(lang)).lproj/Localizable.strings)
92ENSTRINGSFILES = $(foreach lang, $(ENLINGUAS), $(top_srcdir)/$(NSLOCALE_$(lang)).lproj/Localizable.strings)
93CATALOGS = $(STRINGSFILES) $(ENSTRINGSFILES)
94
95.SUFFIXES: .po .sed .sin .nop .po-create .po-update
96
97.sin.sed:
98	sed -e '/^#/d' $< > t-$@
99	mv t-$@ $@
100
101
102internal-all:: all-local-$(USE_NLS)
103
104all-local-yes: $(CATALOGS)
105all-local-no:
106
107# Note: Target 'all' must not depend on target '$(DOMAIN).pot-update',
108# otherwise packages like GCC can not be built if only parts of the source
109# have been downloaded.
110
111# This target rebuilds $(DOMAIN).pot; it is an expensive operation.
112# Note that $(DOMAIN).pot is not touched if it doesn't need to be changed.
113# The determination of whether the package xyz is a GNU one is based on the
114# heuristic whether some file in the top level directory mentions "GNU xyz".
115# If GNU 'find' is available, we avoid grepping through monster files.
116$(DOMAIN).pot-update: $(POTFILES_DEPS) remove-potcdate.sed
117	package_gnu="$(PACKAGE_GNU)"; \
118	test -n "$$package_gnu" || { \
119	  if { if (LC_ALL=C find --version) 2>/dev/null | grep GNU >/dev/null; then \
120	         LC_ALL=C find -L $(top_srcdir) -maxdepth 1 -type f -size -10000000c -exec grep -i 'GNU $(PACKAGE_NAME)' /dev/null '{}' ';' 2>/dev/null; \
121	       else \
122	         LC_ALL=C grep -i 'GNU $(PACKAGE_NAME)' $(top_srcdir)/* 2>/dev/null; \
123	       fi; \
124	     } | grep -v 'libtool:' >/dev/null; then \
125	     package_gnu=yes; \
126	   else \
127	     package_gnu=no; \
128	   fi; \
129	}; \
130	if test "$$package_gnu" = "yes"; then \
131	  package_prefix='GNU '; \
132	else \
133	  package_prefix=''; \
134	fi; \
135	msgid_bugs_address='$(MSGID_BUGS_ADDRESS)'; \
136	case `$(XGETTEXT) --version | sed 1q | sed -e 's,^[^0-9]*,,'` in \
137	  '' | 0.[0-9] | 0.[0-9].* | 0.1[0-5] | 0.1[0-5].* | 0.16 | 0.16.[0-1]*) \
138	    $(XGETTEXT) --default-domain=$(DOMAIN) --directory=$(top_srcdir) \
139	      --add-comments=TRANSLATORS: \
140	      --copyright-holder='$(COPYRIGHT_HOLDER)' \
141	      --msgid-bugs-address="$$msgid_bugs_address" \
142	      $(XGETTEXT_OPTIONS) \
143	      $(POTFILES) \
144	    ;; \
145	  *) \
146	    $(XGETTEXT) --default-domain=$(DOMAIN) --directory=$(top_srcdir) \
147	      --add-comments=TRANSLATORS: \
148	      --copyright-holder='$(COPYRIGHT_HOLDER)' \
149	      --package-name="$${package_prefix}$(PACKAGE_NAME)" \
150	      --package-version='$(VERSION)' \
151	      --msgid-bugs-address="$$msgid_bugs_address" \
152	      $(XGETTEXT_OPTIONS) \
153	      $(POTFILES) \
154	    ;; \
155	esac
156	test ! -f $(DOMAIN).po || { \
157	  if test -f $(DOMAIN).pot-header; then \
158	    sed -e '1,/^#$$/d' < $(DOMAIN).po > $(DOMAIN).1po && \
159	    cat $(DOMAIN).pot-header $(DOMAIN).1po > $(DOMAIN).po && \
160	    rm -f $(DOMAIN).1po \
161	    || exit 1; \
162	  fi; \
163	  if test -f $(DOMAIN).pot; then \
164	    sed -f remove-potcdate.sed < $(DOMAIN).pot > $(DOMAIN).1po && \
165	    sed -f remove-potcdate.sed < $(DOMAIN).po > $(DOMAIN).2po && \
166	    if cmp $(DOMAIN).1po $(DOMAIN).2po >/dev/null 2>&1; then \
167	      rm -f $(DOMAIN).1po $(DOMAIN).2po $(DOMAIN).po; \
168	    else \
169	      rm -f $(DOMAIN).1po $(DOMAIN).2po $(DOMAIN).pot && \
170	      mv $(DOMAIN).po $(DOMAIN).pot; \
171	    fi; \
172	  else \
173	    mv $(DOMAIN).po $(DOMAIN).pot; \
174	  fi; \
175	}
176
177# This rule has no dependencies: we don't need to update $(DOMAIN).pot at
178# every "make" invocation, only create it when it is missing.
179# Only "make $(DOMAIN).pot-update" or "make dist" will force an update.
180$(DOMAIN).pot:
181	$(MAKE) $(DOMAIN).pot-update
182
183# This target rebuilds a PO file if $(DOMAIN).pot has changed.
184# Note that a PO file is not touched if it doesn't need to be changed.
185$(POFILES): $(DOMAIN).pot
186	@lang=`echo $@ | sed -e 's,.*/,,' -e 's/\.po$$//'`; \
187	if test -f $${lang}.po; then \
188	  echo "$(MSGMERGE_UPDATE) $(MSGMERGE_OPTIONS) --lang=$${lang} --previous $${lang}.po $(DOMAIN).pot"; \
189	  case `$(MSGMERGE_UPDATE) --version | sed 1q | sed -e 's,^[^0-9]*,,'` in \
190	    '' | 0.[0-9] | 0.[0-9].* | 0.1[0-5] | 0.1[0-5].*) \
191	      $(MSGMERGE_UPDATE) $(MSGMERGE_OPTIONS) $${lang}.po $(DOMAIN).pot;; \
192	    0.1[6-7] | 0.1[6-7].*) \
193	      $(MSGMERGE_UPDATE) $(MSGMERGE_OPTIONS) --previous $${lang}.po $(DOMAIN).pot;; \
194	    *) \
195	      $(MSGMERGE_UPDATE) $(MSGMERGE_OPTIONS) --lang=$${lang} --previous $${lang}.po $(DOMAIN).pot;; \
196	  esac; \
197	else \
198	  $(MAKE) $${lang}.po-create; \
199	fi
200
201internal-clean::
202	rm -f remove-potcdate.sed
203
204update-po:
205	$(MAKE) $(DOMAIN).pot-update
206	test -z "$(UPDATEPOFILES)" || $(MAKE) $(UPDATEPOFILES)
207	$(MAKE) update-strings
208
209# General rule for creating PO files.
210
211.nop.po-create:
212	@lang=`echo $@ | sed -e 's/\.po-create$$//'`; \
213	echo "File $$lang.po does not exist. If you are a translator, you can create it through 'msginit'." 1>&2; \
214	exit 1
215
216# General rule for updating PO files.
217
218.nop.po-update:
219	@lang=`echo $@ | sed -e 's/\.po-update$$//'`; \
220	tmpdir=`pwd`; \
221	echo "$$lang:"; \
222	echo "$(MSGMERGE) $(MSGMERGE_OPTIONS) --lang=$$lang $$lang.po $(DOMAIN).pot -o $$lang.new.po"; \
223	if { case `$(MSGMERGE) --version | sed 1q | sed -e 's,^[^0-9]*,,'` in \
224	       '' | 0.[0-9] | 0.[0-9].* | 0.1[0-7] | 0.1[0-7].*) \
225	         $(MSGMERGE) $(MSGMERGE_OPTIONS) -o $$tmpdir/$$lang.new.po $$lang.po $(DOMAIN).pot;; \
226	       *) \
227	         $(MSGMERGE) $(MSGMERGE_OPTIONS) --lang=$$lang -o $$tmpdir/$$lang.new.po $$lang.po $(DOMAIN).pot;; \
228	     esac; \
229	   }; then \
230	  if cmp $$lang.po $$tmpdir/$$lang.new.po >/dev/null 2>&1; then \
231	    rm -f $$tmpdir/$$lang.new.po; \
232	  else \
233	    if mv -f $$tmpdir/$$lang.new.po $$lang.po; then \
234	      :; \
235	    else \
236	      echo "msgmerge for $$lang.po failed: cannot move $$tmpdir/$$lang.new.po to $$lang.po" 1>&2; \
237	      exit 1; \
238	    fi; \
239	  fi; \
240	else \
241	  echo "msgmerge for $$lang.po failed!" 1>&2; \
242	  rm -f $$tmpdir/$$lang.new.po; \
243	fi
244
245$(DUMMYPOFILES):
246
247
248update-strings: $(CATALOGS)
249	@:
250
251# During .po -> .strings conversion, take into account the most recent changes
252# to the .pot file. This eliminates the need to update the .po files when the
253# .pot file has changed, which would be troublesome if the .po files are put
254# under version control.
255$(STRINGSFILES): $(DOMAIN).pot $(POFILES)
256	mkdir -p $(patsubst %/,%, $(dir $@))
257	$(MSGMERGE) $(MSGMERGE_FOR_MSGFMT_OPTION) -o $@.1po $(UNIXLOCALE_$(patsubst %.lproj,%, $(notdir $(patsubst %/,%, $(dir $@))))).po $(DOMAIN).pot
258	msgcat --stringtable-output -o $@.tmp $@.1po
259	mv $@.tmp $@
260	rm -f $@.1po
261
262$(ENSTRINGSFILES): $(DOMAIN).pot
263	mkdir -p $(patsubst %/,%, $(dir $@))
264	$(MSGINIT) -i $(DOMAIN).pot --no-translator -l $(UNIXLOCALE_$(patsubst %.lproj,%, $(notdir $(patsubst %/,%, $(dir $@))))) --stringtable-output -o $@.tmp
265	mv $@.tmp $@
266
267echo-languages:
268	@echo $(foreach lang, $(LINGUAS), $(NSLOCALE_$(lang)))
269
270