FreeRDP
Loading...
Searching...
No Matches
TestI18n.c
1
11#include <string.h>
12
13#include <winpr/i18n.h>
14#include <winpr/build-config.h>
15
16#ifdef WITH_WINPR_I18N
17#include <libintl.h>
18#include <locale.h>
19#endif
20
21int TestI18n(int argc, char* argv[])
22{
23 static const char msgid[] = "WinPR i18n test message";
24 WINPR_UNUSED(argc);
25 WINPR_UNUSED(argv);
26
27#ifdef WITH_WINPR_I18N
28 /* A translation locale must not change number formatting in the application. */
29 char numericLocale[128] = WINPR_C_ARRAY_INIT;
30 const char* numeric = setlocale(LC_NUMERIC, "C.UTF-8");
31 if (numeric && (strlen(numeric) < sizeof(numericLocale)))
32 memcpy(numericLocale, numeric, strlen(numeric) + 1);
33#endif
34 if (!winpr_i18n_enable_translation("C"))
35 return -1;
36#ifdef WITH_WINPR_I18N
37 if (numericLocale[0] && (strcmp(setlocale(LC_NUMERIC, nullptr), numericLocale) != 0))
38 return -1;
39#endif
40 if (winpr_i18n_bind_domain(nullptr, nullptr))
41 return -1;
42 if (!winpr_i18n_bind_domain("winpr-test", nullptr))
43 return -1;
44#ifdef WITH_WINPR_I18N
45 if (WINPR_INSTALL_LOCALEDIR[0])
46 {
47 const char* bound = bindtextdomain("winpr-test", nullptr);
48 if (!bound || (strcmp(bound, WINPR_INSTALL_LOCALEDIR) != 0))
49 return -1;
50 }
51#endif
52 const char* const result = winpr_i18n_dgettext("winpr-test", msgid);
53 if (!result || (strcmp(result, msgid) != 0))
54 return -1;
55 return strcmp(WINPR_I18N_GETTEXT("winpr-test", msgid), msgid) == 0 ? 0 : -1;
56}