[gtksourceview] Merge gtksourceview-i18n into gtksourceview-utils



commit a5e26dd02ea5b240838094861474ad44c8fe77d1
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Sat Sep 23 15:00:31 2017 +0200

    Merge gtksourceview-i18n into gtksourceview-utils
    
    What remained in gtksourceview-i18n.h was just two utils functions.

 docs/reference/Makefile.am          |    1 -
 gtksourceview/Makefile.am           |    2 -
 gtksourceview/gtksourcelanguage.c   |    3 +-
 gtksourceview/gtksourceview-i18n.c  |   62 -----------------------------------
 gtksourceview/gtksourceview-i18n.h  |   45 -------------------------
 gtksourceview/gtksourceview-utils.c |   38 +++++++++++++++++++++-
 gtksourceview/gtksourceview-utils.h |    7 ++++
 po/POTFILES.in                      |    1 -
 8 files changed, 46 insertions(+), 113 deletions(-)
---
diff --git a/docs/reference/Makefile.am b/docs/reference/Makefile.am
index a548352..7fcf9fd 100644
--- a/docs/reference/Makefile.am
+++ b/docs/reference/Makefile.am
@@ -62,7 +62,6 @@ IGNORE_HFILES =                                       \
        gtksourcestyle-private.h                \
        gtksourcetypes-private.h                \
        gtksourceundomanagerdefault.h           \
-       gtksourceview-i18n.h                    \
        gtksourceview-utils.h
 
 # Extra options to supply to gtkdoc-mkdb
diff --git a/gtksourceview/Makefile.am b/gtksourceview/Makefile.am
index d31a875..61317de 100644
--- a/gtksourceview/Makefile.am
+++ b/gtksourceview/Makefile.am
@@ -122,7 +122,6 @@ libgtksourceview_private_headers =          \
        gtksourcestyle-private.h                \
        gtksourcetypes-private.h                \
        gtksourceundomanagerdefault.h           \
-       gtksourceview-i18n.h                    \
        gtksourceview-utils.h
 
 libgtksourceview_private_c_files =     \
@@ -141,7 +140,6 @@ libgtksourceview_private_c_files =  \
        gtksourcepixbufhelper.c         \
        gtksourceregex.c                \
        gtksourceundomanagerdefault.c   \
-       gtksourceview-i18n.c            \
        gtksourceview-init.c            \
        gtksourceview-utils.c
 
diff --git a/gtksourceview/gtksourcelanguage.c b/gtksourceview/gtksourcelanguage.c
index 10a8431..005db5c 100644
--- a/gtksourceview/gtksourcelanguage.c
+++ b/gtksourceview/gtksourcelanguage.c
@@ -31,9 +31,10 @@
 
 #include <libxml/xmlreader.h>
 #include <glib/gstdio.h>
-#include "gtksourceview-i18n.h"
+#include <glib/gi18n-lib.h>
 #include "gtksourcelanguage-private.h"
 #include "gtksourcelanguage.h"
+#include "gtksourceview-utils.h"
 
 #ifdef G_OS_WIN32
 #include <io.h>
diff --git a/gtksourceview/gtksourceview-utils.c b/gtksourceview/gtksourceview-utils.c
index 7feee5a..32105b3 100644
--- a/gtksourceview/gtksourceview-utils.c
+++ b/gtksourceview/gtksourceview-utils.c
@@ -23,9 +23,9 @@
 #endif
 
 #include "gtksourceview-utils.h"
-
 #include <errno.h>
 #include <math.h>
+#include <glib/gi18n-lib.h>
 
 #define SOURCEVIEW_DIR "gtksourceview-3.0"
 
@@ -316,3 +316,39 @@ _gtk_source_pango_font_description_to_css (const PangoFontDescription *font_desc
 #undef ADD_KEYVAL
 #undef ADD_KEYVAL_PRINTF
 }
+
+/*
+ * _gtksourceview_dgettext:
+ *
+ * Try to translate string from given domain. It returns
+ * duplicated string which must be freed with g_free().
+ */
+gchar *
+_gtksourceview_dgettext (const gchar *domain,
+                         const gchar *string)
+{
+       const gchar *translated;
+       gchar *tmp;
+
+       g_return_val_if_fail (string != NULL, NULL);
+
+       if (domain == NULL)
+       {
+               return g_strdup (_(string));
+       }
+
+       translated = dgettext (domain, string);
+
+       if (g_strcmp0 (translated, string) == 0)
+       {
+               return g_strdup (_(string));
+       }
+
+       if (g_utf8_validate (translated, -1, NULL))
+       {
+               return g_strdup (translated);
+       }
+
+       tmp = g_locale_to_utf8 (translated, -1, NULL, NULL, NULL);
+       return tmp != NULL ? tmp : g_strdup (string);
+}
diff --git a/gtksourceview/gtksourceview-utils.h b/gtksourceview/gtksourceview-utils.h
index 19d80ee..b2209ae 100644
--- a/gtksourceview/gtksourceview-utils.h
+++ b/gtksourceview/gtksourceview-utils.h
@@ -41,6 +41,13 @@ gint         _gtk_source_string_to_int                       (const gchar *str);
 G_GNUC_INTERNAL
 gchar *                _gtk_source_pango_font_description_to_css       (const PangoFontDescription 
*font_desc);
 
+#define GD_(Domain,String) _gtksourceview_dgettext (Domain, String)
+
+/* Note: it returns duplicated string. */
+G_GNUC_INTERNAL
+gchar *                _gtksourceview_dgettext         (const gchar *domain,
+                                                const gchar *msgid) G_GNUC_FORMAT(2);
+
 G_END_DECLS
 
 #endif /* GTK_SOURCE_VIEW_UTILS_H */
diff --git a/po/POTFILES.in b/po/POTFILES.in
index e8d9456..1626e50 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -41,5 +41,4 @@ gtksourceview/gtksourcetag.c
 gtksourceview/gtksourceundomanagerdefault.c
 gtksourceview/gtksourceutils.c
 gtksourceview/gtksourceview.c
-gtksourceview/gtksourceview-i18n.c
 gtksourceview/gtksourceview-init.c


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]