summaryrefslogtreecommitdiff
path: root/libgphoto2_port/libgphoto2_port/gphoto2-port-info-list.c
diff options
context:
space:
mode:
Diffstat (limited to 'libgphoto2_port/libgphoto2_port/gphoto2-port-info-list.c')
-rw-r--r--libgphoto2_port/libgphoto2_port/gphoto2-port-info-list.c60
1 files changed, 56 insertions, 4 deletions
diff --git a/libgphoto2_port/libgphoto2_port/gphoto2-port-info-list.c b/libgphoto2_port/libgphoto2_port/gphoto2-port-info-list.c
index 83c531f30..ad131ef6b 100644
--- a/libgphoto2_port/libgphoto2_port/gphoto2-port-info-list.c
+++ b/libgphoto2_port/libgphoto2_port/gphoto2-port-info-list.c
@@ -27,6 +27,7 @@
#include <gphoto2/gphoto2-port-info-list.h>
+#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
@@ -63,13 +64,64 @@ struct _GPPortInfoList {
/**
+ * \brief Initialize the localedir directory for the libgphoto2_port gettext domain
+ *
+ * Override the localedir directory libgphoto2_port uses for its message
+ * translations.
+ *
+ * This function is called by the gp_init_localedir() function, so if
+ * you are calling that already, there is no need to call
+ * gp_port_init_localedir() yourself.
+ *
+ * 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 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_port'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_port_init_localedir (const char *localedir)
+{
+ static int locale_initialized = 0;
+ if (locale_initialized) {
+ gp_log(GP_LOG_DEBUG, "gp_port_init_localedir",
+ "ignoring late call (localedir value %s)",
+ localedir?localedir:"NULL");
+ return GP_OK;
+ }
+ const char *const actual_localedir = (localedir?localedir:LOCALEDIR);
+ const char *const gettext_domain = GETTEXT_PACKAGE_LIBGPHOTO2_PORT;
+ if (bindtextdomain (gettext_domain, actual_localedir) == NULL) {
+ if (errno == ENOMEM)
+ return GP_ERROR_NO_MEMORY;
+ return GP_ERROR;
+ }
+ gp_log(GP_LOG_DEBUG, "gp_port_init_localedir",
+ "localedir has been set to %s%s",
+ actual_localedir,
+ localedir?"":" (compile-time default)");
+ locale_initialized = 1;
+ return GP_OK;
+}
+
+
+/**
* \brief Specify codeset for translations
*
- * This function specifies the codeset that are used for the translated
+ * This function specifies the codeset that is used for the translated
* strings that are passed back by the libgphoto2_port functions.
*
- * This function is called by the gp_message_codeset() function, there is
- * no need to call it yourself.
+ * This function is called by the gp_message_codeset() function, so
+ * there is no need to call it yourself.
*
* \param codeset new codeset to use
* \return the previous codeset
@@ -99,7 +151,7 @@ gp_port_info_list_new (GPPortInfoList **list)
* We put this in here because everybody needs to call this function
* before accessing ports...
*/
- bindtextdomain (GETTEXT_PACKAGE_LIBGPHOTO2_PORT, LOCALEDIR);
+ gp_port_init_localedir (NULL);
C_MEM (*list = calloc (1, sizeof (GPPortInfoList)));