The code was moved to a dedicated file (wm_i18n.m4) to reduce the size of configure.ac;
It now searches for gettext+libintl only if LINGUAS is specified, because there is no need for them otherwise; The list of supported locales is created automatically from the list of files present in the source tree, so there won't be problem forgetting to update the variables when a new language is added, or removed because one is considered outdated; The new syntax is now using as much as possible Autoconf's syntax to ensure consistency and better portability; Took opportunity to improve the language check loop to make it smaller and to tell when a locale that the user asked for is not fully supported. Signed-off-by: Christophe CURIS <christophe.cu...@free.fr> --- WPrefs.app/po/Makefile.am | 2 +- configure.ac | 117 +++++----------------------------------------- m4/wm_i18n.m4 | 94 +++++++++++++++++++++++++++++++++++++ po/Makefile.am | 2 +- 4 files changed, 107 insertions(+), 108 deletions(-) create mode 100644 m4/wm_i18n.m4 diff --git a/WPrefs.app/po/Makefile.am b/WPrefs.app/po/Makefile.am index 7b6b7cb..21c23d3 100644 --- a/WPrefs.app/po/Makefile.am +++ b/WPrefs.app/po/Makefile.am @@ -1,6 +1,6 @@ DOMAIN = WPrefs -CATALOGS = @WPMOFILES@ +CATALOGS = @WPREFSMOFILES@ nlsdir = $(NLSDIR) diff --git a/configure.ac b/configure.ac index f43b268..95500ab 100644 --- a/configure.ac +++ b/configure.ac @@ -411,16 +411,13 @@ dnl ========== AC_CHECK_PROG([PKGCONFIG], [pkg-config], [pkg-config]) -dnl gettext -dnl ======= -dnl AM_GNU_GETTEXT +dnl Internationalization +dnl ==================== +dnl Detect the language for translations to be installed and check +dnl that the gettext environment works +WM_I18N_LANGUAGES -INTLIBS="" - -AC_CHECK_FUNC(gettext, [HAVEGETTEXT="yes"], - AC_CHECK_LIB(intl, gettext, [INTLIBS="-lintl" HAVEGETTEXT="yes"], - INTLIBS="" )) AC_CHECK_PROG(XGETTEXT, xgettext, xgettext) @@ -431,81 +428,6 @@ if test "$XGETTEXT" != ""; then fi fi -if test "$LINGUAS" != ""; then - if test "$XGETTEXT" != "" -a "$HAVEGETTEXT" != ""; then - AC_DEFINE(I18N, 1, [Internationalization (I18N) support (set by configure)]) - PO="" - echo "xgettext and gettext() exist; will build i18n support for $LINGUAS" - else - LINGUAS="" - PO="" - echo "xgettext and libintl.a don't both exist; will not build i18n support" - fi -else - INTLIBS="" - MOFILES="" - WPMOFILES="" - UTILMOFILES="" - PO="" -fi - - -dnl The Tower of Babel -dnl ================== - -dnl List of supported locales -dnl ========================= -supported_locales="be bg bs ca cs da de el es et fi fr gl hr hu hy it ja ko ms nl no pl pt ro ru sk sv tr zh_CN zh_TW" -supported_wprefs_locales="bg ca cs de es et fi fr hr hu it ja ko nl pt ru sk zh_CN zh_TW" -supported_wings_locales="bg ca cs de fr hu nl sk" -supported_util_locales="de es fr nl pt" - -for lang in $LINGUAS; do - ok=0 - for l in $supported_locales; do - if test "$l" = "$lang"; then - ok=1 - break - fi - done - if test "$ok" = 1; then - MOFILES="$MOFILES $lang.mo" - else - echo "Locale $lang is not supported." - fi - ok=0 - for l in $supported_wprefs_locales; do - if test "$l" = "$lang"; then - ok=1 - break - fi - done - if test "$ok" = 1; then - WPMOFILES="$WPMOFILES $lang.mo" - fi - ok=0 - for l in $supported_util_locales; do - if test "$l" = "$lang"; then - ok=1 - break - fi - done - if test "$ok" = 1; then - UTILMOFILES="$UTILMOFILES $lang.mo" - fi - ok=0 - for l in $supported_wings_locales; do - if test "$l" = "$lang"; then - ok=1 - break - fi - done - if test "$ok" = 1; then - WINGSMOFILES="$WINGSMOFILES $lang.mo" - fi -done - - dnl Added by Oliver - Support for NLSDIR option dnl =========================================== AC_ARG_WITH(nlsdir, AS_HELP_STRING([--with-nlsdir=PATH], [specify where the locale stuff should go])) @@ -525,13 +447,7 @@ AC_ARG_WITH(menu-textdomain, AS_HELP_STRING([--with-menu-textdomain=DOMAIN], [sp fi]) AC_SUBST(menutextdomain) -AC_SUBST(INTLIBS) AC_SUBST(NLSDIR) -AC_SUBST(MOFILES) -AC_SUBST(WPMOFILES) -AC_SUBST(UTILMOFILES) -AC_SUBST(WINGSMOFILES) -AC_SUBST(supported_locales) dnl =========================================== @@ -995,18 +911,6 @@ AC_OUTPUT dnl Provide a summary of the config dnl =============================== -if test "x$MOFILES" = "x"; then - mof=None -else - mof=`echo $MOFILES` -fi - -if test "x$MOFILES" = "x"; then - languages=None -else - languages=`echo $MOFILES | sed 's/.mo//g'` -fi - echo echo "Window Maker was configured as follows:" echo @@ -1019,11 +923,9 @@ echo "Supported graphic format libraries :$supported_gfx" echo "Unsupported features :$unsupported" echo "Antialiased text support in WINGs : $xft" echo "Pango text layout support in WINGs : $pango" -echo "Translated message files to install : $mof" -dnl echo "Supported languages beside English : $languages" -if test "x$MOFILES" != "x"; then - echo "Installation path for translations : $NLSDIR" | sed -e 's|\$(prefix)|'"$prefix|" -fi +echo "Translated languages to support :$supported_locales" +AS_IF([test "x$supported_locales" != "x disabled"], + [echo "Installation path for translations : $NLSDIR" | sed -e 's|\$(prefix)|'"$prefix|"]) AS_IF([test "x$debug" = "xyes"], [AS_ECHO(["Debug enabled: CFLAGS = $CFLAGS"]) ]) echo @@ -1031,6 +933,9 @@ echo AS_IF([test "x$wm_cv_prog_cc_nestedfunc" != "xyes"], [AC_MSG_WARN([[Your compiler does not support Nested Function, work-around enabled]])]) +AS_IF([test "x$supported_locales" = "x"], + [AC_MSG_WARN([[No language from \$LINGUAS are supported]])]) + AS_IF([test "x$enable_jpeg" = xno], [dnl AS_ECHO(["WARNING WARNING WARNING WARNING WARNING WARNING WARNING"]) AS_ECHO([]) diff --git a/m4/wm_i18n.m4 b/m4/wm_i18n.m4 new file mode 100644 index 0000000..7059c4a --- /dev/null +++ b/m4/wm_i18n.m4 @@ -0,0 +1,94 @@ +# wm_i18n.m4 - Macros to check and enable translations in WindowMaker +# +# Copyright (c) 2014-2015 Christophe CURIS +# Copyright (c) 2015 The Window Maker Tean +# +# 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; see the file COPYING. + + +# WM_I18N_LANGUAGES +# ----------------- +# +# Detect which languages the user wants to be installed and check if +# the gettext environment is available. +# +# The list of languages are provided through the environment variable +# LINGUAS as a space-separated list of ISO 3166 country codes. +# This list is checked against the list of currently available languages +# the sources and a warning is issued if a language is not found. +# +# Support for internationalisation is disabled if the variable is empty +# (or undefined) +# +# The variable 'supported_locales' is created to contain the list of +# languages that will have been detected properly and will be installed +AC_DEFUN_ONCE([WM_I18N_LANGUAGES], +[AC_ARG_VAR([LINGUAS], + [list of language translations to support (I18N), use 'list' to get the list of supported languages, default: none])dnl +AS_IF([test "x$LINGUAS" != "x"], + [wm_save_LIBS="$LIBS" + AC_SEARCH_LIBS([gettext], [intl], [], + [AC_MSG_ERROR([support for internationalization requested, but library for gettext not found])]) + AS_IF([test "x$ac_cv_search_gettext" = "xnone required"], + [INTLIBS=""], + [INTLIBS="$ac_cv_search_gettext"]) + AC_CHECK_FUNCS([gettext dgettext], [], + [AC_MSG_ERROR([support for internationalization requested, but gettext was not found])]) + LIBS="$wm_save_LIBS" + dnl + dnl Environment is sane, let's continue + AC_DEFINE([I18N], [1], [Internationalization (I18N) support (set by configure)]) + supported_locales="" + + # This is the list of locales that our archive currently supports + wings_locales=" m4_esyscmd([ls WINGs/po/ | sed -n '/po$/{s,.po,,;p}' | tr '\n' ' '])" + wmaker_locales=" m4_esyscmd([ls po/ | sed -n '/po$/{s,.po,,;p}' | tr '\n' ' '])" + wprefs_locales=" m4_esyscmd([ls WPrefs.app/po/ | sed -n '/po$/{s,.po,,;p}' | tr '\n' ' '])" + util_locales=" m4_esyscmd([ls util/po/ | sed -n '/po$/{s,.po,,;p}' | tr '\n' ' '])" + + # Check every language asked by user against these lists to know what to install + for lang in $LINGUAS; do + found=0 + wm_missing="" + m4_foreach([REGION], [WINGs, wmaker, WPrefs, util], + [AS_IF([echo "$[]m4_tolower(REGION)[]_locales" | grep " $lang " > /dev/null], + [m4_toupper(REGION)MOFILES="$[]m4_toupper(REGION)MOFILES $lang.mo" + found=1], + [wm_missing="$wm_missing, REGION"]) + ]) + # Locale has to be supported by at least one part to be reported in the end + # If it is not supported everywhere we just display a message to the user so + # that he knows about it + wm_missing="`echo "$wm_missing" | sed -e 's/^, //' `" + AS_IF([test $found = 1], + [supported_locales="$supported_locales $lang" + AS_IF([test "x$wm_missing" != "x"], + [AC_MSG_WARN([locale $lang is not supported in $wm_missing])]) ], + [AC_MSG_WARN([locale $lang is not supported at all, ignoring])]) + done +], +[INTLIBS="" + WINGSMOFILES="" + WMAKERMOFILES="" + WPREFSMOFILES="" + UTILMOFILES="" + supported_locales=" disabled"]) +dnl +dnl The variables that are used in the Makefiles: +AC_SUBST([INTLIBS])dnl +AC_SUBST([WINGSMOFILES])dnl +AC_SUBST([WMAKERMOFILES])dnl +AC_SUBST([WPREFSMOFILES])dnl +AC_SUBST([UTILMOFILES])dnl +]) diff --git a/po/Makefile.am b/po/Makefile.am index 242a174..f8d4e84 100644 --- a/po/Makefile.am +++ b/po/Makefile.am @@ -2,7 +2,7 @@ DOMAIN = WindowMaker nlsdir = $(NLSDIR) -CATALOGS = @MOFILES@ +CATALOGS = @WMAKERMOFILES@ CLEANFILES = $(CATALOGS) $(DOMAIN).pot -- 2.1.4 -- To unsubscribe, send mail to wmaker-dev-unsubscr...@lists.windowmaker.org.