From ee1a8ac29527d7cceb083373926de404b423b131 Mon Sep 17 00:00:00 2001 From: Amos Jeffries Date: Tue, 5 Aug 2008 18:39:39 +1200 Subject: [PATCH] Automatic Translation of .PO and Error Pages This patch embeds the process of creating pre-translated error templates from .po * installs/uninstalls base templates for failover backup if no translation is to be done. * Adds dependency on translation toolkit po2html for 'make dist' target. * Adds 'make translate' target * Adjusts 'make all' to do translation. * Adds --without-po2html configure option to optionally skip the translation step unless explicitly asked for ('make translate'). * Installs translated files properly, and skips silently if missing. * Un-installs translated files, and skips silently if missing. --- configure.in | 17 +++++++++++++ errors/Makefile.am | 60 ++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 72 insertions(+), 5 deletions(-) diff --git a/configure.in b/configure.in index b8b8f64f59..048f073216 100755 --- a/configure.in +++ b/configure.in @@ -3694,6 +3694,23 @@ if test $ac_cv_have_res_ns_list = "yes" ; then fi fi +dnl Squid now has limited locale handling ... +DO_TRANSLATE="yes" +AC_ARG_WITH(po2html, +[ --without-po2html Translation toolkit is required to auto-build translated + error pages. If it is not present this option can be used + to run the 'make dist' target without translating. + A drop-in bundle of pre-translated files is available from + http://www.squid-cache.org/Versions/v3/HEAD/ +], +[ if test "$enableval" != "yes" ; then + echo "Disabling Translation Toolkit dependency" + DO_TRANSLATE="no" + fi +]) +AC_SUBST(DO_TRANSLATE) + + dnl Need the debugging version of malloc if available XTRA_OBJS='' if test "$ac_cv_lib_malloc_main" = "yes" ; then diff --git a/errors/Makefile.am b/errors/Makefile.am index 1f4aaf4531..eaba5a95da 100644 --- a/errors/Makefile.am +++ b/errors/Makefile.am @@ -10,6 +10,12 @@ errordir = $(datadir)/errors DEFAULT_ERROR_DIR = $(errordir) +# List of automated translations possible: +TRANSLATIONS = \ + en + +# Legacy language contributions... +# INSTALL_LANGUAGES = @ERR_LANGUAGES@ LANGUAGES = \ Armenian \ @@ -53,14 +59,30 @@ install-data-local: for f in $(srcdir)/$$l/ERR_*; do \ echo "$(INSTALL_DATA) $$f $(DESTDIR)$(DEFAULT_ERROR_DIR)/$$l"; \ $(INSTALL_DATA) $$f $(DESTDIR)$(DEFAULT_ERROR_DIR)/$$l; \ - done \ + done; \ + done; \ + for l in $(TRANSLATIONS) templates; do \ + if test -d $(srcdir)/$$l; then \ + $(mkinstalldirs) $(DESTDIR)$(DEFAULT_ERROR_DIR)/$$l && \ + for f in $(srcdir)/$$l/ERR_*; do \ + echo "$(INSTALL_DATA) $$f $(DESTDIR)$(DEFAULT_ERROR_DIR)/$$l"; \ + $(INSTALL_DATA) $$f $(DESTDIR)$(DEFAULT_ERROR_DIR)/$$l; \ + done; \ + fi \ done uninstall-local: - @for l in $(INSTALL_LANGUAGES); do \ + @ for l in $(INSTALL_LANGUAGES); do \ for f in $(srcdir)/$$l/ERR_*; do \ rm -f $(DESTDIR)$(DEFAULT_ERROR_DIR)/$$l/`basename $$f`; \ - done \ + done; \ + done; \ + for l in $(TRANSLATIONS) templates; do \ + if test -d $(DESTDIR)$(DEFAULT_ERROR_DIR)/$$l; then \ + for f in $(srcdir)/$$l/ERR_*; do \ + rm -f $(DESTDIR)$(DEFAULT_ERROR_DIR)/$$l/`basename $$f`; \ + done; \ + fi \ done # undocumented hack. You can use this target to create multi-lingual @@ -70,6 +92,10 @@ uninstall-local: # # by Andres Kroonmaa # +# UPDATE: this hack completely breaks HTML standards and with the addition +# of language translations is now largely obsolete. +# It will be removed without notice at some future date. +# addlang: all -@if test -d $(srcdir)/$(ADDLANG); then \ if test -d $(DEFAULT_ERROR_DIR)/$(DESTLANG); then \ @@ -85,7 +111,7 @@ addlang: all fi dist-hook: - @ for lang in $(LANGUAGES); do \ + for lang in $(LANGUAGES); do \ if test "$$lang" = .; then :; else \ test -d $(distdir)/$$lang \ || mkdir $(distdir)/$$lang \ @@ -93,4 +119,28 @@ dist-hook: cp -p $(srcdir)/$$lang/ERR_* $(distdir)/$$lang \ || exit 1; \ fi; \ - done + done; \ + if test "$(DO_TRANSLATE)" = "yes" ; then \ + translate; \ + fi + +translate: + for lang in $(TRANSLATIONS); do \ + test -d $$lang || rm -r $$lang; \ + mkdir $$lang; \ + test -d $(distdir)/$$lang \ + || mkdir $(distdir)/$$lang \ + || exit 1; \ + cd $$lang; \ + for f in `ls -1 ../templates`; do \ + echo "po2html -i ../$$lang.po -t ../templates/$$f"; \ + po2html -i ../$$lang.po -t ../templates/$$f \ + | sed -r s/\>\ \ ?\\\n\$$f || exit 1; \ + done; \ + cd ..; \ + cp -p $(srcdir)/$$lang/ERR_* $(distdir)/$$lang \ + || exit 1; \ + done + +all: + translate -- 2.47.3