From 3841a906fd7461ca598db93d02eac0012ed3469a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20=22sp1rit=22=E2=80=8B?= Date: Tue, 9 Apr 2024 18:00:47 +0200 Subject: [PATCH] meson: Ensure clapper uses local translations within the devenv MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch modifies the initialization routines of clapper to check for CLAPPER_GTK_OVERRIDE_LOCALEDIR and CLAPPER_APP_OVERRIDE_LOCALEDIR and uses that instead of the LOCALEDIR specified in the config.h. It also fixes the bug where libclapper-gtk loads the translations for the clapper application and the clapper application loads the translations for the libclapper-gtk. (It took me shockingly long to figure out why the translations weren't working 🙃) Co-authored-by: Rafał Dzięgiel Signed-off-by: Florian "sp1rit"​ --- meson.build | 4 ++++ src/bin/clapper-app/main.c | 5 ++++- src/bin/clapper-app/meson.build | 2 +- src/bin/clapper-app/po/meson.build | 2 ++ src/lib/clapper-gtk/clapper-gtk-utils.c | 6 +++++- src/lib/clapper-gtk/meson.build | 2 +- src/lib/clapper-gtk/po/meson.build | 2 ++ 7 files changed, 19 insertions(+), 4 deletions(-) diff --git a/meson.build b/meson.build index 75348b95..c7657a6a 100644 --- a/meson.build +++ b/meson.build @@ -19,6 +19,8 @@ clapper_version_suffix = '-' + version_array[0] + '.0' clapper_api_name = meson.project_name() + clapper_version_suffix +devenv = environment() + gnome = import('gnome') pkgconfig = import('pkgconfig') i18n = import('i18n') @@ -124,6 +126,8 @@ endif subdir('src') subdir('doc') +meson.add_devenv(devenv) + summary({ 'prefix': prefix, 'bindir': bindir, diff --git a/src/bin/clapper-app/main.c b/src/bin/clapper-app/main.c index fe53c76e..cd33040e 100644 --- a/src/bin/clapper-app/main.c +++ b/src/bin/clapper-app/main.c @@ -29,13 +29,16 @@ gint main (gint argc, gchar **argv) { + const gchar *clapper_ldir; GApplication *application; gint status; g_setenv ("GSK_RENDERER", "gl", FALSE); setlocale (LC_ALL, ""); - bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); + if (!(clapper_ldir = g_getenv ("CLAPPER_APP_OVERRIDE_LOCALEDIR"))) + clapper_ldir = LOCALEDIR; + bindtextdomain (GETTEXT_PACKAGE, clapper_ldir); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); diff --git a/src/bin/clapper-app/meson.build b/src/bin/clapper-app/meson.build index 9e50a7ac..70e9d168 100644 --- a/src/bin/clapper-app/meson.build +++ b/src/bin/clapper-app/meson.build @@ -42,7 +42,7 @@ clapperapp_conf_inc = [ ] config_h = configuration_data() -config_h.set_quoted('GETTEXT_PACKAGE', meson.project_name() + '-gtk') +config_h.set_quoted('GETTEXT_PACKAGE', meson.project_name() + '-app') config_h.set_quoted('LOCALEDIR', join_paths (prefix, localedir)) config_h.set_quoted('CLAPPER_APP_NAME', 'Clapper') config_h.set_quoted('CLAPPER_APP_ID', app_id) diff --git a/src/bin/clapper-app/po/meson.build b/src/bin/clapper-app/po/meson.build index b166bffe..e74e8800 100644 --- a/src/bin/clapper-app/po/meson.build +++ b/src/bin/clapper-app/po/meson.build @@ -1 +1,3 @@ i18n.gettext(meson.project_name() + '-app', preset: 'glib') + +devenv.set('CLAPPER_APP_OVERRIDE_LOCALEDIR', meson.current_build_dir()) diff --git a/src/lib/clapper-gtk/clapper-gtk-utils.c b/src/lib/clapper-gtk/clapper-gtk-utils.c index bc0f3364..89ceb6bf 100644 --- a/src/lib/clapper-gtk/clapper-gtk-utils.c +++ b/src/lib/clapper-gtk/clapper-gtk-utils.c @@ -62,10 +62,14 @@ clapper_gtk_get_player_from_ancestor (GtkWidget *widget) void clapper_gtk_init_translations (void) { + const gchar *clapper_gtk_ldir; + if (initialized) return; - bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); + if (!(clapper_gtk_ldir = g_getenv ("CLAPPER_GTK_OVERRIDE_LOCALEDIR"))) + clapper_gtk_ldir = LOCALEDIR; + bindtextdomain (GETTEXT_PACKAGE, clapper_gtk_ldir); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); initialized = TRUE; diff --git a/src/lib/clapper-gtk/meson.build b/src/lib/clapper-gtk/meson.build index 8c989a73..0a9db374 100644 --- a/src/lib/clapper-gtk/meson.build +++ b/src/lib/clapper-gtk/meson.build @@ -30,7 +30,7 @@ endforeach subdir('po') config_h = configuration_data() -config_h.set_quoted('GETTEXT_PACKAGE', meson.project_name() + '-app') +config_h.set_quoted('GETTEXT_PACKAGE', meson.project_name() + '-gtk') config_h.set_quoted('LOCALEDIR', join_paths (prefix, localedir)) config_h.set_quoted('CLAPPER_GTK_RESOURCE_PREFIX', clappergtk_resource_prefix) diff --git a/src/lib/clapper-gtk/po/meson.build b/src/lib/clapper-gtk/po/meson.build index 8072d4d9..b4d2dee8 100644 --- a/src/lib/clapper-gtk/po/meson.build +++ b/src/lib/clapper-gtk/po/meson.build @@ -1 +1,3 @@ i18n.gettext(meson.project_name() + '-gtk', preset: 'glib') + +devenv.set('CLAPPER_GTK_OVERRIDE_LOCALEDIR', meson.current_build_dir())