Skip to content

Commit

Permalink
exprlib: add GT function (i18n support)
Browse files Browse the repository at this point in the history
  • Loading branch information
LBCrion committed Dec 25, 2024
1 parent b31a2df commit 4a8690c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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 )

Expand Down
1 change: 1 addition & 0 deletions meson.h.meson
Original file line number Diff line number Diff line change
Expand Up @@ -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@"
12 changes: 12 additions & 0 deletions src/exprlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}
5 changes: 5 additions & 0 deletions src/sfwbar.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
*/

#include <glib-unix.h>
#include <glib/gi18n.h>
#include "sfwbar.h"
#include "appinfo.h"
#include "meson.h"
#include "wayland.h"
#include "config/config.h"
#include "ipc/sway.h"
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 4a8690c

Please sign in to comment.