[beast: 3/6] SFI: provide Bse::bse_gettext_domain() and Bse::_() in glib-extra.hh
- From: Tim Janik <timj src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [beast: 3/6] SFI: provide Bse::bse_gettext_domain() and Bse::_() in glib-extra.hh
- Date: Wed, 21 Jun 2017 09:51:05 +0000 (UTC)
commit 75b91060d169e8dc6375866a7dccd5b07a2e7971
Author: Tim Janik <timj gnu org>
Date: Wed Jun 21 11:48:02 2017 +0200
SFI: provide Bse::bse_gettext_domain() and Bse::_() in glib-extra.hh
Signed-off-by: Tim Janik <timj gnu org>
sfi/glib-extra.cc | 32 ++++++++++++++++++++++++++++++++
sfi/glib-extra.hh | 5 +++++
sfi/sfitests.hh | 7 -------
3 files changed, 37 insertions(+), 7 deletions(-)
---
diff --git a/sfi/glib-extra.cc b/sfi/glib-extra.cc
index 07a3b17..5720a99 100644
--- a/sfi/glib-extra.cc
+++ b/sfi/glib-extra.cc
@@ -1,6 +1,7 @@
// Licensed GNU LGPL v2.1 or later: http://www.gnu.org/licenses/lgpl.html
#include "bcore.hh"
#include <string.h>
+#include <libintl.h>
void
g_object_disconnect_any (gpointer object,
@@ -1077,4 +1078,35 @@ version ()
return PACKAGE_VERSION;
}
+static bool
+initialize_textdomain()
+{
+ bindtextdomain (BST_GETTEXT_DOMAIN, Bse::installpath (Bse::INSTALLPATH_LOCALEBASE).c_str());
+ bind_textdomain_codeset (BST_GETTEXT_DOMAIN, "UTF-8");
+ return true;
+}
+
+/// The gettext domain used by libbse.
+const char*
+bse_gettext_domain ()
+{
+ static BSE_UNUSED bool init = initialize_textdomain();
+ // Atm, Beast and libbse share a gettext domain.
+ return BST_GETTEXT_DOMAIN;
+}
+
+/// Translate message strings in the BEAST/BSE text domain.
+const char*
+_ (const char *string)
+{
+ return dgettext (bse_gettext_domain(), string);
+}
+
+/// Translate message strings in the BEAST/BSE text domain.
+std::string
+_ (const std::string &string)
+{
+ return _ (string.c_str());
+}
+
} // Bse
diff --git a/sfi/glib-extra.hh b/sfi/glib-extra.hh
index 3c7ee03..0b0578f 100644
--- a/sfi/glib-extra.hh
+++ b/sfi/glib-extra.hh
@@ -360,6 +360,11 @@ void installpath_override (const std::string &topdir);
/// Provide a string containing the BSE library version number.
std::string version ();
+// == Translate i18n strings ==
+const char* bse_gettext_domain ();
+const char* (_) (const char *string);
+std::string (_) (const std::string &string);
+
} // Bse
#endif /* __SFI_GLIB_EXTRA_H__ */
diff --git a/sfi/sfitests.hh b/sfi/sfitests.hh
index 99d9dc2..5c4cd08 100644
--- a/sfi/sfitests.hh
+++ b/sfi/sfitests.hh
@@ -16,13 +16,6 @@ sfi_init_test (int *argcp, char **argv)
#define TICK() TOK()
#define TACK() TOK()
-#ifndef _
-# define _(x) (x)
-# define Q_(x) (x)
-# define N_(x) (x)
-# define U_(x) (x)
-#endif
-
/** Macro for test repetitions needed to benchmark in the order of milliseconds.
* TEST_CALIBRATION() - This macro is used to calculate the number of
* repetitions needed for execution of a test routine, so that the total
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]