]> git.sesse.net Git - vlc/blob - src/modules/textdomain.c
Revert "deinterlace: add basic support for YUY2 and NV12 (fixes #2206)"
[vlc] / src / modules / textdomain.c
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 "modules/modules.h"
27
28 #ifdef ENABLE_NLS
29 # include <libintl.h>
30 # if defined (__APPLE__) || defined (_WIN32) || defined(__OS2__)
31 #  include <vlc_charset.h>
32 # endif
33 #endif
34
35 int vlc_bindtextdomain (const char *domain)
36 {
37 #if defined (ENABLE_NLS)
38     /* Specify where to find the locales for current domain */
39 # if !defined (__APPLE__) && !defined (_WIN32) && !defined(__OS2__)
40     static const char path[] = LOCALEDIR;
41
42     if (bindtextdomain (domain, path) == NULL)
43     {
44         fprintf (stderr, "%s: text domain not found in %s\n", domain, path);
45         return -1;
46     }
47 # else
48     char *datadir = config_GetDataDir();
49     if (unlikely(datadir == NULL))
50         return -1;
51
52     char *upath;
53     int ret = asprintf (&upath, "%s" DIR_SEP "locale", datadir);
54     free (datadir);
55     if (unlikely(ret == -1))
56         return -1;
57
58     char *lpath = ToLocaleDup (upath);
59     if (lpath == NULL || bindtextdomain (domain, lpath) == NULL)
60     {
61         free (lpath);
62         fprintf (stderr, "%s: text domain not found in %s\n", domain, upath);
63         free (upath);
64         return -1;
65     }
66     free (lpath);
67     free (upath);
68 # endif
69
70     /* LibVLC wants all messages in UTF-8.
71      * Unfortunately, we cannot ask UTF-8 for strerror_r(), strsignal_r()
72      * and other functions that are not part of our text domain.
73      */
74     if (bind_textdomain_codeset (PACKAGE_NAME, "UTF-8") == NULL)
75     {
76         fprintf (stderr, "%s: UTF-8 encoding not available\n", domain);
77         // Unbinds the text domain to avoid broken encoding
78         bindtextdomain (PACKAGE_NAME, "/DOES_NOT_EXIST");
79         return -1;
80     }
81
82     /* LibVLC does NOT set the default textdomain, since it is a library.
83      * This could otherwise break programs using LibVLC (other than VLC).
84      * textdomain (PACKAGE_NAME);
85      */
86
87 #else /* !ENABLE_NLS */
88     (void)domain;
89 #endif
90
91     return 0;
92 }
93
94 /**
95  * In-tree plugins share their gettext domain with LibVLC.
96  */
97 char *vlc_gettext (const char *msgid)
98 {
99 #ifdef ENABLE_NLS
100     if (likely(*msgid))
101         return dgettext (PACKAGE_NAME, msgid);
102 #endif
103     return (char *)msgid;
104 }
105
106 char *vlc_ngettext (const char *msgid, const char *plural, unsigned long n)
107 {
108 #ifdef ENABLE_NLS
109     if (likely(*msgid))
110         return dngettext (PACKAGE_NAME, msgid, plural, n);
111 #endif
112     return (char *)((n == 1) ? msgid : plural);
113 }