Blame po/Makefile.am

Packit b040ce
# po/Makefile.am for anaconda
Packit b040ce
#
Packit b040ce
# Based loosely on Makefiles generated by gettext
Packit b040ce
#
Packit b040ce
# Copyright (C) 2016 Red Hat, Inc.
Packit b040ce
#
Packit b040ce
# This program is free software; you can redistribute it and/or modify
Packit b040ce
# it under the terms of the GNU Lesser General Public License as published
Packit b040ce
# by the Free Software Foundation; either version 2.1 of the License, or
Packit b040ce
# (at your option) any later version.
Packit b040ce
#
Packit b040ce
# This program is distributed in the hope that it will be useful,
Packit b040ce
# but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit b040ce
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit b040ce
# GNU Lesser General Public License for more details.
Packit b040ce
#
Packit b040ce
# You should have received a copy of the GNU Lesser General Public License
Packit b040ce
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
Packit b040ce
#
Packit b040ce
# Author: David Shea <dshea@redhat.com>
Packit b040ce
Packit b040ce
# This file is intended to replace everything that gettextize or autopoint
Packit b040ce
# installs. It has a lot less weird crud and tries to cooperate with
Packit b040ce
# automake at least a little bit.
Packit b040ce
#
Packit b040ce
# To use it:
Packit b040ce
# - Edit COPYRIGHT_HOLDER and MSGID_BUGS_ADDRESS below
Packit b040ce
#
Packit b040ce
# - Add the file types you're interested in to POTFILE_SUFFIXES. This replaces
Packit b040ce
#   the old POTFILES.in since the list of files you want to select for
Packit b040ce
#   translation is invariably all of them.
Packit b040ce
#
Packit b040ce
# - Add po/Makefile to AC_CONFIG_FILES (there may be po/Makefile.in if
Packit b040ce
#   switching from gettextize, replace that)
Packit b040ce
#
Packit b040ce
# - Get rid of AM_GNU_GETTEXT and AM_GNU_GETTEXT_VERSION. You might want to
Packit b040ce
#   add checks for xgettext, msgmerge, msgfmt, and msgcat. Up to you.
Packit b040ce
#
Packit b040ce
# - Add the following to .gitignore:
Packit b040ce
#     po/*.mo
Packit b040ce
#     po/*.po
Packit b040ce
#     po/*.mpo
Packit b040ce
#     po/*.pot
Packit b040ce
#
Packit b040ce
# - Remove everything in the po/ directory from source control except this
Packit b040ce
#   file.
Packit b040ce
#
Packit b040ce
# The idea is something like this:
Packit b040ce
#   From a clean project, you do the automake stuff and download a bunch of
Packit b040ce
#   .po files from the external translation site. These are the "source" files.
Packit b040ce
#
Packit b040ce
#   From the source tree we create a template file, <package>.pot, of all the
Packit b040ce
#   translatable strings. This file is not saved or distributed because there's
Packit b040ce
#   really no reason to do that if translations are not part of the source
Packit b040ce
#   tree. The file is pushed to the translators when creating a new release,
Packit b040ce
#   and it is used during the build, and that's it.
Packit b040ce
#
Packit b040ce
#   The .po files might not match the .pot file, because this is the nature of
Packit b040ce
#   linear time and translations being a separate task. Maybe the translator
Packit b040ce
#   last touched the .po file yesterday. Maybe three years ago. To get the
Packit b040ce
#   translations in sync with the source, which usually means untranslating
Packit b040ce
#   some strings, we run msgmerge on all of the source files. The merged files
Packit b040ce
#   are saved in builddir as <lang>.mpo, which is a non-standard file extension
Packit b040ce
#   I just made up.
Packit b040ce
#
Packit b040ce
#   The merged .po files are then compiled into .mo files, which are what
Packit b040ce
#   get installed to /usr/share/locale.
Packit b040ce
Packit b040ce
# Variables used in xgettext arguments
Packit b040ce
COPYRIGHT_HOLDER = Red Hat, Inc.
Packit b040ce
MSGID_BUGS_ADDRESS = anaconda-devel-list@redhat.com
Packit b040ce
Packit b040ce
# What kind of files are we looking for?
Packit b040ce
POTFILE_SUFFIXES = c
Packit b040ce
Packit b040ce
# Below this line is the part that shouldn't need to be changed for other
Packit b040ce
# projects
Packit b040ce
Packit b040ce
# Turn POTFILE_SUFFIXES into a list of files
Packit b040ce
POTFILE_INPUT = $(foreach s,$(POTFILE_SUFFIXES),\
Packit b040ce
		$(shell find $(top_srcdir)/ -type d -name .git -prune -o -type f -name '*.$(s)' -print))
Packit b040ce
Packit b040ce
# The template file, generated by from all files with translatable strings.
Packit b040ce
POTFILE = $(PACKAGE).pot
Packit b040ce
Packit b040ce
# The translation files, provided by translators, pulled down from Zanata.
Packit b040ce
# Use whatever we got from Zanata, or nothing at all if no translations were
Packit b040ce
# pulled.
Packit b040ce
POFILES = $(wildcard $(srcdir)/*.po)
Packit b040ce
Packit b040ce
# The translations files after they have been merged with the latest copy of
Packit b040ce
# the .pot file. These are written to $(builddir) as <lang>.mpo.
Packit b040ce
MERGED_POFILES = $(patsubst %.po,%.mpo,$(notdir $(POFILES)))
Packit b040ce
Packit b040ce
# The MO files, which are the binary data built from the .po files.
Packit b040ce
MOFILES = $(patsubst %.mpo,%.mo,$(MERGED_POFILES))
Packit b040ce
Packit b040ce
# Special weirdness to auto-generate sr@latin.po if sr.po is present
Packit b040ce
MERGED_POFILES += $(if $(shell [ -f sr.po ] && echo y),sr@latin.mpo,)
Packit b040ce
sr@latin.mpo: $(srcdir)/sr.po
Packit b040ce
	$(AM_V_GEN)$(MSGFILTER) -i $(srcdir)/sr.po -o $@ recode-sr-latin
Packit b040ce
Packit b040ce
# The gettext programs and arguments
Packit b040ce
# xgettext eXtracts strings from translatable files and generates the template
Packit b040ce
# (.pot) file. We use a wrapper from translation-canary in order to catch
Packit b040ce
# warnings about strings that may not be translatable, and all the keyword
Packit b040ce
# arguments define the various functions that are used to mark a string as
Packit b040ce
# translatable
Packit b040ce
XGETTEXT = $(top_srcdir)/translation-canary/xgettext_werror.sh
Packit b040ce
XGETTEXT_OPTIONS = --keyword=_ --keyword=N_ --keyword=P_:1,2 \
Packit b040ce
	           --keyword=C_:1c,2 --keyword=CN_:1c,2 --keyword=CP_:1c,2,3 \
Packit b040ce
		   --add-comments=TRANSLATORS: \
Packit b040ce
		   --from-code=UTF-8 --package-name=$(PACKAGE) \
Packit b040ce
		   --package-version=$(PACKAGE_VERSION) \
Packit b040ce
		   --copyright-holder="$(COPYRIGHT_HOLDER)" \
Packit b040ce
		   --msgid-bugs-address="$(MSGID_BUGS_ADDRESS)"
Packit b040ce
Packit b040ce
# msgfmt compiles a .po file into a .mo file
Packit b040ce
# Do not include --check in the options, since those checks are more
Packit b040ce
# conveniently done by translation-canary
Packit b040ce
MSGFMT = msgfmt
Packit b040ce
MSGFMT_OPTIONS =
Packit b040ce
Packit b040ce
# msgmerge merges changes in the template (.pot) file back into the translation
Packit b040ce
# (.po) file
Packit b040ce
MSGMERGE = msgmerge
Packit b040ce
MSGMERGE_OPTIONS =
Packit b040ce
Packit b040ce
# msgfilter applies a filter to a .po file. We use this to automatically
Packit b040ce
# transliterate Serbian from Cyrillic (sr) to Latin (sr@latin).
Packit b040ce
MSGFILTER = msgfilter
Packit b040ce
Packit b040ce
# msgcat cats multiple .po (or .pot) files together. We use this to generate
Packit b040ce
# the .pot file from multiple parts.
Packit b040ce
MSGCAT = msgcat
Packit b040ce
Packit b040ce
# Automake magic for verbose/non-verbose build output
Packit b040ce
GETTEXT_V_EXTRACT   = $(GETTEXT_V_EXTRACT_$(V))
Packit b040ce
GETTEXT_V_EXTRACT_  = $(GETTEXT_V_EXTRACT_$(AM_DEFAULT_VERBOSITY))
Packit b040ce
GETTEXT_V_EXTRACT_0 = @echo "  EXTRACT " $@;
Packit b040ce
Packit b040ce
GETTEXT_V_FORMAT    = $(GETTEXT_V_FORMAT_$(V))
Packit b040ce
GETTEXT_V_FORMAT_   = $(GETTEXT_V_FORMAT_$(AM_DEFAULT_VERBOSITY))
Packit b040ce
GETTEXT_V_FORMAT_0  = @echo "  FORMAT  " $@;
Packit b040ce
Packit b040ce
GETTEXT_V_MERGE     = $(GETTEXT_V_MERGE_$(V))
Packit b040ce
GETTEXT_V_MERGE_    = $(GETTEXT_V_MERGE_$(AM_DEFAULT_VERBOSITY))
Packit b040ce
GETTEXT_V_MERGE_0   = @echo "  MERGE   " $@;
Packit b040ce
Packit b040ce
# If make was run with V=1, add verbose options to msgfmt
Packit b040ce
MSGFMT_V_OPTIONS    = $(MSGFMT_V_OPTIONS_$(V))
Packit b040ce
MSGFMT_V_OPTIONS_   = $(MSGFMT_V_OPTIONS_$(AM_DEFAULT_VERBOSITY))
Packit b040ce
MSGFMT_V_OPTIONS_0  = $(MSGFMT_OPTIONS)
Packit b040ce
MSGFMT_V_OPTIONS_1  = $(MSGFMT_OPTIONS) --statistics --verbose
Packit b040ce
Packit b040ce
# Same with msgmerge
Packit b040ce
MSGMERGE_V_OPTIONS  = $(MSGMERGE_V_OPTIONS_$(V))
Packit b040ce
MSGMERGE_V_OPTIONS_ = $(MSGMERGE_V_OPTIONS_$(AM_DEFAULT_VERBOSITY))
Packit b040ce
MSGMERGE_V_OPTIONS_0 = $(MSGMERGE_OPTIONS) --quiet
Packit b040ce
MSGMERGE_V_OPTIONS_1 = $(MSGMERGE_OPTIONS) --verbose
Packit b040ce
Packit b040ce
# Actually do stuff:
Packit b040ce
# .po files get distributed but not installed
Packit Service a8514a
dist_noinst_DATA = $(POFILES) $(POTFILE)
Packit b040ce
Packit b040ce
# Build the .mo files but don't actually do anything with them. The real
Packit b040ce
# install part is in the install-data-local target below. Build the .pot file
Packit b040ce
# as well, even if there are no .mo files to build, so it can be tested.
Packit Service a8514a
nodist_noinst_DATA = $(MOFILES)
Packit b040ce
Packit b040ce
# How to build the .pot file. This needs to be regenerated if anything that
Packit b040ce
# goes into it has changed.
Packit b040ce
$(POTFILE): $(POTFILE_INPUT)
Packit b040ce
	$(GETTEXT_V_EXTRACT)$(XGETTEXT) $(XGETTEXT_OPTIONS) --directory=$(top_srcdir) -o $@ \
Packit b040ce
	    $(patsubst $(top_srcdir)/%,%,$(POTFILE_INPUT))
Packit b040ce
Packit b040ce
# Force a rebuild of the .pot file. Useful if something got removed, for
Packit b040ce
# example.
Packit b040ce
$(PACKAGE).pot-update:
Packit b040ce
	@rm -f $(POTFILE)
Packit b040ce
	@$(MAKE) $(POTFILE)
Packit b040ce
Packit b040ce
# How to build the merged .mpo files from the .po files
Packit Service a8514a
$(MERGED_POFILES): $(POFILES)
Packit b040ce
Packit b040ce
.po.mpo:
Packit Service a8514a
	$(GETTEXT_V_MERGE)$(MSGMERGE) $(MSGMERGE_V_OPTIONS) -o $@ $< $(top_srcdir)/po/$(POTFILE)
Packit b040ce
Packit b040ce
# How to build the .mo files from the .mpo files
Packit Service a8514a
$(MOFILES): $(MERGED_POFILES) $(POTFILE)
Packit b040ce
Packit b040ce
.mpo.mo:
Packit b040ce
	$(GETTEXT_V_FORMAT)$(MSGFMT) $(MSGFMT_V_OPTIONS) -o $@ $<
Packit b040ce
Packit b040ce
# Install the .mo files.
Packit b040ce
# .mo files get installed as $datadir/locale/<lang>/LC_MESSAGES/<package>.po
Packit b040ce
# which doesn't really fit well with the way make or automake do things but
Packit b040ce
# that is the world we live in
Packit b040ce
localedir = $(datadir)/locale
Packit b040ce
install-data-local:
Packit b040ce
	@for mo in $(MOFILES) ; do \
Packit b040ce
		lang="$$(basename "$$mo" .mo)" ; \
Packit b040ce
		$(MKDIR_P) $(DESTDIR)$(localedir)/$$lang/LC_MESSAGES || exit $$? ; \
Packit b040ce
		$(INSTALL_DATA) "$$mo" "$(DESTDIR)$(localedir)/$$lang/LC_MESSAGES/$(PACKAGE).mo" || exit $$? ; \
Packit b040ce
	done
Packit b040ce
Packit b040ce
uninstall-local:
Packit b040ce
	@for mo in $(MOFILES) ; do \
Packit b040ce
		lang="$$(basename "$$mo" .mo)" ; \
Packit b040ce
		rm -f $(DESTDIR)$(localedir)/$$lang/LC_MESSAGES/$(PACKAGE).mo ; \
Packit b040ce
	done
Packit b040ce
Packit Service a8514a
CLEANFILES = $(MERGED_POFILES) $(MOFILES)