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:
@@ -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");
|
||||
|
||||
|
Reference in New Issue
Block a user