Merge branch 'girepository-tool-translation' into 'main'

girepository: Add translation support to utility tools

Closes #3263

See merge request GNOME/glib!3941
This commit is contained in:
Marco Trevisan 2024-02-27 09:41:03 +00:00
commit 972db82a8e
4 changed files with 61 additions and 51 deletions

View File

@ -29,6 +29,7 @@
#include <gio/gio.h>
#include <girepository.h>
#include <glib.h>
#include <glib/gi18n.h>
#include <glib/gstdio.h>
#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"), g_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 programs 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);
@ -187,19 +196,13 @@ main (int argc, char **argv)
return 0;
}
if (!input)
if (!input || g_strv_length (input) != 1)
{
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");
return 1;
}
g_debug ("[parsing] start, %d includes",
includedirs ? g_strv_length (includedirs) : 0);
@ -211,8 +214,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 +239,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))

View File

@ -25,6 +25,7 @@
#include <locale.h>
#include <glib.h>
#include <glib/gi18n.h>
#include <glib/gstdio.h>
#include <gmodule.h>
#include <girepository.h>
@ -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 programs 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;
}

View File

@ -22,6 +22,7 @@
*/
#include <glib.h>
#include <glib/gi18n.h>
#include <girepository.h>
#include <stdlib.h>
#include <locale.h>
@ -68,44 +69,40 @@ 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)
if (!namespaces || g_strv_length (namespaces) > 1)
{
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");
goto out;
}
namespace = namespaces[0];
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 +110,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;
}

View File

@ -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