From 33d2d2e8f7705c68114dcae254c6fc319a4c3378 Mon Sep 17 00:00:00 2001 From: Jim Easterbrook Date: Wed, 11 May 2022 09:53:52 +0100 Subject: Add function to initialise locale directory The function is called from gp_abilities_list_new() so existing code will carry on working as before. Non-standard installations of libgphoto2 can call the initialisation function with their choice of locale dir. The function includes code to ensure it's only run once. --- libgphoto2/gphoto2-abilities-list.c | 22 +++++++++++++++++++++- libgphoto2/libgphoto2.sym | 1 + 2 files changed, 22 insertions(+), 1 deletion(-) (limited to 'libgphoto2') diff --git a/libgphoto2/gphoto2-abilities-list.c b/libgphoto2/gphoto2-abilities-list.c index a88861cb3..a65d67cde 100644 --- a/libgphoto2/gphoto2-abilities-list.c +++ b/libgphoto2/gphoto2-abilities-list.c @@ -69,6 +69,26 @@ gp_message_codeset (const char *codeset) return bind_textdomain_codeset (GETTEXT_PACKAGE_LIBGPHOTO2, codeset); } +/** + * \brief Initialise localisation. + * + * Call bindtextdomain() with our locale directory. This is called by + * gp_abilities_list_new() so you don't need to call it unless you have a + * non-standard installation. + * \param localedir Root directory of libgphoto2's localisation files. + * \return gphoto2 error code. + */ +int +gp_initialise_locale (const char *localedir) +{ + static int locale_initialised = 0; + if (locale_initialised) + return GP_OK; + locale_initialised = 1; + bindtextdomain (GETTEXT_PACKAGE_LIBGPHOTO2, localedir); + return GP_OK; +} + /** * \brief Allocate the memory for a new abilities list. * @@ -90,7 +110,7 @@ gp_abilities_list_new (CameraAbilitiesList **list) * an other way without introducing a global initialization * function... */ - bindtextdomain (GETTEXT_PACKAGE_LIBGPHOTO2, LOCALEDIR); + gp_initialise_locale(LOCALEDIR); C_MEM (*list = calloc (1, sizeof (CameraAbilitiesList))); diff --git a/libgphoto2/libgphoto2.sym b/libgphoto2/libgphoto2.sym index e83fefcf0..cd82d3680 100644 --- a/libgphoto2/libgphoto2.sym +++ b/libgphoto2/libgphoto2.sym @@ -122,6 +122,7 @@ gp_filesystem_set_funcs gp_file_unref gp_gamma_correct_single gp_gamma_fill_table +gp_initialise_locale gp_library_version gp_list_append gp_list_count -- cgit v1.2.1