1 /* Copyright (C) 2005 Hans Ulrich Niedermann <gp@n-dimensional.de>, et. al.
2 * SPDX-License-Identifier: LGPL-2.0-or-later
3 */
4
5 #include "config.h"
6
7 #include "i18n.h"
8 #include <locale.h>
9
10 #include <stdio.h>
11 #include <string.h>
12
13 struct _testcase {
14 char *locale;
15 char *untranslated;
16 char *expected;
17 };
18
19 typedef struct _testcase testcase;
20
21 /* Translators: Just ignore the stuff in the test subdirectory. */
22 static testcase testcases[] = {
23 { "de_DE.UTF-8",
24 N_("[DO_NOT_TRANSLATE_THIS_MARKER]"),
25 "[DO_NOT_TRANSLATE_THIS_MARKER_de]" },
26 { "C",
27 N_("[DO_NOT_TRANSLATE_THIS_MARKER]"),
28 N_("[DO_NOT_TRANSLATE_THIS_MARKER]") },
29 };
30
main(int argc,char * argv[])31 int main(int argc, char *argv[])
32 {
33 char *localedir;
34 int i;
35
36 if (argc != 2) {
37 puts("Syntax: test-nls <localedir>\n");
38 return 1;
39 }
40
41 localedir = argv[1];
42
43 do {
44 const char *newloc = setlocale(LC_ALL, NULL);
45 printf("Default locale: %s\n", newloc);
46 } while (0);
47
48
49 for (i=0; i < sizeof(testcases)/sizeof(testcases[0]); i++) {
50 char *locale = testcases[i].locale;
51 char *untranslated = testcases[i].untranslated;
52 char *expected = testcases[i].expected;
53 char *translation;
54
55 if (1) {
56 printf("setlocale(\"%s\")\n", locale);
57 const char *actual_locale = setlocale(LC_MESSAGES, locale);
58 if (actual_locale == NULL) {
59 fprintf(stderr, "Error: Cannot set locale to %s.\n", locale);
60 return 4;
61 }
62 printf("new locale: %s\n", actual_locale);
63 }
64
65 if (1) {
66 const char *basedir = bindtextdomain(GETTEXT_PACKAGE, localedir);
67 printf("message basedir: %s\n", basedir);
68 }
69
70 if (1) {
71 const char *domain = textdomain(GETTEXT_PACKAGE);
72 printf("message domain: %s\n", domain);
73 }
74
75 if (1) {
76 const char *codeset = bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
77 printf("message codeset: %s\n", codeset);
78 }
79
80 puts("before translation");
81 translation = gettext(untranslated);
82 puts("after translation");
83
84 if (strcmp(expected, translation) != 0) {
85 fprintf(stderr,
86 "locale: %s\n"
87 "localedir: %s\n"
88 "untranslated: %s\n"
89 "expected: %s\n"
90 "translation: %s\n"
91 "Error: translation != expected\n",
92 locale,
93 localedir,
94 untranslated,
95 expected,
96 translation);
97
98 return 1;
99 } else {
100 fprintf(stderr,
101 "expected: %s\n"
102 "translation: %s\n"
103 "Match!\n",
104 expected,
105 translation);
106 }
107 }
108 return 0;
109 }
110