/src/FreeRDP/winpr/libwinpr/utils/i18n.c
Line | Count | Source |
1 | | /** |
2 | | * WinPR: Windows Portable Runtime |
3 | | * Internationalization helpers |
4 | | * |
5 | | * Licensed under the Apache License, Version 2.0 (the "License"); |
6 | | * you may not use this file except in compliance with the License. |
7 | | */ |
8 | | |
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 | | |
17 | | BOOL winpr_i18n_enable_translation(const char* locale) |
18 | 0 | { |
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 | 0 | WINPR_UNUSED(locale); |
24 | 0 | return TRUE; |
25 | 0 | #endif |
26 | 0 | } |
27 | | |
28 | | BOOL winpr_i18n_bind_domain(const char* domain, const char* searchPath) |
29 | 0 | { |
30 | 0 | if (!domain || (domain[0] == '\0')) |
31 | 0 | 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 | 0 | WINPR_UNUSED(searchPath); |
42 | 0 | return TRUE; |
43 | 0 | #endif |
44 | 0 | } |
45 | | |
46 | | const char* winpr_i18n_dgettext(const char* domain, const char* msgid) |
47 | 0 | { |
48 | 0 | if (!msgid) |
49 | 0 | return nullptr; |
50 | | |
51 | | #ifdef WITH_WINPR_I18N |
52 | | if (domain && (domain[0] != '\0')) |
53 | | return dgettext(domain, msgid); |
54 | | #else |
55 | 0 | WINPR_UNUSED(domain); |
56 | 0 | #endif |
57 | 0 | return msgid; |
58 | 0 | } |