e1ab2543660409359c3b26e078896d7b9854bd7b
[gnulib.git] / m4 / locale-fr.m4
1 # locale-fr.m4 serial 7 (gettext-0.16.2)
2 dnl Copyright (C) 2003, 2005-2007 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
6
7 dnl From Bruno Haible.
8
9 dnl Determine the name of a french locale with traditional encoding.
10 AC_DEFUN([gt_LOCALE_FR],
11 [
12   AC_REQUIRE([AC_CANONICAL_HOST])
13   AC_REQUIRE([AM_LANGINFO_CODESET])
14   AC_CACHE_CHECK([for a traditional french locale], gt_cv_locale_fr, [
15     macosx=
16 changequote(,)dnl
17     case "$host_os" in
18       darwin[56]*) ;;
19       darwin*) macosx=yes;;
20     esac
21 changequote([,])dnl
22     if test -n "$macosx"; then
23       # On Darwin 7 (MacOS X), the libc supports some locales in non-UTF-8
24       # encodings, but the kernel does not support them. The documentation
25       # says:
26       #   "... all code that calls BSD system routines should ensure
27       #    that the const *char parameters of these routines are in UTF-8
28       #    encoding. All BSD system functions expect their string
29       #    parameters to be in UTF-8 encoding and nothing else."
30       # See the comments in config.charset. Therefore we bypass the test.
31       gt_cv_locale_fr=none
32     else
33       AC_LANG_CONFTEST([AC_LANG_SOURCE([
34 changequote(,)dnl
35 #include <locale.h>
36 #include <time.h>
37 #if HAVE_LANGINFO_CODESET
38 # include <langinfo.h>
39 #endif
40 #include <stdlib.h>
41 #include <string.h>
42 struct tm t;
43 char buf[16];
44 int main () {
45   /* Check whether the given locale name is recognized by the system.  */
46   if (setlocale (LC_ALL, "") == NULL) return 1;
47   /* Check whether nl_langinfo(CODESET) is nonempty.
48      On MacOS X 10.3.5 (Darwin 7.5) in the fr_FR locale, nl_langinfo(CODESET)
49      is empty, and the behaviour of Tcl 8.4 in this locale is not useful.  */
50 #if HAVE_LANGINFO_CODESET
51   if (nl_langinfo (CODESET) [0] == '\0') return 1;
52 #endif
53 #ifdef __CYGWIN__
54   /* On Cygwin, avoid locale names  without encoding suffix, because the
55      locale_charset() function relies on the encoding suffix.  */
56   if (strchr (getenv ("LC_ALL"), '.') == NULL) return 1;
57 #endif
58   /* Check whether in the abbreviation of the second month, the second
59      character (should be U+00E9: LATIN SMALL LETTER E WITH ACUTE) is only
60      one byte long. This excludes the UTF-8 encoding.  */
61   t.tm_year = 1975 - 1900; t.tm_mon = 2 - 1; t.tm_mday = 4;
62   if (strftime (buf, sizeof (buf), "%b", &t) < 3 || buf[2] != 'v') return 1;
63   /* Check whether the decimal separator is a comma.
64      On NetBSD 3.0 in the fr_FR.ISO8859-1 locale, localeconv()->decimal_point
65      are nl_langinfo(RADIXCHAR) are both ".".  */
66   if (localeconv () ->decimal_point[0] != ',') return 1;
67   return 0;
68 }
69 changequote([,])dnl
70         ])])
71       if AC_TRY_EVAL([ac_link]) && test -s conftest$ac_exeext; then
72         # Setting LC_ALL is not enough. Need to set LC_TIME to empty, because
73         # otherwise on MacOS X 10.3.5 the LC_TIME=C from the beginning of the
74         # configure script would override the LC_ALL setting. Likewise for
75         # LC_CTYPE, which is also set at the beginning of the configure script.
76         # Test for the usual locale name.
77         if (LC_ALL=fr_FR LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then
78           gt_cv_locale_fr=fr_FR
79         else
80           # Test for the locale name with explicit encoding suffix.
81           if (LC_ALL=fr_FR.ISO-8859-1 LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then
82             gt_cv_locale_fr=fr_FR.ISO-8859-1
83           else
84             # Test for the AIX, OSF/1, FreeBSD, NetBSD, OpenBSD locale name.
85             if (LC_ALL=fr_FR.ISO8859-1 LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then
86               gt_cv_locale_fr=fr_FR.ISO8859-1
87             else
88               # Test for the HP-UX locale name.
89               if (LC_ALL=fr_FR.iso88591 LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then
90                 gt_cv_locale_fr=fr_FR.iso88591
91               else
92                 # Test for the Solaris 7 locale name.
93                 if (LC_ALL=fr LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then
94                   gt_cv_locale_fr=fr
95                 else
96                   # None found.
97                   gt_cv_locale_fr=none
98                 fi
99               fi
100             fi
101           fi
102         fi
103       fi
104       rm -fr conftest*
105     fi
106   ])
107   LOCALE_FR=$gt_cv_locale_fr
108   AC_SUBST([LOCALE_FR])
109 ])
110
111 dnl Determine the name of a french locale with UTF-8 encoding.
112 AC_DEFUN([gt_LOCALE_FR_UTF8],
113 [
114   AC_REQUIRE([AM_LANGINFO_CODESET])
115   AC_CACHE_CHECK([for a french Unicode locale], gt_cv_locale_fr_utf8, [
116     AC_LANG_CONFTEST([AC_LANG_SOURCE([
117 changequote(,)dnl
118 #include <locale.h>
119 #include <time.h>
120 #if HAVE_LANGINFO_CODESET
121 # include <langinfo.h>
122 #endif
123 #include <stdlib.h>
124 #include <string.h>
125 struct tm t;
126 char buf[16];
127 int main () {
128   /* On BeOS, locales are not implemented in libc.  Rather, libintl
129      imitates locale dependent behaviour by looking at the environment
130      variables, and all locales use the UTF-8 encoding.  */
131 #if !defined(__BEOS__)
132   /* Check whether the given locale name is recognized by the system.  */
133   if (setlocale (LC_ALL, "") == NULL) return 1;
134   /* Check whether nl_langinfo(CODESET) is nonempty.
135      On MacOS X 10.3.5 (Darwin 7.5) in the fr_FR locale, nl_langinfo(CODESET)
136      is empty, and the behaviour of Tcl 8.4 in this locale is not useful.  */
137 # if HAVE_LANGINFO_CODESET
138   if (nl_langinfo (CODESET) [0] == '\0') return 1;
139 # endif
140 # ifdef __CYGWIN__
141   /* On Cygwin, avoid locale names  without encoding suffix, because the
142      locale_charset() function relies on the encoding suffix.  */
143   if (strchr (getenv ("LC_ALL"), '.') == NULL) return 1;
144 # endif
145   /* Check whether in the abbreviation of the second month, the second
146      character (should be U+00E9: LATIN SMALL LETTER E WITH ACUTE) is
147      two bytes long, with UTF-8 encoding.  */
148   t.tm_year = 1975 - 1900; t.tm_mon = 2 - 1; t.tm_mday = 4;
149   if (strftime (buf, sizeof (buf), "%b", &t) < 4
150       || buf[1] != (char) 0xc3 || buf[2] != (char) 0xa9 || buf[3] != 'v')
151     return 1;
152 #endif
153   /* Check whether the decimal separator is a comma.
154      On NetBSD 3.0 in the fr_FR.ISO8859-1 locale, localeconv()->decimal_point
155      are nl_langinfo(RADIXCHAR) are both ".".  */
156   if (localeconv () ->decimal_point[0] != ',') return 1;
157   return 0;
158 }
159 changequote([,])dnl
160       ])])
161     if AC_TRY_EVAL([ac_link]) && test -s conftest$ac_exeext; then
162       # Setting LC_ALL is not enough. Need to set LC_TIME to empty, because
163       # otherwise on MacOS X 10.3.5 the LC_TIME=C from the beginning of the
164       # configure script would override the LC_ALL setting. Likewise for
165       # LC_CTYPE, which is also set at the beginning of the configure script.
166       # Test for the usual locale name.
167       if (LC_ALL=fr_FR LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then
168         gt_cv_locale_fr_utf8=fr_FR
169       else
170         # Test for the locale name with explicit encoding suffix.
171         if (LC_ALL=fr_FR.UTF-8 LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then
172           gt_cv_locale_fr_utf8=fr_FR.UTF-8
173         else
174           # Test for the Solaris 7 locale name.
175           if (LC_ALL=fr.UTF-8 LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then
176             gt_cv_locale_fr_utf8=fr.UTF-8
177           else
178             # None found.
179             gt_cv_locale_fr_utf8=none
180           fi
181         fi
182       fi
183     fi
184     rm -fr conftest*
185   ])
186   LOCALE_FR_UTF8=$gt_cv_locale_fr_utf8
187   AC_SUBST([LOCALE_FR_UTF8])
188 ])