diff options
author | Hans Ulrich Niedermann <hun@n-dimensional.de> | 2022-05-15 18:36:46 +0200 |
---|---|---|
committer | Hans Ulrich Niedermann <hun@n-dimensional.de> | 2022-05-19 17:11:17 +0200 |
commit | 77f3b22e937c212fb330a18b3f1924b3a7539122 (patch) | |
tree | ec9fa26e96f8f26535d086c2db30f34b2fa4cccb /libgphoto2/gphoto2-abilities-list.c | |
parent | 00b09b0d45f503e4cb4e02bc25e239c109bd7865 (diff) | |
download | libgphoto2-77f3b22e937c212fb330a18b3f1924b3a7539122.tar.gz |
Complete what adding gp_init_localedir() started
Complete what adding the gp_init_localedir() function implied:
* only set success flag in the success case
* consistent use of "initialize" spelling
* add analogous gp_port_init_localedir() function
* implement and document edge cases
* update NEWS
Diffstat (limited to 'libgphoto2/gphoto2-abilities-list.c')
-rw-r--r-- | libgphoto2/gphoto2-abilities-list.c | 49 |
1 files changed, 37 insertions, 12 deletions
diff --git a/libgphoto2/gphoto2-abilities-list.c b/libgphoto2/gphoto2-abilities-list.c index 33776efc8..b4a9725d1 100644 --- a/libgphoto2/gphoto2-abilities-list.c +++ b/libgphoto2/gphoto2-abilities-list.c @@ -71,27 +71,52 @@ gp_message_codeset (const char *codeset) } /** - * \brief Initialise locale directory. - * - * 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. + * \brief Initialize the localedir directory for the libgphoto2 gettext domain + * + * Override the localedir directory libgphoto2 uses for its message + * translations. + * + * You only need to call this if you have a non-standard installation + * where the locale files are at a location which differs from the + * compiled in default location. + * + * If you do need to call this function, call it before calling any + * non-initialization function. + * + * Internally, this will make sure bindtextdomain() is called for the + * relevant gettext text domain(s). + * + * \param localedir Root directory of libgphoto2's localization files. + * If NULL, use the compiled in default value, which + * will be something like "/usr/share/locale". * \return gphoto2 error code. */ int gp_init_localedir (const char *localedir) { - static int locale_initialised = 0; - if (locale_initialised) + static int locale_initialized = 0; + if (locale_initialized) { + gp_log(GP_LOG_DEBUG, "gp_init_localedir", + "ignoring late call (localedir value %s)", + localedir?localedir:"NULL"); return GP_OK; - locale_initialised = 1; - if (bindtextdomain (GETTEXT_PACKAGE_LIBGPHOTO2, localedir) == NULL) - { + } + const int gpp_result = gp_port_init_localedir (localedir); + if (gpp_result != GP_OK) { + return gpp_result; + } + const char *actual_localedir = (localedir?localedir:LOCALEDIR); + const char *const gettext_domain = GETTEXT_PACKAGE_LIBGPHOTO2; + if (bindtextdomain (gettext_domain, actual_localedir) == NULL) { if (errno == ENOMEM) return GP_ERROR_NO_MEMORY; return GP_ERROR; } + gp_log(GP_LOG_DEBUG, "gp_init_localedir", + "localedir has been set to %s%s", + actual_localedir, + localedir?"":" (compile-time default)"); + locale_initialized = 1; return GP_OK; } @@ -116,7 +141,7 @@ gp_abilities_list_new (CameraAbilitiesList **list) * an other way without introducing a global initialization * function... */ - gp_init_localedir(LOCALEDIR); + gp_init_localedir (NULL); C_MEM (*list = calloc (1, sizeof (CameraAbilitiesList))); |