i18n: remove the module and embed the gettext calls into the lua api

There is no need to have this as an optional module, since libintl
is a hard dependency of both PipeWire and GLib. This way we can keep
things a bit simpler and faster (no string copies and plugin lookups)

Bump meson dependency to 0.59 to benefit of the libintl lookup that
is now built into meson's dependency() function.
This commit is contained in:
George Kiagiadakis
2022-05-10 15:10:52 +03:00
parent 85d0ecfb40
commit 2eed279c9d
8 changed files with 45 additions and 145 deletions

View File

@@ -106,11 +106,12 @@ wp_lib = library('wireplumber-' + wireplumber_api_version,
'-DWIREPLUMBER_DEFAULT_MODULE_DIR="@0@"'.format(wireplumber_module_dir),
'-DWIREPLUMBER_DEFAULT_CONFIG_DIR="@0@"'.format(wireplumber_config_dir),
'-DWIREPLUMBER_DEFAULT_DATA_DIR="@0@"'.format(wireplumber_data_dir),
'-DLOCALE_DIR="@0@"'.format(wireplumber_locale_dir),
'-DBUILDING_WP',
],
install: true,
include_directories: wp_lib_include_dir,
dependencies : [gobject_dep, gmodule_dep, gio_dep, pipewire_dep],
dependencies : [gobject_dep, gmodule_dep, gio_dep, pipewire_dep, libintl_dep],
soversion: wireplumber_so_version,
version: meson.project_version(),
)

View File

@@ -10,6 +10,7 @@
#include "wp.h"
#include <pipewire/pipewire.h>
#include <libintl.h>
/*!
* \defgroup wp Library Initialization
@@ -51,6 +52,9 @@ wp_init (WpInitFlags flags)
if (flags & WP_INIT_SPA_TYPES)
wp_spa_dynamic_type_init ();
bindtextdomain (GETTEXT_PACKAGE, LOCALE_DIR);
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
/* ensure WpProxy subclasses are loaded, which is needed to be able
to autodetect the GType of proxies created through wp_proxy_new_global() */
g_type_ensure (WP_TYPE_CLIENT);

View File

@@ -1,7 +1,7 @@
project('wireplumber', ['c'],
version : '0.4.9',
license : 'MIT',
meson_version : '>= 0.56.0',
meson_version : '>= 0.59.0',
default_options : [
'warning_level=1',
'buildtype=debugoptimized',
@@ -28,6 +28,11 @@ add_project_arguments([
], language: 'c'
)
add_project_arguments([
'-DGETTEXT_PACKAGE="@0@"'.format(meson.project_name()),
], language: 'c'
)
glib_dep = dependency('glib-2.0', version : glib_req_version)
gobject_dep = dependency('gobject-2.0', version : glib_req_version)
gmodule_dep = dependency('gmodule-2.0', version : glib_req_version)
@@ -37,6 +42,7 @@ spa_dep = dependency('libspa-0.2', version: '>= 0.2')
pipewire_dep = dependency('libpipewire-0.3', version: '>= 0.3.48')
mathlib = cc.find_library('m')
threads_dep = dependency('threads')
libintl_dep = dependency('intl')
system_lua = get_option('system-lua')
if system_lua
@@ -87,12 +93,6 @@ 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')

View File

@@ -137,7 +137,7 @@ shared_library(
c_args : [common_c_args, '-DG_LOG_DOMAIN="m-lua-scripting"'],
install : true,
install_dir : wireplumber_module_dir,
dependencies : [wp_dep, pipewire_dep, wplua_dep],
dependencies : [wp_dep, pipewire_dep, wplua_dep, libintl_dep],
)
shared_library(
@@ -162,19 +162,6 @@ 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',

View File

@@ -1,97 +0,0 @@
/* 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;
}

View File

@@ -10,6 +10,7 @@
#include <wp/wp.h>
#include <pipewire/pipewire.h>
#include <wplua/wplua.h>
#include <libintl.h>
#define URI_API "resource:///org/freedesktop/pipewire/wireplumber/m-lua-scripting/api.lua"
@@ -113,6 +114,32 @@ static const luaL_Reg source_methods[] = {
{ NULL, NULL }
};
/* i18n */
static int
i18n_gettext (lua_State *L)
{
const gchar * msgid = luaL_checkstring (L, 1);
lua_pushstring (L, dgettext (GETTEXT_PACKAGE, msgid));
return 1;
}
static int
i18n_ngettext (lua_State *L)
{
const gchar * msgid = luaL_checkstring (L, 1);
const gchar *msgid_plural = luaL_checkstring (L, 2);
gulong n = luaL_checkinteger (L, 3);
lua_pushstring (L, dngettext (GETTEXT_PACKAGE, msgid, msgid_plural, n));
return 1;
}
static const luaL_Reg i18n_funcs[] = {
{ "gettext", i18n_gettext },
{ "ngettext", i18n_ngettext },
{ NULL, NULL }
};
/* WpCore */
static int
@@ -1434,6 +1461,9 @@ wp_lua_scripting_api_init (lua_State *L)
luaL_newlib (L, glib_methods);
lua_setglobal (L, "GLib");
luaL_newlib (L, i18n_funcs);
lua_setglobal (L, "I18n");
luaL_newlib (L, log_funcs);
lua_setglobal (L, "WpLog");

View File

@@ -186,35 +186,13 @@ 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,
Features = Features,
Feature = Feature,
GLib = GLib,
I18n = I18n,
Log = WpLog,
Core = WpCore,
Plugin = WpPlugin,
@@ -232,5 +210,4 @@ SANDBOX_EXPORT = {
State = WpState_new,
LocalModule = WpImplModule_new,
ImplMetadata = WpImplMetadata_new,
I18n = I18n
}

View File

@@ -12,8 +12,6 @@ function alsa_monitor.enable()
load_module("reserve-device")
end
load_module("i18n")
load_monitor("alsa", {
properties = alsa_monitor.properties,
rules = alsa_monitor.rules,