/src/vlc/src/modules/textdomain.c
Line | Count | Source |
1 | | /***************************************************************************** |
2 | | * textdomain.c : Modules text domain management |
3 | | ***************************************************************************** |
4 | | * Copyright (C) 2010 Rémi Denis-Courmont |
5 | | * |
6 | | * This program is free software; you can redistribute it and/or modify it |
7 | | * under the terms of the GNU Lesser General Public License as published by |
8 | | * the Free Software Foundation; either version 2.1 of the License, or |
9 | | * (at your option) any later version. |
10 | | * |
11 | | * This program is distributed in the hope that it will be useful, |
12 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | | * GNU Lesser General Public License for more details. |
15 | | * |
16 | | * You should have received a copy of the GNU Lesser General Public License |
17 | | * along with this program; if not, write to the Free Software Foundation, |
18 | | * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. |
19 | | *****************************************************************************/ |
20 | | |
21 | | #ifdef HAVE_CONFIG_H |
22 | | # include "config.h" |
23 | | #endif |
24 | | |
25 | | #include <vlc_common.h> |
26 | | #include <vlc_configuration.h> |
27 | | #include "modules/modules.h" |
28 | | |
29 | | #ifdef ENABLE_NLS |
30 | | # include <libintl.h> |
31 | | # include <vlc_charset.h> |
32 | | #endif |
33 | | |
34 | | int vlc_bindtextdomain (const char *domain) |
35 | 0 | { |
36 | | #if defined (ENABLE_NLS) |
37 | | /* Specify where to find the locales for current domain */ |
38 | | char *upath = config_GetSysPath(VLC_LOCALE_DIR, NULL); |
39 | | if (unlikely(upath == NULL)) |
40 | | return -1; |
41 | | |
42 | | char *lpath = ToLocale(upath); |
43 | | if (lpath == NULL || bindtextdomain (domain, lpath) == NULL) |
44 | | { |
45 | | LocaleFree(lpath); |
46 | | fprintf (stderr, "%s: text domain not found in %s\n", domain, upath); |
47 | | free (upath); |
48 | | return -1; |
49 | | } |
50 | | LocaleFree(lpath); |
51 | | free (upath); |
52 | | |
53 | | /* LibVLC wants all messages in UTF-8. |
54 | | * Unfortunately, we cannot ask UTF-8 for strerror_r(), strsignal_r() |
55 | | * and other functions that are not part of our text domain. |
56 | | */ |
57 | | if (bind_textdomain_codeset (PACKAGE_NAME, "UTF-8") == NULL) |
58 | | { |
59 | | fprintf (stderr, "%s: UTF-8 encoding not available\n", domain); |
60 | | // Unbinds the text domain to avoid broken encoding |
61 | | bindtextdomain (PACKAGE_NAME, "/DOES_NOT_EXIST"); |
62 | | return -1; |
63 | | } |
64 | | |
65 | | /* LibVLC does NOT set the default textdomain, since it is a library. |
66 | | * This could otherwise break programs using LibVLC (other than VLC). |
67 | | * textdomain (PACKAGE_NAME); |
68 | | */ |
69 | | |
70 | | #else /* !ENABLE_NLS */ |
71 | 0 | (void)domain; |
72 | 0 | #endif |
73 | |
|
74 | 0 | return 0; |
75 | 0 | } |
76 | | |
77 | | /** |
78 | | * In-tree plugins share their gettext domain with LibVLC. |
79 | | */ |
80 | | const char *vlc_gettext(const char *msgid) |
81 | 13.1k | { |
82 | | #ifdef ENABLE_NLS |
83 | | if (likely(*msgid)) |
84 | | return dgettext (PACKAGE_NAME, msgid); |
85 | | #endif |
86 | 13.1k | return msgid; |
87 | 13.1k | } |
88 | | |
89 | | const char *vlc_ngettext(const char *msgid, const char *plural, |
90 | | unsigned long n) |
91 | 0 | { |
92 | | #ifdef ENABLE_NLS |
93 | | if (likely(*msgid)) |
94 | | return dngettext (PACKAGE_NAME, msgid, plural, n); |
95 | | #endif |
96 | 0 | return ((n == 1) ? msgid : plural); |
97 | 0 | } |