From 4a8690ccf09f7ea352c6c6dbc92f6586fc920e92 Mon Sep 17 00:00:00 2001 From: Lev Babiev Date: Wed, 25 Dec 2024 22:19:46 +0000 Subject: [PATCH] exprlib: add GT function (i18n support) --- meson.build | 2 ++ meson.h.meson | 1 + src/exprlib.c | 12 ++++++++++++ src/sfwbar.c | 5 +++++ 4 files changed, 20 insertions(+) diff --git a/meson.build b/meson.build index c4b5a15..c0437b6 100644 --- a/meson.build +++ b/meson.build @@ -25,6 +25,8 @@ conf_data.set('module_dir', get_option('prefix') / get_option('libdir') / 'sfwbar') conf_data.set('conf_dir', get_option('prefix') / get_option('datadir') / 'sfwbar') +conf_data.set('locale_dir', + get_option('prefix') / get_option('datadir') / 'locale') configure_file(input: 'meson.h.meson', output: 'meson.h', configuration: conf_data ) diff --git a/meson.h.meson b/meson.h.meson index b3c65ac..89b41ad 100644 --- a/meson.h.meson +++ b/meson.h.meson @@ -4,3 +4,4 @@ #define GTK_LAYER_VER_MICRO @glsh_micro@ #define MODULE_DIR "@module_dir@" #define SYSTEM_CONF_DIR "@conf_dir@" +#define LOCALE_DIR "@locale_dir@" diff --git a/src/exprlib.c b/src/exprlib.c index 703f79d..6b04bf0 100644 --- a/src/exprlib.c +++ b/src/exprlib.c @@ -492,6 +492,17 @@ static value_t expr_ident ( vm_t *vm, value_t p[], int np ) return result; } +static value_t action_gettext ( vm_t *vm, value_t p[], gint np ) +{ + vm_param_check_np_range(vm, np, 1, 2, "GT"); + vm_param_check_string(vm, p, 0, "GT"); + if(np==2) + vm_param_check_string(vm, p, 1, "GT"); + + return value_new_string((gchar *)g_dgettext( + np==2? value_get_string(p[1]) : "sfwbar", value_get_string(p[0]))); +} + void expr_lib_init ( void ) { vm_func_init(); @@ -521,4 +532,5 @@ void expr_lib_init ( void ) vm_func_add("windowinfo", expr_lib_window_info, FALSE); vm_func_add("read", expr_lib_read, FALSE); vm_func_add("interfaceprovider", expr_iface_provider, FALSE); + vm_func_add("gt", action_gettext, FALSE); } diff --git a/src/sfwbar.c b/src/sfwbar.c index 5db33db..5c33242 100644 --- a/src/sfwbar.c +++ b/src/sfwbar.c @@ -4,8 +4,10 @@ */ #include +#include #include "sfwbar.h" #include "appinfo.h" +#include "meson.h" #include "wayland.h" #include "config/config.h" #include "ipc/sway.h" @@ -94,6 +96,9 @@ static void activate (GtkApplication* app, gpointer data ) GList *clist, *iter; application = app; + bindtextdomain("sfwbar", LOCALE_DIR); + bind_textdomain_codeset("sfwbar", "UTF-8"); + textdomain("sfwbar"); config_init(); expr_lib_init(); action_lib_init();