pbutils: Move locale dir initialization to a separate function and do lazy initialization

It is the only thing gst_pb_utils_init()  does and it could be
automatically called from the places in pbutils it is needed.

After 1.14 we should deprecate gst_pb_utils_init().

https://bugzilla.gnome.org/show_bug.cgi?id=793611
diff --git a/gst-libs/gst/pbutils/descriptions.c b/gst-libs/gst/pbutils/descriptions.c
index 66b8316..97894c7 100644
--- a/gst-libs/gst/pbutils/descriptions.c
+++ b/gst-libs/gst/pbutils/descriptions.c
@@ -434,6 +434,8 @@
 
   g_assert (info != NULL);
 
+  gst_pb_utils_init_locale_text_domain ();
+
   if (info->desc != NULL)
     return g_strdup (_(info->desc));
 
@@ -930,6 +932,8 @@
 
   g_return_val_if_fail (protocol != NULL, NULL);
 
+  gst_pb_utils_init_locale_text_domain ();
+
   if (strcmp (protocol, "cdda") == 0)
     return g_strdup (_("Audio CD source"));
 
@@ -1019,6 +1023,8 @@
 
   g_return_val_if_fail (gst_caps_is_fixed (tmp), NULL);
 
+  gst_pb_utils_init_locale_text_domain ();
+
   /* special-case RTP caps */
   if (caps_are_rtp_caps (tmp, "video", &str)) {
     ret = g_strdup_printf (_("%s video RTP depayloader"), str);
@@ -1069,6 +1075,7 @@
   g_return_val_if_fail (GST_IS_CAPS (caps), NULL);
   tmp = copy_and_clean_caps (caps);
   g_return_val_if_fail (gst_caps_is_fixed (tmp), NULL);
+  gst_pb_utils_init_locale_text_domain ();
 
   /* special-case RTP caps */
   if (caps_are_rtp_caps (tmp, "video", &str)) {
@@ -1117,6 +1124,8 @@
 
   g_return_val_if_fail (factory_name != NULL, NULL);
 
+  gst_pb_utils_init_locale_text_domain ();
+
   ret = g_strdup_printf (_("GStreamer element %s"), factory_name);
   if (ret && g_str_has_prefix (ret, factory_name))
     *ret = g_ascii_toupper (*ret);
diff --git a/gst-libs/gst/pbutils/encoding-target.c b/gst-libs/gst/pbutils/encoding-target.c
index 539cfc4..9497d14 100644
--- a/gst-libs/gst/pbutils/encoding-target.c
+++ b/gst-libs/gst/pbutils/encoding-target.c
@@ -368,6 +368,8 @@
   const char *loc = NULL;
   gchar *ret;
 
+  gst_pb_utils_init_locale_text_domain ();
+
 #ifdef ENABLE_NLS
 #if defined(LC_MESSAGES)
   loc = setlocale (LC_MESSAGES, NULL);
diff --git a/gst-libs/gst/pbutils/pbutils-private.h b/gst-libs/gst/pbutils/pbutils-private.h
index 9f0c036..9652c8f 100644
--- a/gst-libs/gst/pbutils/pbutils-private.h
+++ b/gst-libs/gst/pbutils/pbutils-private.h
@@ -112,3 +112,6 @@
 /* missing-plugins.c */
 G_GNUC_INTERNAL
 GstCaps *copy_and_clean_caps (const GstCaps * caps);
+
+G_GNUC_INTERNAL
+void gst_pb_utils_init_locale_text_domain (void);
diff --git a/gst-libs/gst/pbutils/pbutils.c b/gst-libs/gst/pbutils/pbutils.c
index e2271ec..b75c2fa 100644
--- a/gst-libs/gst/pbutils/pbutils.c
+++ b/gst-libs/gst/pbutils/pbutils.c
@@ -60,6 +60,25 @@
 
 #include "gst/gst-i18n-plugin.h"
 
+static void
+_init_locale_text_domain (void)
+{
+#ifdef ENABLE_NLS
+  GST_DEBUG ("binding text domain %s to locale dir %s", GETTEXT_PACKAGE,
+      LOCALEDIR);
+  bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
+  bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+#endif
+}
+
+void
+gst_pb_utils_init_locale_text_domain (void)
+{
+  static GOnce locale_init_once = G_ONCE_INIT;
+
+  g_once (&locale_init_once, _init_locale_text_domain, NULL);
+}
+
 /**
  * gst_pb_utils_init:
  *
@@ -79,12 +98,7 @@
     GST_LOG ("already initialised");
     return;
   }
-#ifdef ENABLE_NLS
-  GST_DEBUG ("binding text domain %s to locale dir %s", GETTEXT_PACKAGE,
-      LOCALEDIR);
-  bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
-  bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
-#endif
+  gst_pb_utils_init_locale_text_domain ();
 
   inited = TRUE;
 }