aboutsummaryrefslogtreecommitdiff
path: root/hardinfo
diff options
context:
space:
mode:
authorJulien Lavergne <gilir@ubuntu.com>2013-01-05 16:18:38 +0100
committerLeandro Pereira <leandro@hardinfo.org>2014-01-03 08:02:30 -0200
commiteb77158796dbf5f3ce395f5b85a2d0f78038fa00 (patch)
treefd3e5bc8281922378b388020f662871aeb60d805 /hardinfo
parentba24b32ccaaf44f683ffe35cd4ac4ddf61c8da06 (diff)
Add initial translation support (patch from rodin.s)
Diffstat (limited to 'hardinfo')
-rw-r--r--hardinfo/hardinfo.c26
-rw-r--r--hardinfo/util.c71
2 files changed, 48 insertions, 49 deletions
diff --git a/hardinfo/hardinfo.c b/hardinfo/hardinfo.c
index ffe35920..8218df14 100644
--- a/hardinfo/hardinfo.c
+++ b/hardinfo/hardinfo.c
@@ -32,6 +32,10 @@ ProgramParameters params = { 0 };
int main(int argc, char **argv)
{
+ setlocale( LC_ALL, "" );
+ bindtextdomain( "hardinfo", "/usr/share/locale" );
+ textdomain( "hardinfo" );
+
GSList *modules;
DEBUG("HardInfo version " VERSION ". Debug version.");
@@ -47,16 +51,16 @@ int main(int argc, char **argv)
if (params.show_version) {
g_print("HardInfo version " VERSION "\n");
g_print
- ("Copyright (C) 2003-2009 Leandro A. F. Pereira. See COPYING for details.\n\n");
+ (_("Copyright (C) 2003-2009 Leandro A. F. Pereira. See COPYING for details.\n\n"));
- g_print("Compile-time options:\n"
+ g_print(_("Compile-time options:\n"
" Release version: %s (%s)\n"
" BinReloc enabled: %s\n"
" Data prefix: %s\n"
" Library prefix: %s\n"
- " Compiled on: %s %s (%s)\n",
- RELEASE ? "Yes" : "No (" VERSION ")", ARCH,
- ENABLE_BINRELOC ? "Yes" : "No",
+ " Compiled on: %s %s (%s)\n"),
+ RELEASE ? _("Yes") : "No (" VERSION ")", ARCH,
+ ENABLE_BINRELOC ? _("Yes") : _("No"),
PREFIX, LIBPREFIX, PLATFORM, KERNEL, HOSTNAME);
DEBUG(" Debugging is enabled.");
@@ -67,15 +71,15 @@ int main(int argc, char **argv)
/* initialize the binreloc library, so we can load program data */
if (!binreloc_init(FALSE))
- g_error("Failed to find runtime data.\n\n"
+ g_error(_("Failed to find runtime data.\n\n"
"\342\200\242 Is HardInfo correctly installed?\n"
- "\342\200\242 See if %s and %s exists and you have read permision.",
+ "\342\200\242 See if %s and %s exists and you have read permision."),
PREFIX, LIBPREFIX);
/* list all module names */
if (params.list_modules) {
- g_print("Modules:\n"
- "%-20s%-15s%-12s\n", "File Name", "Name", "Version");
+ g_print(_("Modules:\n"
+ "%-20s%-15s%-12s\n"), _("File Name"), _("Name"), _("Version"));
for (modules = modules_load_all(); modules;
modules = modules->next) {
@@ -128,7 +132,7 @@ int main(int argc, char **argv)
result = module_call_method_param("benchmark::runBenchmark", params.run_benchmark);
if (!result) {
- g_error("Unknown benchmark ``%s'' or libbenchmark.so not loaded", params.run_benchmark);
+ g_error(_("Unknown benchmark ``%s'' or libbenchmark.so not loaded"), params.run_benchmark);
} else {
g_print("%s\n", result);
g_free(result);
@@ -156,7 +160,7 @@ int main(int argc, char **argv)
g_free(report);
} else {
- g_error("Don't know what to do. Exiting.");
+ g_error(_("Don't know what to do. Exiting."));
}
moreinfo_shutdown();
diff --git a/hardinfo/util.c b/hardinfo/util.c
index 3c083b34..e94d215a 100644
--- a/hardinfo/util.c
+++ b/hardinfo/util.c
@@ -96,35 +96,30 @@ gchar *seconds_to_string(unsigned int seconds)
days = hours / 24;
hours %= 24;
-#define plural(x) ((x > 1) ? "s" : "")
if (days < 1) {
if (hours < 1) {
- return g_strdup_printf("%d minute%s", minutes,
- plural(minutes));
+ return g_strdup_printf(ngettext("%d minute","%d minutes",minutes),minutes);
} else {
- return g_strdup_printf("%d hour%s, %d minute%s",
- hours,
- plural(hours), minutes,
- plural(minutes));
+ return g_strdup_printf(ngettext("%d hour, ","%d hours, ",hours),hours,
+ ngettext("%d minute","%d minutes",minutes),minutes);
}
}
-
- return g_strdup_printf("%d day%s, %d hour%s and %d minute%s",
- days, plural(days), hours,
- plural(hours), minutes, plural(minutes));
+ return g_strdup_printf(ngettext("%d day, ","%d days, ",days),days,
+ ngettext("%d hour and ","%d hours and ",hours),hours,
+ ngettext("%d minute","%d minutes",minutes),minutes);
}
inline gchar *size_human_readable(gfloat size)
{
if (size < KiB)
- return g_strdup_printf("%.1f B", size);
+ return g_strdup_printf(_("%.1f B"), size);
if (size < MiB)
- return g_strdup_printf("%.1f KiB", size / KiB);
+ return g_strdup_printf(_("%.1f KiB"), size / KiB);
if (size < GiB)
- return g_strdup_printf("%.1f MiB", size / MiB);
+ return g_strdup_printf(_("%.1f MiB"), size / MiB);
- return g_strdup_printf("%.1f GiB", size / GiB);
+ return g_strdup_printf(_("%.1f GiB"), size / GiB);
}
inline char *strend(gchar * str, gchar chr)
@@ -338,7 +333,7 @@ log_handler(const gchar * log_domain,
if (!params.gui_running) {
/* No GUI running: spit the message to the terminal */
g_print("\n\n*** %s: %s\n\n",
- (log_level & G_LOG_FLAG_FATAL) ? "Error" : "Warning",
+ (log_level & G_LOG_FLAG_FATAL) ? _("Error") : _("Warning"),
message);
} else {
/* Hooray! We have a GUI running! */
@@ -353,8 +348,8 @@ log_handler(const gchar * log_domain,
"<big><b>%s</b></big>\n\n%s",
(log_level &
G_LOG_FLAG_FATAL) ?
- "Fatal Error" :
- "Warning", message);
+ _("Fatal Error") :
+ _("Warning"), message);
gtk_dialog_run(GTK_DIALOG(dialog));
gtk_widget_destroy(dialog);
@@ -378,56 +373,56 @@ void parameters_init(int *argc, char ***argv, ProgramParameters * param)
.short_name = 'r',
.arg = G_OPTION_ARG_NONE,
.arg_data = &create_report,
- .description = "creates a report and prints to standard output"},
+ .description = N_("creates a report and prints to standard output")},
{
.long_name = "report-format",
.short_name = 'f',
.arg = G_OPTION_ARG_STRING,
.arg_data = &report_format,
- .description = "chooses a report format (text, html)"},
+ .description = N_("chooses a report format (text, html)")},
{
.long_name = "run-benchmark",
.short_name = 'b',
.arg = G_OPTION_ARG_STRING,
.arg_data = &run_benchmark,
- .description = "run benchmark; requires benchmark.so to be loaded"},
+ .description = N_("run benchmark; requires benchmark.so to be loaded")},
{
.long_name = "list-modules",
.short_name = 'l',
.arg = G_OPTION_ARG_NONE,
.arg_data = &list_modules,
- .description = "lists modules"},
+ .description = N_("lists modules")},
{
.long_name = "load-module",
.short_name = 'm',
.arg = G_OPTION_ARG_STRING_ARRAY,
.arg_data = &use_modules,
- .description = "specify module to load"},
+ .description = N_("specify module to load")},
{
.long_name = "autoload-deps",
.short_name = 'a',
.arg = G_OPTION_ARG_NONE,
.arg_data = &autoload_deps,
- .description = "automatically load module dependencies"},
+ .description = N_("automatically load module dependencies")},
#ifdef HAS_LIBSOUP
{
.long_name = "xmlrpc-server",
.short_name = 'x',
.arg = G_OPTION_ARG_NONE,
.arg_data = &run_xmlrpc_server,
- .description = "run in XML-RPC server mode"},
+ .description = N_("run in XML-RPC server mode")},
#endif /* HAS_LIBSOUP */
{
.long_name = "version",
.short_name = 'v',
.arg = G_OPTION_ARG_NONE,
.arg_data = &show_version,
- .description = "shows program version and quit"},
+ .description = N_("shows program version and quit")},
{NULL}
};
GOptionContext *ctx;
- ctx = g_option_context_new("- System Profiler and Benchmark tool");
+ ctx = g_option_context_new(_("- System Profiler and Benchmark tool"));
g_option_context_set_ignore_unknown_options(ctx, FALSE);
g_option_context_set_help_enabled(ctx, TRUE);
@@ -437,8 +432,8 @@ void parameters_init(int *argc, char ***argv, ProgramParameters * param)
g_option_context_free(ctx);
if (*argc >= 2) {
- g_print("Unrecognized arguments.\n"
- "Try ``%s --help'' for more information.\n", *(argv)[0]);
+ g_print(_("Unrecognized arguments.\n"
+ "Try ``%s --help'' for more information.\n"), *(argv)[0]);
exit(1);
}
@@ -503,7 +498,7 @@ void open_url(gchar * url)
browser = (gchar *)browsers[i++];
} while (browser);
- g_warning("Couldn't find a Web browser to open URL %s.", url);
+ g_warning(_("Couldn't find a Web browser to open URL %s."), url);
}
/* Copyright: Jens Låås, SLU 2002 */
@@ -733,7 +728,7 @@ static ShellModule *module_load(gchar * filename)
g_module_symbol(module->dll, "hi_note_func",
(gpointer) & (entry->notefunc));
- entry->name = entries[i].name;
+ entry->name = _(entries[i].name); //gettext unname N_() in computer.c line 67 etc...
entry->scan_func = entries[i].scan_callback;
entry->func = entries[i].callback;
entry->number = i;
@@ -850,7 +845,7 @@ static GSList *modules_check_deps(GSList * modules)
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_QUESTION,
GTK_BUTTONS_NONE,
- "Module \"%s\" depends on module \"%s\", load it?",
+ _("Module \"%s\" depends on module \"%s\", load it?"),
module->name,
deps[i]);
gtk_dialog_add_buttons(GTK_DIALOG(dialog),
@@ -873,7 +868,7 @@ static GSList *modules_check_deps(GSList * modules)
gtk_widget_destroy(dialog);
} else {
- g_error("Module \"%s\" depends on module \"%s\".",
+ g_error(_("Module \"%s\" depends on module \"%s\"."),
module->name, deps[i]);
}
}
@@ -918,12 +913,12 @@ static GSList *modules_load(gchar ** module_list)
if (g_slist_length(modules) == 0) {
if (params.use_modules == NULL) {
g_error
- ("No module could be loaded. Check permissions on \"%s\" and try again.",
+ (_("No module could be loaded. Check permissions on \"%s\" and try again."),
params.path_lib);
} else {
g_error
- ("No module could be loaded. Please use hardinfo -l to list all avai"
- "lable modules and try again with a valid module list.");
+ (_("No module could be loaded. Please use hardinfo -l to list all avai"
+ "lable modules and try again with a valid module list."));
}
}
@@ -1098,7 +1093,7 @@ void module_entry_scan_all_except(ModuleEntry * entries, gint except_entry)
if (i == except_entry)
continue;
- text = g_strdup_printf("Scanning: %s...", entry.name);
+ text = g_strdup_printf(_("Scanning: %s..."), _(entry.name));
shell_status_update(text);
g_free(text);
@@ -1108,7 +1103,7 @@ void module_entry_scan_all_except(ModuleEntry * entries, gint except_entry)
}
shell_view_set_enabled(TRUE);
- shell_status_update("Done.");
+ shell_status_update(_("Done."));
}
void module_entry_scan_all(ModuleEntry * entries)