1
0
mirror of https://github.com/gryf/wmaker.git synced 2025-12-18 12:00:31 +01:00

make: new target 'update-lang' to update the PO files for a languages against latest sources

With the new target, it is now easy to update all translations in the
project for a language against latest code with the simple command, run
from the top directory:

  make update-lang PO=<lang>

Signed-off-by: Christophe CURIS <christophe.curis@free.fr>
This commit is contained in:
Christophe CURIS
2015-01-20 22:04:10 +01:00
committed by Carlos R. Mafra
parent 2429d5e196
commit a9a0d2ac85
7 changed files with 218 additions and 0 deletions

View File

@@ -40,6 +40,7 @@ EXTRA_DIST = TODO BUGS BUGFORM FAQ INSTALL \
email-clients.txt checkpatch.pl update-changelog.pl \
script/check-translation-sources.sh \
script/generate-mapfile-from-header.sh \
script/generate-po-from-template.sh \
script/generate-txt-from-texi.sh \
script/nested-func-to-macro.sh
@@ -56,3 +57,28 @@ coverage:
.PHONY: coverage-reset coverage
endif
# make update-lang PO=<lang>
# ==========================
# Update the PO files against the POT file in all the translation sub-directories
#
# We do not use an automatic recursive target from Automake (AM_EXTRA_RECURSIVE_TARGETS)
# because we want to check only once that the variable PO was defined; the added bonus
# being that we do not process all directories but only the related ones, which is
# faster and a lot less verbose
update-lang:
if HAVE_XGETTEXT
@if echo "$(PO)" | grep -v '^[a-z][a-z]\(_[A-Z][A-Z]\)\?$$' > /dev/null ; then \
echo "Error: invalid value \"$(PO)\" for update-lang, use PO=<lang>" >&2 ; exit 1 ; \
fi ; \
for subdir in $(SUBDIRS_PO); do \
($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) update-lang || exit $$?); \
done
SUBDIRS_PO = WINGs/po po util/po WPrefs.app/po
else
@echo "Error: the program 'xgettext' was not found by configure, it is mandatory for this operation" >&2 ; exit 1
endif
.PHONY: update-lang

View File

@@ -78,7 +78,14 @@ SUFFIXES = .po .mo
all-local: $(CATALOGS)
.PHONY: update-lang
if HAVE_XGETTEXT
update-lang: $(DOMAIN).pot
$(AM_V_GEN)$(top_srcdir)/script/generate-po-from-template.sh \
-n "$(PACKAGE_NAME)" -v "$(PACKAGE_VERSION)" -b "$(PACKAGE_BUGREPORT)" \
-t "$(DOMAIN).pot" "$(srcdir)/$(PO).po"
$(DOMAIN).pot: $(POTFILES)
$(AM_V_GEN)$(XGETTEXT) --default-domain=$(DOMAIN) \
--add-comments --keyword=_ --keyword=N_ $(POTFILES)

View File

@@ -44,7 +44,14 @@ SUFFIXES = .po .mo
all-local: $(CATALOGS)
.PHONY: update-lang
if HAVE_XGETTEXT
update-lang: $(DOMAIN).pot
$(AM_V_GEN)$(top_srcdir)/script/generate-po-from-template.sh \
-n "$(PACKAGE_NAME)" -v "$(PACKAGE_VERSION)" -b "$(PACKAGE_BUGREPORT)" \
-t "$(DOMAIN).pot" "$(srcdir)/$(PO).po"
$(DOMAIN).pot: $(POTFILES)
$(AM_V_GEN)$(XGETTEXT) --default-domain=$(DOMAIN) \
--add-comments --keyword=_ --keyword=N_ $(POTFILES)

View File

@@ -348,6 +348,9 @@ value. If you don't know what is the correct value, unset it.
You may have noticed that many translations are not up to date, because the code has evolved but the
persons who initially contributed may not have had the time to continue, so any help is welcome.
Since @sc{Window Maker} 0.95.7 there are some targets to @command{make} that can help you in that
task.
@c ------------------------------------------------------------------ Install the latest sources ---
@section Install the latest sources
@@ -425,7 +428,16 @@ In @sc{Window Maker}, you have actually 4 @code{po} files to take care of:
@item @file{util/po/@emph{<lang>}.po}: for the command-line tools of @sc{Window Maker}
@end itemize
As stated previously, there is a @command{make} target that can help you to automatically generate
the POT and update the PO for these 4 cases:
@example
make update-lang PO=<lang>
@end example
Once run, it will have updated as needed the 4 @code{po} files against the latest source code.
You may wish to use the command @command{git gui} to view the changes;
you can now edit the files to complete the translation, correct them, remove deprecated stuff, ...
Please note that the encoding should be set to @emph{UTF-8} as this is now the standard.
If you think an error message is too obscure, just ask on the developer mailing list

View File

@@ -73,7 +73,14 @@ SUFFIXES = .po .mo
all-local: $(CATALOGS)
.PHONY: update-lang
if HAVE_XGETTEXT
update-lang: $(DOMAIN).pot
$(AM_V_GEN)$(top_srcdir)/script/generate-po-from-template.sh \
-n "$(PACKAGE_NAME)" -v "$(PACKAGE_VERSION)" -b "$(PACKAGE_BUGREPORT)" \
-t "$(DOMAIN).pot" "$(srcdir)/$(PO).po"
$(DOMAIN).pot: $(POTFILES)
$(AM_V_GEN)$(XGETTEXT) --default-domain=$(DOMAIN) \
--add-comments --keyword=_ --keyword=N_ $(POTFILES)

View File

@@ -0,0 +1,152 @@
#!/bin/sh
###########################################################################
#
# Window Maker window manager
#
# Copyright (c) 2014-2015 Christophe CURIS
# Copyright (c) 2015 Window Maker Team
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
###########################################################################
#
# generate-po-from-template.sh:
# update an existing <lang>.po file from the POT (gettext template for
# translations)
#
# The goal is to take the opportunity to do a little bit more than what
# msgmerge does, including:
# - copying the full template if the language file does not yet exist;
# - post-process a few fields that it does not change but we may wish to
# see updated (project name, version, ...)
#
###########################################################################
#
# Please note that this script is writen in sh+awk on purpose: this script
# is gonna be run on the machine of the person who is trying to compile
# WindowMaker, and as such we cannot be sure to find any scripting language
# in a known version and that works (python/ruby/tcl/perl/php/you-name-it).
#
# So for portability, we stick to the same sh+awk constraint as Autotools
# to limit the problem, see for example:
# http://www.gnu.org/savannah-checkouts/gnu/autoconf/manual/autoconf-2.69/html_node/Portable-Shell.html
#
###########################################################################
# Report an error on stderr and exit with status 1 to tell make could not work
arg_error() {
echo "$0: $@" >&2
exit 1
}
# print help and exit with success status
print_help() {
echo "$0: update language po file from xgettext template"
echo "Usage: $0 [options...] po_file"
echo "valid options are:"
echo " -b email : email address to place in 'Report-Msgid-Bugs-To'"
echo " -n name : name of the project, to place in 'Project-Id-Version'"
echo " -t file : template file to be used"
echo " -v version : version of the project, to place in 'Project-Id-Version'"
exit 0
}
# Extract command line arguments
while [ $# -gt 0 ]; do
case $1 in
-b)
shift
project_email="$1"
;;
-h|-help|--help) print_help ;;
-n)
shift
project_name="$1"
;;
-t)
shift
[ "x$template" = "x" ] || arg_error "template already set to \"$template\", can't use also \"$1\""
template="$1"
[ -r "$template" ] || arg_error "template file \"$1\" is not readable"
;;
-v)
shift
project_version="$1"
;;
-*) arg_error "unknow option '$1'" ;;
*)
[ "x$lang_file" = "x" ] || arg_error "only 1 po file can be specified, not \"$lang_file\" and \"$1\""
lang_file="$1"
;;
esac
shift
done
# Check consistency of command-line
[ "x$lang_file" != "x" ] || arg_error "no po file given"
[ "x$template" != "x" ] || arg_error "no template file given"
# Generate the <lang>.po using the usual method if possible
if [ -r "$lang_file" ] ; then
msgmerge --update --silent "$lang_file" "$template"
# Fuzzy matching is generally not great, so print a little message to make
# sure the user will think about taking care of it
grep ', fuzzy' "$lang_file" > /dev/null && \
echo "Warning: fuzzy matching was used in \"$lang_file\", please review"
else
# If the <lang>.po file does not exist, we create a dummy one now from the
# template, updating a few fields that 'msgmerge' will not do:
# - it won't touch 'Language', so let's handle it for the user;
# - it won't like 'CHARSET' in content-type, we place a safe 'UTF-8' as default;
echo "Warning: creating new \"$lang_file\""
lang="`echo "$lang_file" | sed -e 's,^.*/\([^/]*\)$,\1,' -e 's/\..*$//' `"
sed -e '/^"Language:/s,:.*\\n,: '"$lang"'\\n,' \
-e '/^"Content-Type:/s,CHARSET,UTF-8,' < "$template" > "$lang_file"
fi
# We need to post-process the generated file because 'msgmerge' does not do
# everything, there are some field for which we can give a value to xgettext
# but msgmerge will not take the new value of the header on update
temp_file="`echo "$lang_file" | sed -e 's,^.*/\([^/]*\)$,\1,' -e 's/\.po$//' `.tmp"
# The 'PO-Revision-Date' is supposed to be automatically updated by the user's
# po edition tool, but in case it does not, we feel safer with at least the
# current date
cmd_update="/PO-Revision-Date:/s,:.*\\\\n,: `date +"%Y-%m-%d %H:%M%z" `\\\\n,"
# We update the 'Project-Id-Version', because for historical reasons the PO
# files did not have had a consistent name; it is also the opportunity to
# place the current version of the project in the field
if [ "x$project_name$project_version" != "x" ]; then
cmd_update="$cmd_update;/Project-Id-Version:/s,:.*\\\\n,: $project_name $project_version\\\\n,"
fi
# We update the 'Report-Msgid-Bugs-To', because for historical reasons the PO
# files probably did not have this information; it is also an opportunity to be
# sure it is in line with project's latest value
if [ "x$project_email" != "x" ]; then
cmd_update="$cmd_update;/Report-Msgid-Bugs-To:/s,:.*\\\\n,: $project_email\\\\n,"
fi
mv "$lang_file" "$temp_file"
sed -e "$cmd_update" < "$temp_file" > "$lang_file"
rm -f "$temp_file"

View File

@@ -19,7 +19,14 @@ SUFFIXES = .po .mo
all-local: $(CATALOGS)
.PHONY: update-lang
if HAVE_XGETTEXT
update-lang: $(DOMAIN).pot
$(AM_V_GEN)$(top_srcdir)/script/generate-po-from-template.sh \
-n "$(PACKAGE_NAME)" -v "$(PACKAGE_VERSION)" -b "$(PACKAGE_BUGREPORT)" \
-t "$(DOMAIN).pot" "$(srcdir)/$(PO).po"
$(DOMAIN).pot: $(POTFILES)
$(AM_V_GEN)$(XGETTEXT) --default-domain=$(DOMAIN) \
--add-comments --keyword=_ --keyword=N_ $(POTFILES)