1 /* Test program, used by the format-c-5 test.
2 Copyright (C) 2004, 2006, 2010, 2018, 2023 Free Software Foundation, Inc.
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16
17 #ifdef HAVE_CONFIG_H
18 # include "config.h"
19 #endif
20
21 #include <locale.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25
26 /* For %Id to work, we need the real setlocale(), not the fake one. */
27 #if !USE_SYSTEM_LIBINTL && !(__GLIBC__ >= 2 && !defined __UCLIBC__)
28 # include "setlocale.c"
29 #endif
30
31 #if USE_SYSTEM_LIBINTL
32 # define xsetenv setenv
33 # include <libintl.h>
34 #else
35 # include "xsetenv.h"
36 /* Make sure we use the included libintl, not the system's one. */
37 # undef _LIBINTL_H
38 # include "libgnuintl.h"
39 #endif
40
41 int
42 main (int argc, char *argv[])
43 {
44 int n = 5;
45 const char *en;
46 const char *s;
47 const char *expected_translation;
48 const char *expected_result;
49 char buf[100];
50
51 xsetenv ("LC_ALL", argv[1], 1);
52 if (setlocale (LC_ALL, "") == NULL)
53 /* Couldn't set locale. */
54 exit (77);
55
56 textdomain ("fc5");
57 bindtextdomain ("fc5", ".");
58
59 if (strcmp (gettext ("the president"), "der Vorsitzende") != 0)
60 {
61 fprintf (stderr, "Simple messages not translated.\n");
62 exit (1);
63 }
64
65 s = gettext ("father of %d children");
66 en = "father of %d children";
67 #if (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2)) && !defined __UCLIBC__
68 expected_translation = "Vater von %Id Kindern";
69 if (strncmp (argv[1], "fa", 2) == 0)
70 expected_result = "Vater von \xdb\xb5 Kindern";
71 else
72 expected_result = "Vater von 5 Kindern";
73 #else
74 expected_translation = "Vater von %d Kindern";
75 expected_result = "Vater von 5 Kindern";
76 #endif
77
78 if (strcmp (s, en) == 0)
79 {
80 fprintf (stderr, "String not translated.\n");
81 exit (1);
82 }
83 if (strcmp (s, expected_translation) != 0)
84 {
85 fprintf (stderr, "String incorrectly translated.\n");
86 exit (1);
87 }
88 sprintf (buf, s, n);
89 if (strcmp (buf, expected_result) != 0)
90 {
91 fprintf (stderr, "printf of translation wrong.\n");
92 exit (1);
93 }
94 return 0;
95 }