Update Serbian translation from master branch
[wmaker-crm.git] / m4 / wm_i18n.m4
blob460a5d367f7793da8543f27a1b47b507e54c315d
1 # wm_i18n.m4 - Macros to check and enable translations in WindowMaker
3 # Copyright (c) 2014-2015 Christophe CURIS
4 # Copyright (c) 2015-2021 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 wrlib/po/ ; 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      wraster_locales=" m4_esyscmd([ls wrlib/po/ | sed -n '/po$/{s,.po,,;p}' | tr '\n' ' '])"
70      wings_locales=" m4_esyscmd([ls WINGs/po/ | sed -n '/po$/{s,.po,,;p}' | tr '\n' ' '])"
71      wmaker_locales=" m4_esyscmd([ls po/ | sed -n '/po$/{s,.po,,;p}' | tr '\n' ' '])"
72      wprefs_locales=" m4_esyscmd([ls WPrefs.app/po/ | sed -n '/po$/{s,.po,,;p}' | tr '\n' ' '])"
73      util_locales=" m4_esyscmd([ls util/po/ | sed -n '/po$/{s,.po,,;p}' | tr '\n' ' '])"
74      man_locales=" m4_esyscmd([ls doc/ | grep '^[a-z][a-z]\(_[A-Z][A-Z]\)*$' | tr '\n' ' '])"
76      # If the LINGUAS is specified as a simple '*', then we enable all the languages
77      # we know. This is not standard, but it is useful is some cases
78      AS_IF([test "x$LINGUAS" = "x*"],
79          [LINGUAS="WM_ALL_LANGUAGES"])
81      # Check every language asked by user against these lists to know what to install
82      for lang in $LINGUAS; do
83          found=0
84          wm_missing=""
85          m4_foreach([REGION], [WRaster, WINGs, wmaker, WPrefs, util, man],
86              [AS_IF([echo "$[]m4_tolower(REGION)[]_locales" | grep " $lang " > /dev/null],
87                  [m4_toupper(REGION)MOFILES="$[]m4_toupper(REGION)MOFILES $lang.mo"
88                   found=1],
89                  [wm_missing="$wm_missing, REGION"])
90              ])
91          # Locale has to be supported by at least one part to be reported in the end
92          # If it is not supported everywhere we just display a message to the user so
93          # that he knows about it
94          wm_missing="`echo "$wm_missing" | sed -e 's/^, //' `"
95          AS_IF([test $found = 1],
96              [supported_locales="$supported_locales $lang"
97               AS_IF([test "x$wm_missing" != "x"],
98                   [AC_MSG_WARN([locale $lang is not supported in $wm_missing])]) ],
99              [AC_MSG_WARN([locale $lang is not supported at all, ignoring])])
100      done
101      #
102      # Post-processing the names for the man pages because we are not expecting
103      # a "po" file but a directory name in this case
104      MANLANGDIRS="`echo $MANMOFILES | sed -e 's,\.mo,,g' `"
106 [INTLIBS=""
107  WRASTERMOFILES=""
108  WINGSMOFILES=""
109  WMAKERMOFILES=""
110  WPREFSMOFILES=""
111  UTILMOFILES=""
112  MANLANGDIRS=""
113  supported_locales=" disabled"])
115 dnl The variables that are used in the Makefiles:
116 AC_SUBST([INTLIBS])dnl
117 AC_SUBST([WRASTERMOFILES])dnl
118 AC_SUBST([WINGSMOFILES])dnl
119 AC_SUBST([WMAKERMOFILES])dnl
120 AC_SUBST([WPREFSMOFILES])dnl
121 AC_SUBST([UTILMOFILES])dnl
122 AC_SUBST([MANLANGDIRS])dnl
126 # WM_I18N_XGETTEXT
127 # ----------------
129 # xgettext is used to generate the Templates for translation, it is not
130 # mandatory for users, only for translation teams. We look for it even
131 # if I18N was not asked because it can be used by dev team.
132 AC_DEFUN_ONCE([WM_I18N_XGETTEXT],
133 [AC_CHECK_PROGS([XGETTEXT], [xgettext], [])
134 AS_IF([test "x$XGETTEXT" != "x"],
135     AS_IF([$XGETTEXT --help 2>&1 | grep "illegal" > /dev/null],
136         [AC_MSG_WARN([[$XGETTEXT is not GNU version, ignoring]])
137          XGETTEXT=""]))
138 AM_CONDITIONAL([HAVE_XGETTEXT], [test "x$XGETTEXT" != "x"])dnl
142 # WM_I18N_MENUTEXTDOMAIN
143 # ----------------------
145 # This option allows user to define a special Domain for translating
146 # Window Maker's menus. This can be useful because distributions may
147 # wish to customize the menus, and thus can make them translatable
148 # with their own po/mo files without having to touch WMaker's stuff.
149 AC_DEFUN_ONCE([WM_I18N_MENUTEXTDOMAIN],
150 [m4_divert_push([INIT_PREPARE])dnl
151  AC_ARG_WITH([menu-textdomain],
152     [AS_HELP_STRING([--with-menu-textdomain=DOMAIN],
153         [specify gettext domain used for menu translations])],
154     [AS_CASE([$withval],
155         [yes], [AC_MSG_ERROR([you are supposed to give a domain name for '--with-menu-textdomain'])],
156         [no],  [menutextdomain=""],
157         [menutextdomain="$withval"])],
158     [menutextdomain=""])
159 m4_divert_pop([INIT_PREPARE])dnl
160 AS_IF([test "x$menutextdomain" != "x"],
161     [AC_DEFINE_UNQUOTED([MENU_TEXTDOMAIN], ["$menutextdomain"],
162         [gettext domain to be used for menu translations]) ])
166 dnl WM_I18N_XLOCALE
167 dnl ---------------
169 dnl X11 needs to redefine the function 'setlocale' to properly initialize itself,
170 dnl we check if user wants to disable this behaviour or if it is not supported
171 AC_DEFUN_ONCE([WM_I18N_XLOCALE],
172 [m4_divert_push([INIT_PREPARE])dnl
173  AC_ARG_ENABLE([xlocale],
174     [AS_HELP_STRING([--disable-xlocale],
175         [disable initialization of locale for X])],
176     [AS_CASE([$enableval],
177         [yes|no], [],
178         [AC_MSG_ERROR([bad value '$enableval' for --disable-xlocale])])],
179     [enable_xlocale=auto])
180 m4_divert_pop([INIT_PREPARE])dnl
181 AS_IF([test "x$enable_xlocale" != "xno"],
182     [AC_CHECK_LIB([X11], [_Xsetlocale],
183         [AC_DEFINE([X_LOCALE], [1],
184             [defined if the locale is initialized by X window])],
185         [AS_IF([test "x$enable_xlocale" = "xyes"],
186             [AC_MSG_ERROR([support for X_LOCALE was explicitely requested, but X11 lacks the appropriate function])])],
187         [$XLFLAGS $XLIBS]) ])