mirror of
https://gitlab.freedesktop.org/pipewire/wireplumber.git
synced 2026-05-05 00:48:01 +02:00
modules: add m-i18n
Add simple gettext i18n module. Add Lua script API functions I18n.gettext, I18n.ngettext.
This commit is contained in:
parent
f8e7b39c25
commit
bbe9ac00f3
7 changed files with 155 additions and 0 deletions
|
|
@ -17,6 +17,7 @@ wireplumber_bin_dir = get_option('prefix') / get_option('bindir')
|
|||
wireplumber_module_dir = get_option('prefix') / get_option('libdir') / 'wireplumber-' + wireplumber_api_version
|
||||
wireplumber_data_dir = get_option('prefix') / get_option('datadir') / 'wireplumber'
|
||||
wireplumber_config_dir = get_option('prefix') / get_option('sysconfdir') / 'wireplumber'
|
||||
wireplumber_locale_dir = get_option('prefix') / get_option('localedir')
|
||||
|
||||
cc = meson.get_compiler('c')
|
||||
|
||||
|
|
@ -86,6 +87,12 @@ summary({'systemd conf data': systemd.found(),
|
|||
'libsystemd': libsystemd_dep.found(),
|
||||
'libelogind': libelogind_dep.found()}, bool_yn: true)
|
||||
|
||||
libintl_dep = dependency('intl', required: false)
|
||||
if not libintl_dep.found()
|
||||
libintl_dep = cc.find_library('intl', required: false)
|
||||
endif
|
||||
summary({'libintl': libintl_dep.found()}, bool_yn: true)
|
||||
|
||||
gnome = import('gnome')
|
||||
pkgconfig = import('pkgconfig')
|
||||
fs = import('fs')
|
||||
|
|
@ -116,6 +123,7 @@ subdir('lib')
|
|||
subdir('docs')
|
||||
subdir('modules')
|
||||
subdir('src')
|
||||
subdir('po')
|
||||
|
||||
if get_option('tests')
|
||||
subdir('tests')
|
||||
|
|
|
|||
|
|
@ -161,6 +161,19 @@ shared_library(
|
|||
dependencies : [wp_dep, pipewire_dep],
|
||||
)
|
||||
|
||||
shared_library(
|
||||
'wireplumber-module-i18n',
|
||||
[
|
||||
'module-i18n.c',
|
||||
],
|
||||
c_args : [common_c_args, '-DG_LOG_DOMAIN="m-i18n"',
|
||||
'-DGETTEXT_PACKAGE="@0@"'.format(meson.project_name()),
|
||||
'-DLOCALEDIR="@0@"'.format(wireplumber_locale_dir)],
|
||||
install : true,
|
||||
install_dir : wireplumber_module_dir,
|
||||
dependencies : [wp_dep, pipewire_dep, libintl_dep],
|
||||
)
|
||||
|
||||
if libsystemd_dep.found() or libelogind_dep.found()
|
||||
shared_library(
|
||||
'wireplumber-module-logind',
|
||||
|
|
|
|||
97
modules/module-i18n.c
Normal file
97
modules/module-i18n.c
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
/* WirePlumber
|
||||
*
|
||||
* Copyright © 2022 Collabora Ltd.
|
||||
* @author Pauli Virtanen <pav@iki.fi>
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
#include <wp/wp.h>
|
||||
#include <pipewire/pipewire.h>
|
||||
|
||||
#include <libintl.h>
|
||||
|
||||
#define NAME "i18n"
|
||||
|
||||
struct _WpI18n
|
||||
{
|
||||
WpPlugin parent;
|
||||
};
|
||||
|
||||
enum {
|
||||
ACTION_GETTEXT,
|
||||
ACTION_NGETTEXT,
|
||||
N_SIGNALS
|
||||
};
|
||||
|
||||
static guint signals[N_SIGNALS] = {0};
|
||||
|
||||
G_DECLARE_FINAL_TYPE (WpI18n, wp_i18n,
|
||||
WP, I18N, WpPlugin)
|
||||
G_DEFINE_TYPE (WpI18n, wp_i18n, WP_TYPE_PLUGIN)
|
||||
|
||||
static void
|
||||
wp_i18n_init (WpI18n * self)
|
||||
{
|
||||
}
|
||||
|
||||
static gchar *
|
||||
wp_i18n_gettext (WpI18n * self, const gchar * msgid)
|
||||
{
|
||||
return g_strdup (dgettext (GETTEXT_PACKAGE, msgid));
|
||||
}
|
||||
|
||||
static gchar *
|
||||
wp_i18n_ngettext (WpI18n * self, const gchar * msgid, const gchar *msgid_plural, gulong n)
|
||||
{
|
||||
return g_strdup (dngettext (GETTEXT_PACKAGE, msgid, msgid_plural, n));
|
||||
}
|
||||
|
||||
static void
|
||||
wp_i18n_enable (WpPlugin * plugin, WpTransition * transition)
|
||||
{
|
||||
WpI18n * self = WP_I18N (plugin);
|
||||
|
||||
wp_object_update_features (WP_OBJECT (self), WP_PLUGIN_FEATURE_ENABLED, 0);
|
||||
}
|
||||
|
||||
static void
|
||||
wp_i18n_disable (WpPlugin * plugin)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
wp_i18n_class_init (WpI18nClass * klass)
|
||||
{
|
||||
WpPluginClass *plugin_class = (WpPluginClass *) klass;
|
||||
|
||||
bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
|
||||
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
|
||||
|
||||
plugin_class->enable = wp_i18n_enable;
|
||||
plugin_class->disable = wp_i18n_disable;
|
||||
|
||||
signals[ACTION_GETTEXT] = g_signal_new_class_handler (
|
||||
"gettext", G_TYPE_FROM_CLASS (klass),
|
||||
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
|
||||
(GCallback) wp_i18n_gettext,
|
||||
NULL, NULL, NULL, G_TYPE_STRING, 1,
|
||||
G_TYPE_STRING);
|
||||
|
||||
signals[ACTION_NGETTEXT] = g_signal_new_class_handler (
|
||||
"ngettext", G_TYPE_FROM_CLASS (klass),
|
||||
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
|
||||
(GCallback) wp_i18n_ngettext,
|
||||
NULL, NULL, NULL, G_TYPE_STRING, 3,
|
||||
G_TYPE_STRING, G_TYPE_STRING, G_TYPE_ULONG);
|
||||
}
|
||||
|
||||
WP_PLUGIN_EXPORT gboolean
|
||||
wireplumber__module_init (WpCore * core, GVariant * args, GError ** error)
|
||||
{
|
||||
wp_plugin_register (g_object_new (wp_i18n_get_type (),
|
||||
"name", NAME,
|
||||
"core", core,
|
||||
NULL));
|
||||
return TRUE;
|
||||
}
|
||||
|
|
@ -186,6 +186,29 @@ local Feature = {
|
|||
},
|
||||
}
|
||||
|
||||
local I18n = {
|
||||
gettext = function (msgid)
|
||||
local i18n = WpPlugin.find("i18n")
|
||||
if i18n then
|
||||
return i18n:call("gettext", msgid)
|
||||
else
|
||||
return msgid
|
||||
end
|
||||
end,
|
||||
ngettext = function (msgid, msgid_plural, n)
|
||||
local i18n = WpPlugin.find("i18n")
|
||||
if i18n then
|
||||
return i18n:call("ngettext", msgid, msgid_plural, n)
|
||||
else
|
||||
if n == 1 then
|
||||
return msgid
|
||||
else
|
||||
return msgid_plural
|
||||
end
|
||||
end
|
||||
end
|
||||
}
|
||||
|
||||
SANDBOX_EXPORT = {
|
||||
Debug = Debug,
|
||||
Id = Id,
|
||||
|
|
@ -209,4 +232,5 @@ SANDBOX_EXPORT = {
|
|||
State = WpState_new,
|
||||
LocalModule = WpImplModule_new,
|
||||
ImplMetadata = WpImplMetadata_new,
|
||||
I18n = I18n
|
||||
}
|
||||
|
|
|
|||
0
po/LINGUAS
Normal file
0
po/LINGUAS
Normal file
1
po/POTFILES.in
Normal file
1
po/POTFILES.in
Normal file
|
|
@ -0,0 +1 @@
|
|||
src/scripts/monitors/alsa.lua
|
||||
12
po/meson.build
Normal file
12
po/meson.build
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
i18n = import('i18n')
|
||||
|
||||
i18n.gettext(
|
||||
meson.project_name(),
|
||||
preset: 'glib',
|
||||
# Page width is set to 90 characters in order to avoid bad wrapping of the
|
||||
# bug reporting address.
|
||||
args: ['--msgid-bugs-address=https://gitlab.freedesktop.org/pipewire/wireplumber/issues/new',
|
||||
'--width=90', '--keyword=I18n.gettext:1', '--keyword=I18n.ngettext:1,2']
|
||||
)
|
||||
|
||||
po_dir = meson.current_source_dir()
|
||||
Loading…
Add table
Reference in a new issue