Add translation statistics

The Makefile in install/po has a new target "msg-stats" which
prints out statistics concerning the current pot and po files.
Here is an example:

% make msg-stats
ipa.pot has 133 messages
id.po:   107/133  80.5%   13 po untranslated,   13 missing,   26 untranslated
kn.po:     4/133   3.0%  116 po untranslated,   13 missing,  129 untranslated
pl.po:   120/133  90.2%    0 po untranslated,   13 missing,   13 untranslated

Also update configure.ac to search for msgcmp, awk & sed programs.
This commit is contained in:
John Dennis 2010-02-16 10:24:31 -05:00 committed by Rob Crittenden
parent 7ef9cc94ed
commit e7dbbd96b4
2 changed files with 33 additions and 5 deletions

View File

@ -20,6 +20,8 @@ AM_MAINTAINER_MODE
AC_SUBST(VERSION)
AC_PROG_MKDIR_P
AC_PROG_AWK
AC_PROG_SED
AC_PATH_PROG(XGETTEXT, xgettext, [no])
if test "x$XGETTEXT" = "xno"; then
@ -41,6 +43,11 @@ if test "x$MSGMERGE" = "xno"; then
AC_MSG_ERROR([msgmerge not found, install gettext])
fi
AC_PATH_PROG(MSGCMP, msgcmp, [no])
if test "x$MSGCMP" = "xno"; then
AC_MSG_ERROR([msgcmp not found, install gettext])
fi
AC_ARG_WITH([gettext_domain],
[AS_HELP_STRING([--with-gettext-domain=name],
[set the name of the i18n message catalog])],

View File

@ -6,11 +6,14 @@ localedir = ${datarootdir}/locale
INSTALL = @INSTALL@
INSTALL_DATA = @INSTALL@ -m 644
AWK = @AWK@
SED = @SED@
MKDIR_P = @MKDIR_P@
XGETTEXT = @XGETTEXT@
MSGFMT = @MSGFMT@
MSGINIT = @MSGINIT@
MSGMERGE = @MSGMERGE@
MSGCMP = @MSGCMP@
DOMAIN = @GETTEXT_DOMAIN@
MSGMERGE_UPDATE = $(MSGMERGE) --update
@ -24,7 +27,7 @@ XGETTEXT_OPTIONS = \
--package-name="$(PACKAGE_NAME)" \
--msgid-bugs-address="$(PACKAGE_BUGREPORT)"
languages = $(shell sed 's/\#.*//' LINGUAS) # The sed command removes comments
languages = $(shell $(SED) 's/\#.*//' LINGUAS) # The sed command removes comments
po_files = $(patsubst %, %.po, $(languages))
mo_files = $(patsubst %.po, %.mo, $(po_files))
@ -167,7 +170,7 @@ SUFFIXES = .po .mo
$(po_files): $(DOMAIN).pot
@if [ ! -f @a ]; then \
lang=`echo $@ | sed -r -e 's/\.po$$//'` # Strip .po suffix ; \
lang=`echo $@ | $(SED) -r -e 's/\.po$$//'` # Strip .po suffix ; \
echo Creating nonexistent $@, you should add this file to your SCM repository; \
$(MSGINIT) --locale $$lang --no-translator -i $(DOMAIN).pot -o $@; \
fi; \
@ -176,7 +179,7 @@ $(po_files): $(DOMAIN).pot
create-po: $(DOMAIN).pot
@for po_file in $(po_files); do \
if [ ! -e $$po_file ]; then \
lang=`echo $$po_file | sed -r -e 's/\.po$$//'` # Strip .po suffix ; \
lang=`echo $$po_file | $(SED) -r -e 's/\.po$$//'` # Strip .po suffix ; \
echo Creating nonexistent $$po_file, you should add this file to your SCM repository; \
$(MSGINIT) --locale $$lang --no-translator -i $(DOMAIN).pot -o $$po_file; \
fi; \
@ -204,9 +207,27 @@ update-pot:
mv $(DOMAIN).pot.update $(DOMAIN).pot \
&& \
# Replace the charset with UTF-8 ; \
sed -i -r -e 's%("Content-Type: text/plain; charset=)(.*)(\\n")%\1UTF-8\3%' $(DOMAIN).pot
$(SED) -i -r -e 's%("Content-Type: text/plain; charset=)(.*)(\\n")%\1UTF-8\3%' $(DOMAIN).pot
msg-stats:
@pot_count=`$(MSGFMT) --statistics $(DOMAIN).pot 2>&1 | \
$(AWK) '{match($$0, /([0-9]+) translated messages, ([0-9]+) untranslated messages/, groups); \
printf "%s\n", groups[2];}'` ; \
echo "$(DOMAIN).pot has $$pot_count messages" ; \
for po_file in $(po_files); do \
$(MSGCMP) $$po_file $(DOMAIN).pot 2>&1 | \
$(AWK) -v po_file=$$po_file -v pot_count=$$pot_count -v pot_file=$(DOMAIN).pot \
'BEGIN {po_untranslated=0; undefined=0;} \
/this message is untranslated/ {po_untranslated++} \
/this message is used but not defined/ {undefined++} \
END {untranslated = po_untranslated+undefined; \
translated = pot_count - untranslated; \
ratio = sprintf("%d/%d", translated, pot_count); \
printf "%-7s %8s %5.1f%% %4d po untranslated, %4d missing, %4d untranslated\n", \
po_file ":", ratio, translated/pot_count*100.0, po_untranslated, undefined, untranslated;}'; \
done
install: $(mo_files)
@for lang in $(languages); do \
dstdir=$(DESTDIR)$(localedir)/$$lang/LC_MESSAGES; \
@ -249,7 +270,7 @@ distclean: clean
test_lang:
rm -rf test.po test_locale
$(MSGINIT) --no-translator -i $(DOMAIN).pot -l en_US -o test.po
sed -i -r -e 's/^msgstr[ \t]+"(.*)"[ \t]*$$/msgstr "\xe2\x86\x92\1\xe2\x86\x90"/' test.po
$(SED) -i -r -e 's/^msgstr[ \t]+"(.*)"[ \t]*$$/msgstr "\xe2\x86\x92\1\xe2\x86\x90"/' test.po
$(MKDIR_P) test_locale/en_US/LC_MESSAGES
$(MSGFMT) -o test_locale/en_US/LC_MESSAGES/ipa.mo test.po