gtk4-builder-tool: Localization fixes
authorMatthias Clasen <mclasen@redhat.com>
Sat, 18 Mar 2023 02:04:25 +0000 (22:04 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Sat, 18 Mar 2023 02:04:25 +0000 (22:04 -0400)
Be consistent about marking strings for
translation. And make locatization actually
work by including gi18n-lib.h instead of gi18n.h.

tools/gtk-builder-tool-enumerate.c
tools/gtk-builder-tool-preview.c
tools/gtk-builder-tool-screenshot.c
tools/gtk-builder-tool-simplify.c
tools/gtk-builder-tool-validate.c
tools/gtk-builder-tool.c

index 81c4cfc5552395a7e023c56b2544d31194dc8e56..12db2604720d3288a279ea28cfcde08e1739d57d 100644 (file)
@@ -23,7 +23,7 @@
 #include <string.h>
 #include <errno.h>
 
-#include <glib/gi18n.h>
+#include <glib/gi18n-lib.h>
 #include <glib/gprintf.h>
 #include <glib/gstdio.h>
 #include <gtk/gtk.h>
index 6c7473d80e01ee5d8384d862af4fbffd24a879a7..43fa2ff5b2c7c45566e552fee44b766be5a512ab 100644 (file)
@@ -23,7 +23,7 @@
 #include <string.h>
 #include <errno.h>
 
-#include <glib/gi18n.h>
+#include <glib/gi18n-lib.h>
 #include <glib/gprintf.h>
 #include <glib/gstdio.h>
 #include <gtk/gtk.h>
@@ -125,15 +125,15 @@ preview_file (const char *filename,
   if (object == NULL)
     {
       if (id)
-        g_printerr ("No object with ID '%s' found\n", id);
+        g_printerr (_("No object with ID '%s' found\n"), id);
       else
-        g_printerr ("No previewable object found\n");
+        g_printerr (_("No previewable object found\n"));
       exit (1);
     }
 
   if (!GTK_IS_WIDGET (object))
     {
-      g_printerr ("Objects of type %s can't be previewed\n", G_OBJECT_TYPE_NAME (object));
+      g_printerr (_("Objects of type %s can't be previewed\n"), G_OBJECT_TYPE_NAME (object));
       exit (1);
     }
 
@@ -184,7 +184,7 @@ do_preview (int          *argc,
 
   if (gdk_display_get_default () == NULL)
     {
-      g_printerr ("Could not initialize windowing system\n");
+      g_printerr (_("Could not initialize windowing system\n"));
       exit (1);
     }
 
@@ -205,13 +205,13 @@ do_preview (int          *argc,
 
   if (filenames == NULL)
     {
-      g_printerr ("No .ui file specified\n");
+      g_printerr (_("No .ui file specified\n"));
       exit (1);
     }
 
   if (g_strv_length (filenames) > 1)
     {
-      g_printerr ("Can only preview a single .ui file\n");
+      g_printerr (_("Can only preview a single .ui file\n"));
       exit (1);
     }
 
index 99e033ef68286b04a28cbeda95a8f5a5d037fd5d..cf20eaec8849c6294ffea9b585c533733f7e346a 100644 (file)
@@ -23,7 +23,7 @@
 #include <string.h>
 #include <errno.h>
 
-#include <glib/gi18n.h>
+#include <glib/gi18n-lib.h>
 #include <glib/gprintf.h>
 #include <glib/gstdio.h>
 #include <gtk/gtk.h>
@@ -233,15 +233,15 @@ screenshot_file (const char *filename,
   if (object == NULL)
     {
       if (id)
-        g_printerr ("No object with ID '%s' found\n", id);
+        g_printerr (_("No object with ID '%s' found\n"), id);
       else
-        g_printerr ("No object found\n");
+        g_printerr (_("No object found\n"));
       exit (1);
     }
 
   if (!GTK_IS_WIDGET (object))
     {
-      g_printerr ("Objects of type %s can't be screenshot\n", G_OBJECT_TYPE_NAME (object));
+      g_printerr (_("Objects of type %s can't be screenshot\n"), G_OBJECT_TYPE_NAME (object));
       exit (1);
     }
 
@@ -295,7 +295,7 @@ screenshot_file (const char *filename,
 
   if (texture == NULL)
     {
-      g_printerr ("Failed to take a screenshot\n");
+      g_printerr (_("Failed to take a screenshot\n"));
       exit (1);
     }
 
@@ -306,8 +306,8 @@ screenshot_file (const char *filename,
 
   if (g_file_test (save_to, G_FILE_TEST_EXISTS) && !force)
     {
-      g_printerr ("File %s exists.\n"
-                  "Use --force to overwrite.\n", save_to);
+      g_printerr (_("File %s exists.\n"
+                    "Use --force to overwrite.\n"), save_to);
       exit (1);
     }
 
@@ -328,11 +328,11 @@ screenshot_file (const char *filename,
                            g_bytes_get_size (bytes),
                            &error))
     {
-      g_print ("Output written to %s.\n", save_to);
+      g_print (_("Output written to %s.\n"), save_to);
     }
   else
     {
-      g_printerr ("Failed to save %s: %s\n", save_to, error->message);
+      g_printerr (_("Failed to save %s: %s\n"), save_to, error->message);
       exit (1);
     }
 
@@ -366,7 +366,7 @@ do_screenshot (int          *argc,
 
   if (gdk_display_get_default () == NULL)
     {
-      g_printerr ("Could not initialize windowing system\n");
+      g_printerr (_("Could not initialize windowing system\n"));
       exit (1);
     }
 
@@ -387,13 +387,13 @@ do_screenshot (int          *argc,
 
   if (filenames == NULL)
     {
-      g_printerr ("No .ui file specified\n");
+      g_printerr (_("No .ui file specified\n"));
       exit (1);
     }
 
   if (g_strv_length (filenames) > 2)
     {
-      g_printerr ("Can only screenshot a single .ui file and a single output file\n");
+      g_printerr (_("Can only screenshot a single .ui file and a single output file\n"));
       exit (1);
     }
 
index d279aa526fe0a735ea30addd15d5fb7b6a91eed5..3a8ecf3b903880aa80ba95c83d122331f71b2966 100644 (file)
@@ -23,7 +23,7 @@
 #include <string.h>
 #include <errno.h>
 
-#include <glib/gi18n.h>
+#include <glib/gi18n-lib.h>
 #include <glib/gprintf.h>
 #include <glib/gstdio.h>
 #include <gtk/gtk.h>
@@ -648,10 +648,31 @@ warn_missing_property (Element      *element,
                        const char   *property_name,
                        PropKind      kind)
 {
-  const char *kind_str[] = { "", "Packing ", "Cell ", "Layout " };
+  char *name;
+  char *msg;
 
-  g_printerr (_("%s:%d: %sproperty %s::%s not found\n"),
-              data->input_filename, element->line_number, kind_str[kind], class_name, property_name);
+  name = g_strconcat (class_name, "::", property_name, NULL);
+  switch (kind)
+    {
+    case PROP_KIND_OBJECT:
+      msg = g_strdup_printf (_("Property %s not found"), name);
+      break;
+    case PROP_KIND_PACKING:
+      msg = g_strdup_printf (_("Packing property %s not found"), name);
+      break;
+    case PROP_KIND_CELL_PACKING:
+      msg = g_strdup_printf (_("Cell property %s not found"), name);
+      break;
+    case PROP_KIND_LAYOUT:
+      msg = g_strdup_printf (_("Layout property %s not found"), name);
+      break;
+    default:
+      g_assert_not_reached ();
+    }
+
+  g_printerr ("%s:%d: %s\n", data->input_filename, element->line_number, msg);
+  g_free (name);
+  g_free (msg);
 }
 
 static gboolean
@@ -1373,7 +1394,7 @@ rewrite_start_center_end_children (Element      *element,
       else if (end_child == NULL)
         end_child = child;
       else
-        g_warning ("%s only accepts three children", get_class_name (element));
+        g_warning (_("%s only accepts three children"), get_class_name (element));
     }
 
   if (start_child)
@@ -2454,7 +2475,7 @@ simplify_file (const char *filename,
 
   if (data.root == NULL)
     {
-      g_printerr (_("Can’t parse “%s”\n"), filename);
+      g_printerr (_("Can’t parse “%s”: %s\n"), filename, "");
       return FALSE;
     }
 
@@ -2486,7 +2507,7 @@ simplify_file (const char *filename,
 
       if (!g_file_set_contents (data.input_filename, content, length, &error))
         {
-          g_printerr (_("Failed to write %s: “%s”\n"), data.input_filename, error->message);
+          g_printerr (_("Failed to write “%s”: “%s”\n"), data.input_filename, error->message);
           return FALSE;
         }
     }
index db94242dffacaa9ebaf2a8c94c8ad6091bdba0d6..011b8b8d79f2b568aeb971e11cb60e10e62ad8a8 100644 (file)
@@ -23,7 +23,7 @@
 #include <string.h>
 #include <errno.h>
 
-#include <glib/gi18n.h>
+#include <glib/gi18n-lib.h>
 #include <glib/gprintf.h>
 #include <glib/gstdio.h>
 #include <gtk/gtk.h>
@@ -42,7 +42,7 @@ make_fake_type (const char *type_name,
   parent_type = g_type_from_name (parent_name);
   if (parent_type == G_TYPE_INVALID)
     {
-      g_printerr ("Failed to lookup template parent type %s\n", parent_name);
+      g_printerr (_("Failed to lookup template parent type %s\n"), parent_name);
       exit (1);
     }
 
@@ -120,7 +120,7 @@ fake_scope_check_deprecations (FakeScope  *self,
       if (is_deprecated (name))
         {
           if (s->len == 0)
-            g_string_append (s, "Deprecated types:\n");
+            g_string_append (s, _("Deprecated types:\n"));
           g_string_append_printf (s, "%s", name);
           g_string_append (s, "\n");
         }
@@ -164,7 +164,7 @@ validate_template (const char *filename,
   object = g_object_new (template_type, NULL);
   if (!object)
     {
-      g_printerr ("Failed to create an instance of the template type %s\n", type_name);
+      g_printerr (_("Failed to create an instance of the template type %s\n"), type_name);
       return FALSE;
     }
 
@@ -276,6 +276,12 @@ do_validate (int *argc, const char ***argv)
       exit (1);
     }
 
+  if (!filenames)
+    {
+      g_printerr (_("No .ui file specified\n"));
+      exit (1);
+    }
+
   g_option_context_free (context);
 
   for (i = 0; filenames[i]; i++)
index 278d3fb4db0ef3b1b503c8e2b2be046047d20534..a17af70b893151978e4d8980a8e9b3a464c7b220 100644 (file)
@@ -23,7 +23,7 @@
 #include <string.h>
 #include <errno.h>
 
-#include <glib/gi18n.h>
+#include <glib/gi18n-lib.h>
 #include <glib/gprintf.h>
 #include <glib/gstdio.h>
 #include <gtk/gtk.h>