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

@@ -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
}