[gtksourceview: 3/3] i18n: simplify gtksourceview-i18n



commit acaaebb658865ab7f0257977cfe10dae6cca0bd0
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Tue Aug 2 06:43:01 2016 +0200

    i18n: simplify gtksourceview-i18n

 gtksourceview/gtksourceview-i18n.c |   41 ++++++++++++++----------------------
 gtksourceview/gtksourceview-i18n.h |   31 ++++++++------------------
 2 files changed, 26 insertions(+), 46 deletions(-)
---
diff --git a/gtksourceview/gtksourceview-i18n.c b/gtksourceview/gtksourceview-i18n.c
index 507d080..175999a 100644
--- a/gtksourceview/gtksourceview-i18n.c
+++ b/gtksourceview/gtksourceview-i18n.c
@@ -27,51 +27,42 @@
 
 #include "gtksourceview-i18n.h"
 
-const gchar *
-_gtksourceview_gettext (const gchar *msgid)
-{
-       return g_dgettext (GETTEXT_PACKAGE, msgid);
-}
-
 /**
  * _gtksourceview_dgettext:
  *
  * Try to translate string from given domain. It returns
  * duplicated string which must be freed with g_free().
  */
-#ifdef ENABLE_NLS
-char *
-_gtksourceview_dgettext (const char *domain,
-                         const char *string)
+gchar *
+_gtksourceview_dgettext (const gchar *domain,
+                         const gchar *string)
 {
-       gchar *tmp;
+#ifdef ENABLE_NLS
        const gchar *translated;
+       gchar *tmp;
 
        g_return_val_if_fail (string != NULL, NULL);
 
        if (domain == NULL)
-               return g_strdup (_gtksourceview_gettext (string));
+       {
+               return g_strdup (_(string));
+       }
 
        translated = dgettext (domain, string);
 
-       if (strcmp (translated, string) == 0)
-               return g_strdup (_gtksourceview_gettext (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);
-
-       if (tmp == NULL)
-               return g_strdup (string);
-       else
-               return tmp;
-}
+       return tmp != NULL ? tmp : g_strdup (string);
 #else
-char *
-_gtksourceview_dgettext (const char *domain,
-                         const char *string)
-{
        return g_strdup (string);
-}
 #endif
+}
diff --git a/gtksourceview/gtksourceview-i18n.h b/gtksourceview/gtksourceview-i18n.h
index be402a2..a544dfa 100644
--- a/gtksourceview/gtksourceview-i18n.h
+++ b/gtksourceview/gtksourceview-i18n.h
@@ -1,9 +1,10 @@
 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; coding: utf-8 -*- *
- * Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation
- * All rights reserved.
  *
  * This file is part of GtkSourceView
  *
+ * Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation
+ * Copyright (C) 2016 - Sébastien Wilmet <swilmet gnome org>
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
@@ -13,13 +14,13 @@
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
-
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
-/*
- * Handles all of the internationalization configuration options.
+
+/* Handles all of the internationalization configuration options.
  * Author: Tom Tromey <tromey creche cygnus com>
  */
 
@@ -35,21 +36,11 @@
 G_BEGIN_DECLS
 
 #ifdef ENABLE_NLS
-#    include <libintl.h>
-#    undef _
-#    define _(String) _gtksourceview_gettext (String)
-#    undef N_
-#    ifdef gettext_noop
-#        define N_(String) gettext_noop (String)
-#    else
-#        define N_(String) (String)
-#    endif
+#    include <glib/gi18n-lib.h>
 #    undef GD_
 #    define GD_(Domain,String) _gtksourceview_dgettext (Domain, String)
-#    undef C_
-#    define C_(Context,String) _gtksourceview_gettext (Context "\004" String)
 #else
-/* Stubs that do something close enough.  */
+/* Stubs that do something close enough. */
 #    undef textdomain
 #    define textdomain(String) (String)
 #    undef gettext
@@ -72,12 +63,10 @@ G_BEGIN_DECLS
 #    define C_(Context,String) (String)
 #endif
 
-G_GNUC_INTERNAL
-const gchar *_gtksourceview_gettext (const char *msgid) G_GNUC_FORMAT(1);
-
 /* NOTE: it returns duplicated string */
 G_GNUC_INTERNAL
-gchar *_gtksourceview_dgettext (const char *domain, const char *msgid) G_GNUC_FORMAT(2);
+gchar *                _gtksourceview_dgettext         (const gchar *domain,
+                                                const gchar *msgid) G_GNUC_FORMAT(2);
 
 G_END_DECLS
 


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