win32: Package msi input files when doing a release tarball
[vlc.git] / src / modules / textdomain.c
blobbdeb936749f0d0c9a556b86158c3296bfb890081
1 /*****************************************************************************
2 * textdomain.c : Modules text domain management
3 *****************************************************************************
4 * Copyright (C) 2010 RĂ©mi Denis-Courmont
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.
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.
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 *****************************************************************************/
21 #ifdef HAVE_CONFIG_H
22 # include "config.h"
23 #endif
25 #include <vlc_common.h>
26 #include "modules/modules.h"
28 #ifdef ENABLE_NLS
29 # include <libintl.h>
30 # include <vlc_charset.h>
31 #endif
33 int vlc_bindtextdomain (const char *domain)
35 #if defined (ENABLE_NLS)
36 /* Specify where to find the locales for current domain */
37 char *upath = config_GetSysPath(VLC_LOCALE_DIR, NULL);
38 if (unlikely(upath == NULL))
39 return -1;
41 char *lpath = ToLocale(upath);
42 if (lpath == NULL || bindtextdomain (domain, lpath) == NULL)
44 LocaleFree(lpath);
45 fprintf (stderr, "%s: text domain not found in %s\n", domain, upath);
46 free (upath);
47 return -1;
49 LocaleFree(lpath);
50 free (upath);
52 /* LibVLC wants all messages in UTF-8.
53 * Unfortunately, we cannot ask UTF-8 for strerror_r(), strsignal_r()
54 * and other functions that are not part of our text domain.
56 if (bind_textdomain_codeset (PACKAGE_NAME, "UTF-8") == NULL)
58 fprintf (stderr, "%s: UTF-8 encoding not available\n", domain);
59 // Unbinds the text domain to avoid broken encoding
60 bindtextdomain (PACKAGE_NAME, "/DOES_NOT_EXIST");
61 return -1;
64 /* LibVLC does NOT set the default textdomain, since it is a library.
65 * This could otherwise break programs using LibVLC (other than VLC).
66 * textdomain (PACKAGE_NAME);
69 #else /* !ENABLE_NLS */
70 (void)domain;
71 #endif
73 return 0;
76 /**
77 * In-tree plugins share their gettext domain with LibVLC.
79 char *vlc_gettext (const char *msgid)
81 #ifdef ENABLE_NLS
82 if (likely(*msgid))
83 return dgettext (PACKAGE_NAME, msgid);
84 #endif
85 return (char *)msgid;
88 char *vlc_ngettext (const char *msgid, const char *plural, unsigned long n)
90 #ifdef ENABLE_NLS
91 if (likely(*msgid))
92 return dngettext (PACKAGE_NAME, msgid, plural, n);
93 #endif
94 return (char *)((n == 1) ? msgid : plural);