summaryrefslogtreecommitdiff
path: root/tests/test-i18n.c
blob: 90b27a0be278b6d4ac4ba95560b7bc4828830bd9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include "config.h"

#include <stdio.h>

#include <locale.h>

#include "libgphoto2/i18n.h"


static
const char *const default_locale_list[] = {
	"C",
	"",
	"en_US",
	"en_US.UTF-8",
	"en@quot",
	"en@quot_US",
	"en@quot_US.UTF-8",
	"en_US@quot",
	"en_US.UTF-8@quot",
	"en_US@quot.UTF-8",
	"de",
	"de_DE",
	"de_DE.UTF-8",
	"fr",
	"fr_FR",
	"fr_FR.UTF-8"
};


static
const size_t default_locale_list_count =
	sizeof(default_locale_list) / sizeof(default_locale_list[0]);


static
void indented_print(char *indentation, char *message)
{
	if (message[0] == '\0') {
		printf("%s<no translation>\n", indentation);
		return;
	}
	printf("%s", indentation);
	for (char *p=message; *p != '\0'; ++p) {
		if (p[0] == '\n') {
			putchar(p[0]);
			if (p[1] != '\0') {
				printf("%s", indentation);
			}
		} else {
			putchar(p[0]);
		}
	}
}


static
void print_locale_list(const size_t list_count,
		       const char *const *list)
{
	for (size_t i=0; i<list_count; ++i) {
		char *locale = setlocale(LC_ALL, list[i]);
		if (locale) {
			printf("Translated empty string to '%s' (%s):\n",
			       list[i], locale);
		        indented_print("    ",
				       dgettext(GETTEXT_PACKAGE_LIBGPHOTO2,
						""));
			setlocale(LC_ALL, "C");
		} else {
			printf("Skipping locale: '%s'\n", list[i]);
		}
	}
}


int main(const int argc, const char *const *argv)
{
	bindtextdomain(GETTEXT_PACKAGE_LIBGPHOTO2, LOCALEDIR);

	if (argc > 1) {
		const size_t list_counter = (size_t) (argc - 1);
		const char *const *list   = &(argv[1]);
		print_locale_list(list_counter, list);
	} else {
		print_locale_list(default_locale_list_count,
				  default_locale_list);
	}

	return 0;
}


/*
 * Local variables:
 * mode:c
 * c-basic-offset:8
 * End:
 */