mirror of
				https://gitlab.freedesktop.org/pipewire/pipewire.git
				synced 2025-11-03 09:01:54 -05:00 
			
		
		
		
	pipewire: add i18n initialization
Initialize the i18n support. Add two methods to call the i18n interface. Add defines for _() and N_() for translations.
This commit is contained in:
		
							parent
							
								
									043178e16b
								
							
						
					
					
						commit
						5f09e302a9
					
				
					 3 changed files with 39 additions and 2 deletions
				
			
		| 
						 | 
				
			
			@ -186,7 +186,7 @@ cdata.set('PIPEWIRE_API_VERSION', '"@0@"'.format(apiversion))
 | 
			
		|||
cdata.set('PIPEWIRE_DATADIR', '"@0@"'.format(pipewire_datadir))
 | 
			
		||||
cdata.set('LOCALEDIR', '"@0@"'.format(pipewire_localedir))
 | 
			
		||||
cdata.set('LIBDIR', '"@0@"'.format(pipewire_libdir))
 | 
			
		||||
cdata.set('GETTEXT_PACKAGE', '"pipewire"')
 | 
			
		||||
cdata.set('GETTEXT_PACKAGE', '"@0@"'.format(meson.project_name()))
 | 
			
		||||
cdata.set('PIPEWIRE_LICENSE', '"MIT"')
 | 
			
		||||
cdata.set('PIPEWIRE_PACKAGE_ORIGIN', '"Unknown package origin"')
 | 
			
		||||
cdata.set('PIPEWIRE_PACKAGE_NAME', '"PipeWire source release"')
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -49,6 +49,8 @@
 | 
			
		|||
 | 
			
		||||
#define SUPPORTLIB	"support/libspa-support"
 | 
			
		||||
 | 
			
		||||
static struct spa_i18n *_pipewire_i18n = NULL;
 | 
			
		||||
 | 
			
		||||
struct plugin {
 | 
			
		||||
	struct spa_list link;
 | 
			
		||||
	char *filename;
 | 
			
		||||
| 
						 | 
				
			
			@ -376,6 +378,18 @@ static const char *i18n_ntext(void *object, const char *msgid, const char *msgid
 | 
			
		|||
	return dngettext(support->i18n_domain, msgid, msgid_plural, n);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void init_i18n(struct support *support)
 | 
			
		||||
{
 | 
			
		||||
	/* Load locale from the environment. */
 | 
			
		||||
	setlocale(LC_ALL, "");
 | 
			
		||||
	/* Set LC_NUMERIC to C so that floating point strings are consistently
 | 
			
		||||
	 * formatted and parsed across locales. */
 | 
			
		||||
	setlocale(LC_NUMERIC, "C");
 | 
			
		||||
	bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
 | 
			
		||||
	bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
 | 
			
		||||
	pw_set_domain(GETTEXT_PACKAGE);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void *add_i18n(struct support *support)
 | 
			
		||||
{
 | 
			
		||||
	static struct spa_i18n_methods i18n_methods = {
 | 
			
		||||
| 
						 | 
				
			
			@ -387,11 +401,25 @@ static void *add_i18n(struct support *support)
 | 
			
		|||
			SPA_TYPE_INTERFACE_I18N,
 | 
			
		||||
			SPA_VERSION_I18N,
 | 
			
		||||
			&i18n_methods, support);
 | 
			
		||||
	_pipewire_i18n = (struct spa_i18n*) &support->i18n_iface;
 | 
			
		||||
 | 
			
		||||
	support->support[support->n_support++] =
 | 
			
		||||
		SPA_SUPPORT_INIT(SPA_TYPE_INTERFACE_I18N, &support->i18n_iface);
 | 
			
		||||
		SPA_SUPPORT_INIT(SPA_TYPE_INTERFACE_I18N, _pipewire_i18n);
 | 
			
		||||
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
SPA_EXPORT
 | 
			
		||||
const char *pw_gettext(const char *msgid)
 | 
			
		||||
{
 | 
			
		||||
	return spa_i18n_text(_pipewire_i18n, msgid);
 | 
			
		||||
}
 | 
			
		||||
SPA_EXPORT
 | 
			
		||||
const char *pw_bgettext(const char *msgid, const char *msgid_plural, unsigned long int n)
 | 
			
		||||
{
 | 
			
		||||
	return spa_i18n_ntext(_pipewire_i18n, msgid, msgid_plural, n);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#ifdef HAVE_SYSTEMD
 | 
			
		||||
static struct spa_log *load_journal_logger(struct support *support)
 | 
			
		||||
{
 | 
			
		||||
| 
						 | 
				
			
			@ -465,6 +493,8 @@ void pw_init(int *argc, char **argv[])
 | 
			
		|||
	if ((str = getenv("PIPEWIRE_DEBUG")))
 | 
			
		||||
		configure_debug(support, str);
 | 
			
		||||
 | 
			
		||||
	init_i18n(support);
 | 
			
		||||
 | 
			
		||||
	if ((str = getenv("SPA_PLUGIN_DIR")) == NULL)
 | 
			
		||||
		str = PLUGINDIR;
 | 
			
		||||
	support->plugin_dir = str;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -30,6 +30,7 @@ extern "C" {
 | 
			
		|||
#endif
 | 
			
		||||
 | 
			
		||||
#include <spa/support/plugin.h>
 | 
			
		||||
#include <spa/support/i18n.h>
 | 
			
		||||
 | 
			
		||||
#include <pipewire/array.h>
 | 
			
		||||
#include <pipewire/client.h>
 | 
			
		||||
| 
						 | 
				
			
			@ -154,6 +155,12 @@ struct spa_handle *pw_load_spa_handle(const char *lib,
 | 
			
		|||
 | 
			
		||||
int pw_unload_spa_handle(struct spa_handle *handle);
 | 
			
		||||
 | 
			
		||||
const char *pw_gettext(const char *msgid);
 | 
			
		||||
const char *pw_ngettext(const char *msgid, const char *msgid_plural, unsigned long int n);
 | 
			
		||||
 | 
			
		||||
#define _(String)	(pw_gettext(String))
 | 
			
		||||
#define N_(String)	(String)
 | 
			
		||||
 | 
			
		||||
#ifdef __cplusplus
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue