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 <pwithnall@gnome.org>

Fixes: #3263
This commit is contained in:
Philip Withnall
2024-02-26 12:43:30 +00:00
parent 5b022f903c
commit 57a8834d7b
4 changed files with 61 additions and 39 deletions

View File

@@ -22,6 +22,7 @@
*/
#include <glib.h>
#include <glib/gi18n.h>
#include <girepository.h>
#include <stdlib.h>
#include <locale.h>
@@ -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;
}