FreeRDP
Loading...
Searching...
No Matches
i18n.c
1
9#include <winpr/i18n.h>
10#include <winpr/build-config.h>
11
12#ifdef WITH_WINPR_I18N
13#include <libintl.h>
14#include <locale.h>
15#endif
16
17BOOL winpr_i18n_enable_translation(const char* locale)
18{
19#ifdef WITH_WINPR_I18N
20 const char* const requested = (locale && (locale[0] != '\0')) ? locale : "";
21 return setlocale(LC_MESSAGES, requested) ? TRUE : FALSE;
22#else
23 WINPR_UNUSED(locale);
24 return TRUE;
25#endif
26}
27
28BOOL winpr_i18n_bind_domain(const char* domain, const char* searchPath)
29{
30 if (!domain || (domain[0] == '\0'))
31 return FALSE;
32
33#ifdef WITH_WINPR_I18N
34 const char* catalogPath = searchPath;
35 if (!catalogPath || (catalogPath[0] == '\0'))
36 catalogPath = WINPR_INSTALL_LOCALEDIR;
37 if (catalogPath && (catalogPath[0] != '\0') && !bindtextdomain(domain, catalogPath))
38 return FALSE;
39 return bind_textdomain_codeset(domain, "UTF-8") ? TRUE : FALSE;
40#else
41 WINPR_UNUSED(searchPath);
42 return TRUE;
43#endif
44}
45
46const char* winpr_i18n_dgettext(const char* domain, const char* msgid)
47{
48 if (!msgid)
49 return nullptr;
50
51#ifdef WITH_WINPR_I18N
52 if (domain && (domain[0] != '\0'))
53 return dgettext(domain, msgid);
54#else
55 WINPR_UNUSED(domain);
56#endif
57 return msgid;
58}