pipewire: add i18n interface to support

Implement the i18n interface and add it to support.
This commit is contained in:
Wim Taymans 2021-04-14 18:01:32 +02:00
parent 7ee23a046c
commit 0b5741e725

View file

@ -36,8 +36,11 @@
#include <errno.h>
#include <dlfcn.h>
#include <libintl.h>
#include <spa/utils/names.h>
#include <spa/support/cpu.h>
#include <spa/support/i18n.h>
#include "pipewire.h"
#include "private.h"
@ -72,6 +75,8 @@ struct support {
const char *plugin_dir;
const char *support_lib;
struct registry *registry;
const char *i18n_domain;
struct spa_interface i18n_iface;
struct spa_support support[MAX_SUPPORT];
uint32_t n_support;
unsigned int in_valgrind:1;
@ -340,6 +345,35 @@ static void *add_interface(struct support *support,
return iface;
}
static const char *i18n_text(void *object, const char *msgid)
{
struct support *support = object;
return dgettext(support->i18n_domain, msgid);
}
static const char *i18n_ntext(void *object, const char *msgid, const char *msgid_plural,
unsigned long int n)
{
struct support *support = object;
return dngettext(support->i18n_domain, msgid, msgid_plural, n);
}
static void *add_i18n(struct support *support)
{
static struct spa_i18n_methods i18n_methods = {
SPA_VERSION_I18N_METHODS,
.text = i18n_text,
.ntext = i18n_ntext,
};
support->i18n_iface = SPA_INTERFACE_INIT(
SPA_TYPE_INTERFACE_I18N,
SPA_VERSION_I18N,
&i18n_methods, support);
support->support[support->n_support++] =
SPA_SUPPORT_INIT(SPA_TYPE_INTERFACE_I18N, &support->i18n_iface);
return 0;
}
#ifdef HAVE_SYSTEMD
static struct spa_log *load_journal_logger(struct support *support)
{
@ -459,6 +493,9 @@ void pw_init(int *argc, char **argv[])
info = SPA_DICT_INIT(items, n_items);
add_interface(support, SPA_NAME_SUPPORT_CPU, SPA_TYPE_INTERFACE_CPU, &info);
add_i18n(support);
pw_log_info("version %s", pw_get_library_version());
}