From 57a8834d7b4cd8aa552dcd7a876305b636d1b6d7 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Mon, 26 Feb 2024 12:43:30 +0000 Subject: [PATCH] girepository: Add translation support to utility tools This fixes a few formatting and newline issues in the strings at the same time, but nothing major. Signed-off-by: Philip Withnall Fixes: #3263 --- girepository/compiler/compiler.c | 46 +++++++++++++++++----------- girepository/decompiler/decompiler.c | 26 +++++++++------- girepository/inspector/inspector.c | 25 +++++++++------ po/POTFILES.in | 3 ++ 4 files changed, 61 insertions(+), 39 deletions(-) diff --git a/girepository/compiler/compiler.c b/girepository/compiler/compiler.c index ed9e3897f..aa76e3066 100644 --- a/girepository/compiler/compiler.c +++ b/girepository/compiler/compiler.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #ifdef G_OS_WIN32 @@ -89,8 +90,9 @@ write_out_typelib (gchar *prefix, if (file == NULL) { - g_fprintf (stderr, "failed to open '%s': %s\n", - tmp_filename, g_strerror (errno)); + char *message = g_strdup_printf (_("Failed to open ‘%s’: %s"), tmp_filename, g_strerror (errno)); + g_fprintf (stderr, "%s\n", message); + g_free (message); goto out; } } @@ -98,8 +100,9 @@ write_out_typelib (gchar *prefix, written = fwrite (typelib->data, 1, typelib->len, file); if (written < typelib->len) { - g_fprintf (stderr, "ERROR: Could not write the whole output: %s", - strerror (errno)); + char *message = g_strdup_printf (_("Error: Could not write the whole output: %s"), strerror (errno)); + g_fprintf (stderr, "%s\n", message); + g_free (message); goto out; } @@ -109,7 +112,11 @@ write_out_typelib (gchar *prefix, { if (!g_file_move (tmp_file_obj, file_obj, G_FILE_COPY_OVERWRITE, NULL, NULL, NULL, &error)) { - g_fprintf (stderr, "ERROR: failed to rename %s to %s: %s", tmp_filename, filename, error->message); + char *message = g_strdup_printf (_("Error: Failed to rename ‘%s’ to ‘%s’: %s"), + tmp_filename, filename, + error->message); + g_fprintf (stderr, "%s\n", message); + g_free (message); g_clear_error (&error); goto out; } @@ -137,12 +144,12 @@ log_handler (const gchar *log_domain, } static GOptionEntry options[] = { - { "includedir", 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &includedirs, "include directories in GIR search path", NULL }, - { "output", 'o', 0, G_OPTION_ARG_FILENAME, &output, "output file", "FILE" }, - { "shared-library", 'l', 0, G_OPTION_ARG_FILENAME_ARRAY, &shlibs, "shared library", "FILE" }, - { "debug", 0, 0, G_OPTION_ARG_NONE, &debug, "show debug messages", NULL }, - { "verbose", 0, 0, G_OPTION_ARG_NONE, &verbose, "show verbose messages", NULL }, - { "version", 0, 0, G_OPTION_ARG_NONE, &show_version, "show program's version number and exit", NULL }, + { "includedir", 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &includedirs, N_("Include directories in GIR search path"), NULL }, + { "output", 'o', 0, G_OPTION_ARG_FILENAME, &output, N_("Output file"), N_("FILE") }, + { "shared-library", 'l', 0, G_OPTION_ARG_FILENAME_ARRAY, &shlibs, N_("Shared library"), N_("FILE") }, + { "debug", 0, 0, G_OPTION_ARG_NONE, &debug, N_("Show debug messages"), NULL }, + { "verbose", 0, 0, G_OPTION_ARG_NONE, &verbose, N_("Show verbose messages"), NULL }, + { "version", 0, 0, G_OPTION_ARG_NONE, &show_version, N_("Show program’s version number and exit"), NULL }, { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &input, NULL, NULL }, G_OPTION_ENTRY_NULL }; @@ -164,7 +171,9 @@ main (int argc, char **argv) if (error) { - g_fprintf (stderr, "error parsing arguments: %s\n", error->message); + char *message = g_strdup_printf (_("Error parsing arguments: %s"), error->message); + g_fprintf (stderr, "%s\n", message); + g_free (message); g_error_free (error); @@ -189,14 +198,14 @@ main (int argc, char **argv) if (!input) { - g_fprintf (stderr, "no input files\n"); + g_fprintf (stderr, "%s\n", _("Please specify exactly one input file")); return 1; } if (g_strv_length (input) != 1) { - g_printerr ("Please specify only one input file\n"); + g_printerr ("%s\n", _("Please specify exactly one input file")); return 1; } @@ -211,8 +220,9 @@ main (int argc, char **argv) module = gi_ir_parser_parse_file (parser, input[0], &error); if (module == NULL) { - g_fprintf (stderr, "error parsing file %s: %s\n", - input[0], error->message); + char *message = g_strdup_printf (_("Error parsing file ‘%s’: %s"), input[0], error->message); + g_fprintf (stderr, "%s\n", message); + g_free (message); return 1; } @@ -235,9 +245,9 @@ main (int argc, char **argv) typelib = gi_ir_module_build_typelib (module); if (typelib == NULL) - g_error ("Failed to build typelib for module '%s'\n", module->name); + g_error (_("Failed to build typelib for module ‘%s’"), module->name); if (!gi_typelib_validate (typelib, &error)) - g_error ("Invalid typelib for module '%s': %s", + g_error (_("Invalid typelib for module ‘%s’: %s"), module->name, error->message); if (!write_out_typelib (NULL, typelib)) diff --git a/girepository/decompiler/decompiler.c b/girepository/decompiler/decompiler.c index dcde7d25b..51a225383 100644 --- a/girepository/decompiler/decompiler.c +++ b/girepository/decompiler/decompiler.c @@ -25,6 +25,7 @@ #include #include +#include #include #include #include @@ -47,10 +48,10 @@ main (int argc, char *argv[]) gint i; GOptionEntry options[] = { - { "output", 'o', 0, G_OPTION_ARG_FILENAME, &output, "output file", "FILE" }, - { "includedir", 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &includedirs, "include directories in GIR search path", NULL }, - { "all", 0, 0, G_OPTION_ARG_NONE, &show_all, "show all available information", NULL, }, - { "version", 0, 0, G_OPTION_ARG_NONE, &show_version, "show program's version number and exit", NULL }, + { "output", 'o', 0, G_OPTION_ARG_FILENAME, &output, N_("Output file"), N_("FILE") }, + { "includedir", 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &includedirs, N_("Include directories in GIR search path"), NULL }, + { "all", 0, 0, G_OPTION_ARG_NONE, &show_all, N_("Show all available information"), NULL, }, + { "version", 0, 0, G_OPTION_ARG_NONE, &show_version, N_("Show program’s version number and exit"), NULL }, { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &input, NULL, NULL }, G_OPTION_ENTRY_NULL }; @@ -63,7 +64,9 @@ main (int argc, char *argv[]) g_option_context_add_main_entries (context, options, NULL); if (!g_option_context_parse (context, &argc, &argv, &error)) { - g_fprintf (stderr, "failed to parse: %s\n", error->message); + char *message = g_strdup_printf (_("Failed to parse: %s"), error->message); + g_fprintf (stderr, "%s\n", message); + g_free (message); g_error_free (error); return 1; } @@ -77,7 +80,7 @@ main (int argc, char *argv[]) if (!input) { - g_fprintf (stderr, "no input files\n"); + g_fprintf (stderr, "%s\n", _("No input files")); return 1; } @@ -103,7 +106,7 @@ main (int argc, char *argv[]) error = NULL; mfile = g_mapped_file_new (input[i], FALSE, &error); if (!mfile) - g_error ("failed to read '%s': %s", input[i], error->message); + g_error (_("Failed to read ‘%s’: %s"), input[i], error->message); bytes = g_mapped_file_get_bytes (mfile); g_clear_pointer (&mfile, g_mapped_file_unref); @@ -115,19 +118,20 @@ main (int argc, char *argv[]) typelib = gi_typelib_new_from_bytes (bytes, &error); if (!typelib) - g_error ("failed to create typelib '%s': %s", input[i], error->message); + g_error (_("Failed to create typelib ‘%s’: %s"), input[i], error->message); namespace = gi_repository_load_typelib (repository, typelib, 0, &error); if (namespace == NULL) - g_error ("failed to load typelib: %s", error->message); + g_error (_("Failed to load typelib: %s"), error->message); gi_ir_writer_write (repository, output, namespace, needs_prefix, show_all); /* when writing to stdout, stop after the first module */ if (input[i + 1] && !output) { - g_fprintf (stderr, "warning, %d modules omitted\n", - g_strv_length (input) - 1); + char *message = g_strdup_printf (_("Warning: %u modules omitted"), g_strv_length (input) - 1); + g_fprintf (stderr, "%s\n", message); + g_free (message); break; } diff --git a/girepository/inspector/inspector.c b/girepository/inspector/inspector.c index 088bee4c2..9d94e0d9d 100644 --- a/girepository/inspector/inspector.c +++ b/girepository/inspector/inspector.c @@ -22,6 +22,7 @@ */ #include +#include #include #include #include @@ -68,36 +69,38 @@ main (gint argc, GStrv namespaces = NULL; const gchar *namespace = NULL; const GOptionEntry options[] = { - { "typelib-version", 0, 0, G_OPTION_ARG_STRING, &version, "Typelib version to inspect", "VERSION" }, - { "print-shlibs", 0, 0, G_OPTION_ARG_NONE, &opt_shlibs, "List the shared libraries the typelib requires", NULL }, - { "print-typelibs", 0, 0, G_OPTION_ARG_NONE, &opt_typelibs, "List other typelibs the inspected typelib requires", NULL }, - { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &namespaces, "The typelib to inspect", "NAMESPACE" }, + { "typelib-version", 0, 0, G_OPTION_ARG_STRING, &version, N_("Typelib version to inspect"), N_("VERSION") }, + { "print-shlibs", 0, 0, G_OPTION_ARG_NONE, &opt_shlibs, N_("List the shared libraries the typelib requires"), NULL }, + { "print-typelibs", 0, 0, G_OPTION_ARG_NONE, &opt_typelibs, N_("List other typelibs the inspected typelib requires"), NULL }, + { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &namespaces, N_("The typelib to inspect"), N_("NAMESPACE") }, G_OPTION_ENTRY_NULL }; GOptionContext *context = NULL; setlocale (LC_ALL, ""); - context = g_option_context_new ("- Inspect GI typelib"); + context = g_option_context_new (_("- Inspect GI typelib")); g_option_context_add_main_entries (context, options, NULL); if (!g_option_context_parse (context, &argc, &argv, &error)) { + char *message = g_strdup_printf (_("Failed to parse command line options: %s"), error->message); status = EXIT_FAILURE; - g_printerr ("Failed to parse command line options: %s\n", error->message); + g_printerr ("%s\n", message); + g_free (message); goto out; } if (!namespaces) { status = EXIT_FAILURE; - g_printerr ("Please specify at least one namespace\n"); + g_printerr ("%s\n", _("Please specify exactly one namespace")); goto out; } if (g_strv_length (namespaces) > 1) { status = EXIT_FAILURE; - g_printerr ("Please specify only one namespace\n"); + g_printerr ("%s\n", _("Please specify exactly one namespace")); goto out; } namespace = namespaces[0]; @@ -105,7 +108,7 @@ main (gint argc, if (!opt_shlibs && !opt_typelibs) { status = EXIT_FAILURE; - g_printerr ("Please specify --print-shlibs, --print-typelibs or both.\n"); + g_printerr ("%s\n", _("Please specify --print-shlibs, --print-typelibs or both")); goto out; } @@ -113,8 +116,10 @@ main (gint argc, typelib = gi_repository_require (repository, namespace, version, 0, &error); if (!typelib) { + char *message = g_strdup_printf (_("Failed to load typelib: %s"), error->message); status = EXIT_FAILURE; - g_printerr ("Failed to load typelib: %s\n", error->message); + g_printerr ("%s\n", message); + g_free (message); goto out; } diff --git a/po/POTFILES.in b/po/POTFILES.in index 9a4cdf35c..0712c0ac2 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -181,6 +181,9 @@ gio/gzlibcompressor.c gio/gzlibdecompressor.c gio/tests/gdbus-daemon.c gio/win32/gwinhttpfile.c +girepository/compiler/compiler.c +girepository/decompiler/decompiler.c +girepository/inspector/inspector.c glib/gatomic.c glib/gbookmarkfile.c glib/gconvert.c