doc: do not install translated man pages if the language was not enabled in LINGUAS
[wmaker-crm.git] / m4 / wm_i18n.m4
blob307481e33bb5af6da94a6fe62af079984fabfe46
1 # wm_i18n.m4 - Macros to check and enable translations in WindowMaker
3 # Copyright (c) 2014-2015 Christophe CURIS
4 # Copyright (c) 2015 The Window Maker Tean
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along
17 # with this program; see the file COPYING.
20 # WM_I18N_LANGUAGES
21 # -----------------
23 # Detect which languages the user wants to be installed and check if
24 # the gettext environment is available.
26 # The list of languages are provided through the environment variable
27 # LINGUAS as a space-separated list of ISO 3166 country codes.
28 # This list is checked against the list of currently available languages
29 # the sources and a warning is issued if a language is not found.
31 # Support for internationalisation is disabled if the variable is empty
32 # (or undefined)
34 # The variable 'supported_locales' is created to contain the list of
35 # languages that will have been detected properly and will be installed
36 AC_DEFUN_ONCE([WM_I18N_LANGUAGES],
37 [AC_ARG_VAR([LINGUAS],
38     [list of language translations to support (I18N), use 'list' to get the list of supported languages, default: none])dnl
39 AC_DEFUN([WM_ALL_LANGUAGES],
40     [m4_esyscmd([( ls WINGs/po/ ; ls po/ ; ls WPrefs.app/po/ ; ls util/po/ ) | sed -n -e '/po$/{s,\.po,,;p}' | sort -u | tr '\n' ' '])])dnl
41 dnl We 'divert' the macro to have it executed as soon as the option list have
42 dnl been processed, so the list of locales will be printed after the configure
43 dnl options have been parsed, but before any test have been run
44 m4_divert_text([INIT_PREPARE],
45     [AS_IF([test "x$LINGUAS" = "xlist"],
46         [AS_ECHO(["Supported languages: WM_ALL_LANGUAGES"])
47          AS_EXIT([0])]) ])dnl
48 AS_IF([test "x$LINGUAS" != "x"],
49     [wm_save_LIBS="$LIBS"
50      AC_SEARCH_LIBS([gettext], [intl], [],
51         [AC_MSG_ERROR([support for internationalization requested, but library for gettext not found])])
52      AS_IF([test "x$ac_cv_search_gettext" = "xnone required"],
53          [INTLIBS=""],
54          [INTLIBS="$ac_cv_search_gettext"])
55      AC_CHECK_FUNCS([gettext dgettext], [],
56         [AC_MSG_ERROR([support for internationalization requested, but gettext was not found])])
57      LIBS="$wm_save_LIBS"
58      dnl
59      dnl The program 'msgfmt' is needed to convert the 'po' files into 'mo' files
60      AC_CHECK_PROG([MSGFMT], [msgfmt], [msgfmt])
61      AS_IF([test "x$MSGFMT" = "x"],
62          [AC_MSG_ERROR([the program 'msgfmt' is mandatory to install translation - do you miss the package 'gettext'?])])
63      dnl
64      dnl Environment is sane, let's continue
65      AC_DEFINE([I18N], [1], [Internationalization (I18N) support (set by configure)])
66      supported_locales=""
68      # This is the list of locales that our archive currently supports
69      wings_locales=" m4_esyscmd([ls WINGs/po/ | sed -n '/po$/{s,.po,,;p}' | tr '\n' ' '])"
70      wmaker_locales=" m4_esyscmd([ls po/ | sed -n '/po$/{s,.po,,;p}' | tr '\n' ' '])"
71      wprefs_locales=" m4_esyscmd([ls WPrefs.app/po/ | sed -n '/po$/{s,.po,,;p}' | tr '\n' ' '])"
72      util_locales=" m4_esyscmd([ls util/po/ | sed -n '/po$/{s,.po,,;p}' | tr '\n' ' '])"
73      man_locales=" m4_esyscmd([ls doc/ | grep '^[a-z][a-z]\(_[A-Z][A-Z]\)*$' | tr '\n' ' '])"
75      # If the LINGUAS is specified as a simple '*', then we enable all the languages
76      # we know. This is not standard, but it is useful is some cases
77      AS_IF([test "x$LINGUAS" = "x*"],
78          [LINGUAS="WM_ALL_LANGUAGES"])
80      # Check every language asked by user against these lists to know what to install
81      for lang in $LINGUAS; do
82          found=0
83          wm_missing=""
84          m4_foreach([REGION], [WINGs, wmaker, WPrefs, util, man],
85              [AS_IF([echo "$[]m4_tolower(REGION)[]_locales" | grep " $lang " > /dev/null],
86                  [m4_toupper(REGION)MOFILES="$[]m4_toupper(REGION)MOFILES $lang.mo"
87                   found=1],
88                  [wm_missing="$wm_missing, REGION"])
89              ])
90          # Locale has to be supported by at least one part to be reported in the end
91          # If it is not supported everywhere we just display a message to the user so
92          # that he knows about it
93          wm_missing="`echo "$wm_missing" | sed -e 's/^, //' `"
94          AS_IF([test $found = 1],
95              [supported_locales="$supported_locales $lang"
96               AS_IF([test "x$wm_missing" != "x"],
97                   [AC_MSG_WARN([locale $lang is not supported in $wm_missing])]) ],
98              [AC_MSG_WARN([locale $lang is not supported at all, ignoring])])
99      done
100      #
101      # Post-processing the names for the man pages because we are not expecting
102      # a "po" file but a directory name in this case
103      MANLANGDIRS="`echo $MANMOFILES | sed -e 's,\.mo,,g' `"
105 [INTLIBS=""
106  WINGSMOFILES=""
107  WMAKERMOFILES=""
108  WPREFSMOFILES=""
109  UTILMOFILES=""
110  MANLANGDIRS=""
111  supported_locales=" disabled"])
113 dnl The variables that are used in the Makefiles:
114 AC_SUBST([INTLIBS])dnl
115 AC_SUBST([WINGSMOFILES])dnl
116 AC_SUBST([WMAKERMOFILES])dnl
117 AC_SUBST([WPREFSMOFILES])dnl
118 AC_SUBST([UTILMOFILES])dnl
119 AC_SUBST([MANLANGDIRS])dnl
123 # WM_I18N_XGETTEXT
124 # ----------------
126 # xgettext is used to generate the Templates for translation, it is not
127 # mandatory for users, only for translation teams. We look for it even
128 # if I18N was not asked because it can be used by dev team.
129 AC_DEFUN_ONCE([WM_I18N_XGETTEXT],
130 [AC_CHECK_PROGS([XGETTEXT], [xgettext], [])
131 AS_IF([test "x$XGETTEXT" != "x"],
132     AS_IF([$XGETTEXT --help 2>&1 | grep "illegal" > /dev/null],
133         [AC_MSG_WARN([[$XGETTEXT is not GNU version, ignoring]])
134          XGETTEXT=""]))
135 AM_CONDITIONAL([HAVE_XGETTEXT], [test "x$XGETTEXT" != "x"])dnl
139 # WM_I18N_MENUTEXTDOMAIN
140 # ----------------------
142 # This option allows user to define a special Domain for translating
143 # Window Maker's menus. This can be useful because distributions may
144 # wish to customize the menus, and thus can make them translatable
145 # with their own po/mo files without having to touch WMaker's stuff.
146 AC_DEFUN_ONCE([WM_I18N_MENUTEXTDOMAIN],
147 [AC_ARG_WITH([menu-textdomain],
148     [AS_HELP_STRING([--with-menu-textdomain=DOMAIN],
149         [specify gettext domain used for menu translations])],
150     [AS_CASE([$withval],
151         [yes], [AC_MSG_ERROR([you are supposed to give a domain name for '--with-menu-textdomain'])],
152         [no],  [menutextdomain=""],
153         [menutextdomain="$withval"])],
154     [menutextdomain=""])
155 AS_IF([test "x$menutextdomain" != "x"],
156     [AC_DEFINE_UNQUOTED([MENU_TEXTDOMAIN], ["$menutextdomain"],
157         [gettext domain to be used for menu translations]) ])
161 dnl WM_I18N_XLOCALE
162 dnl ---------------
164 dnl X11 needs to redefine the function 'setlocale' to properly initialize itself,
165 dnl we check if user wants to disable this behaviour or if it is not supported
166 AC_DEFUN_ONCE([WM_I18N_XLOCALE],
167 [AC_ARG_ENABLE([xlocale],
168     [AS_HELP_STRING([--disable-xlocale],
169         [disable initialization of locale for X])],
170     [AS_CASE([$enableval],
171         [yes|no], [],
172         [AC_MSG_ERROR([bad value '$enableval' for --disable-xlocale])])],
173     [enable_xlocale=auto])
174 AS_IF([test "x$enable_xlocale" != "xno"],
175     [AC_CHECK_LIB([X11], [_Xsetlocale],
176         [AC_DEFINE([X_LOCALE], [1],
177             [defined if the locale is initialized by X window])],
178         [AS_IF([test "x$enable_xlocale" = "xyes"],
179             [AC_MSG_ERROR([support for X_LOCALE was explicitely requested, but X11 lacks the appropriate function])])],
180         [$XLFLAGS $XLIBS]) ])