Advertisement
Guest User

i18n patch

a guest
Mar 2nd, 2011
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 10.78 KB | None | 0 0
  1. diff -Naur /home/max/123/src/hardinfo//hardinfo/hardinfo.c /home/max/123/hardinfo/hardinfo/hardinfo.c
  2. --- /home/max/123/src/hardinfo//hardinfo/hardinfo.c 2011-03-02 20:22:17.000000000 +0300
  3. +++ /home/max/123/hardinfo/hardinfo/hardinfo.c  2011-03-02 21:56:53.000000000 +0300
  4. @@ -32,8 +32,13 @@
  5.  
  6.  int main(int argc, char **argv)
  7.  {
  8. +    /* gettext init */
  9. +    bindtextdomain ("hardinfo", LOCALEDIR);
  10. +    textdomain ("hardinfo");
  11. +
  12.      GSList *modules;
  13.  
  14. +
  15.      DEBUG("HardInfo version " VERSION ". Debug version.");
  16.  
  17.      DEBUG("g_thread_init()");
  18. @@ -45,21 +50,21 @@
  19.  
  20.      /* show version information and quit */
  21.      if (params.show_version) {
  22. -   g_print("HardInfo version " VERSION "\n");
  23. +   g_print(_("HardInfo version ") VERSION "\n");
  24.     g_print
  25. -       ("Copyright (C) 2003-2009 Leandro A. F. Pereira. See COPYING for details.\n\n");
  26. +       (_("Copyright (C) 2003-2009 Leandro A. F. Pereira. See COPYING for details.\n\n"));
  27.  
  28. -   g_print("Compile-time options:\n"
  29. -       "  Release version:   %s (%s)\n"
  30. -       "  BinReloc enabled:  %s\n"
  31. -       "  Data prefix:       %s\n"
  32. -       "  Library prefix:    %s\n"
  33. -       "  Compiled on:       %s %s (%s)\n",
  34. -       RELEASE ? "Yes" : "No (" VERSION ")", ARCH,
  35. -       ENABLE_BINRELOC ? "Yes" : "No",
  36. +   g_print(_("Compile-time options:\n")
  37. +       _("  Release version:   %s (%s)\n")
  38. +       _("  BinReloc enabled:  %s\n")
  39. +       _("  Data prefix:       %s\n")
  40. +       _("  Library prefix:    %s\n")
  41. +       _("  Compiled on:       %s %s (%s)\n"),
  42. +       RELEASE ? _("Yes") : "No (" VERSION ")"), ARCH,
  43. +       ENABLE_BINRELOC ? _("Yes") : _("No"),
  44.         PREFIX, LIBPREFIX, PLATFORM, KERNEL, HOSTNAME);
  45.  
  46. -   DEBUG("  Debugging is enabled.");
  47. +   DEBUG(_("  Debugging is enabled."));
  48.  
  49.     /* show also available modules */
  50.     params.list_modules = TRUE;
  51. @@ -67,15 +72,15 @@
  52.  
  53.      /* initialize the binreloc library, so we can load program data */
  54.      if (!binreloc_init(FALSE))
  55. -   g_error("Failed to find runtime data.\n\n"
  56. -       "\342\200\242 Is HardInfo correctly installed?\n"
  57. -       "\342\200\242 See if %s and %s exists and you have read permision.",
  58. +   g_error(N_("Failed to find runtime data.\n\n")
  59. +       N_("\342\200\242 Is HardInfo correctly installed?\n")
  60. +       N_("\342\200\242 See if %s and %s exists and you have read permision."),
  61.         PREFIX, LIBPREFIX);
  62.  
  63.      /* list all module names */
  64.      if (params.list_modules) {
  65. -   g_print("Modules:\n"
  66. -       "%-20s%-15s%-12s\n", "File Name", "Name", "Version");
  67. +   g_print(_("Modules:\n")
  68. +       "%-20s%-15s%-12s\n", _("File Name"), _("Name"), _("Version"));
  69.  
  70.     for (modules = modules_load_all(); modules;
  71.          modules = modules->next) {
  72. @@ -125,7 +130,7 @@
  73.          
  74.          result = module_call_method_param("benchmark::runBenchmark", params.run_benchmark);
  75.          if (!result) {
  76. -          g_error("Unknown benchmark ``%s'' or libbenchmark.so not loaded", params.run_benchmark);
  77. +          g_error(_("Unknown benchmark ``%s'' or libbenchmark.so not loaded"), params.run_benchmark);
  78.          } else {
  79.            g_print("%s\n", result);
  80.            g_free(result);
  81. @@ -153,7 +158,7 @@
  82.  
  83.     g_free(report);
  84.      } else {
  85. -        g_error("Don't know what to do. Exiting.");
  86. +        g_error(_("Don't know what to do. Exiting."));
  87.      }
  88.  
  89.      DEBUG("finished");
  90. diff -Naur /home/max/123/src/hardinfo//hardinfo/util.c /home/max/123/hardinfo/hardinfo/util.c
  91. --- /home/max/123/src/hardinfo//hardinfo/util.c 2011-03-02 20:22:17.000000000 +0300
  92. +++ /home/max/123/hardinfo/hardinfo/util.c  2011-03-02 22:29:17.000000000 +0300
  93. @@ -95,36 +95,36 @@
  94.      minutes %= 60;
  95.      days = hours / 24;
  96.      hours %= 24;
  97. -
  98. -#define plural(x) ((x > 1) ? "s" : "")
  99. +/*
  100. +* little fuzzy here. if you know how to fix this, ...;
  101. +* http://www.gnu.org/software/hello/manual/gettext/Plural-forms.html
  102. +*/
  103.  
  104.      if (days < 1) {
  105.     if (hours < 1) {
  106. -       return g_strdup_printf("%d minute%s", minutes,
  107. -                  plural(minutes));
  108. +       return g_strdup_printf(ngettext("%d minute","%d minutes",minutes),minutes);
  109.     } else {
  110. -       return g_strdup_printf("%d hour%s, %d minute%s",
  111. -                  hours,
  112. -                  plural(hours), minutes,
  113. -                  plural(minutes));
  114. +       return g_strdup_printf(ngettext("%d hour, ","%d hours, ",hours),hours,
  115. +                   ngettext("%d minute","%d minutes",minutes),minutes);
  116.     }
  117.      }
  118.  
  119. -    return g_strdup_printf("%d day%s, %d hour%s and %d minute%s",
  120. -              days, plural(days), hours,
  121. -              plural(hours), minutes, plural(minutes));
  122. +    return g_strdup_printf(ngettext("%d day, ","%d days, ",days),
  123. +              ngettext("%d hour and ","%d hours and ",hours)              
  124. +              ngettext("%d minute","%d hours",hours),
  125. +)
  126.  }
  127.  
  128.  inline gchar *size_human_readable(gfloat size)
  129.  {
  130.      if (size < KiB)
  131. -   return g_strdup_printf("%.1f B", size);
  132. +   return g_strdup_printf(_("%.1f B"), size);
  133.      if (size < MiB)
  134. -   return g_strdup_printf("%.1f KiB", size / KiB);
  135. +   return g_strdup_printf(_("%.1f KiB"), size / KiB);
  136.      if (size < GiB)
  137. -   return g_strdup_printf("%.1f MiB", size / MiB);
  138. +   return g_strdup_printf(_("%.1f MiB"), size / MiB);
  139.  
  140. -    return g_strdup_printf("%.1f GiB", size / GiB);
  141. +    return g_strdup_printf(_("%.1f GiB"), size / GiB);
  142.  }
  143.  
  144.  inline char *strend(gchar * str, gchar chr)
  145. @@ -279,8 +279,7 @@
  146.         g_error_free(error);
  147.     }
  148.  
  149. -   DEBUG("%strying hardcoded paths.",
  150. -         try_hardcoded ? "" : "binreloc init failed. ");
  151. +   DEBUG("%strying hardcoded paths.", try_hardcoded ? "" : "binreloc init failed. ");
  152.      } else {
  153.     /* If we were able to initialize BinReloc, build the default data
  154.        and library paths. */
  155. @@ -338,7 +337,7 @@
  156.      if (!params.gui_running) {
  157.     /* No GUI running: spit the message to the terminal */
  158.     g_print("\n\n*** %s: %s\n\n",
  159. -       (log_level & G_LOG_FLAG_FATAL) ? "Error" : "Warning",
  160. +       (log_level & G_LOG_FLAG_FATAL) ? _("Error") : _("Warning"),
  161.         message);
  162.      } else {
  163.     /* Hooray! We have a GUI running! */
  164. @@ -353,8 +352,8 @@
  165.                             "<big><b>%s</b></big>\n\n%s",
  166.                             (log_level &
  167.                              G_LOG_FLAG_FATAL) ?
  168. -                           "Fatal Error" :
  169. -                           "Warning", message);
  170. +                           _("Fatal Error") :
  171. +                           _("Warning"), message);
  172.  
  173.     gtk_dialog_run(GTK_DIALOG(dialog));
  174.     gtk_widget_destroy(dialog);
  175. @@ -378,51 +377,51 @@
  176.      .short_name = 'r',
  177.      .arg = G_OPTION_ARG_NONE,
  178.      .arg_data = &create_report,
  179. -    .description = "creates a report and prints to standard output"},
  180. +    .description = N_("creates a report and prints to standard output")},
  181.     {
  182.      .long_name = "report-format",
  183.      .short_name = 'f',
  184.      .arg = G_OPTION_ARG_STRING,
  185.      .arg_data = &report_format,
  186. -    .description = "chooses a report format (text, html)"},
  187. +    .description = N_("chooses a report format (text, html)")},
  188.     {
  189.      .long_name = "run-benchmark",
  190.      .short_name = 'b',
  191.      .arg = G_OPTION_ARG_STRING,
  192.      .arg_data = &run_benchmark,
  193. -    .description = "run benchmark; requires benchmark.so to be loaded"},
  194. +    .description = N_("run benchmark; requires benchmark.so to be loaded")},
  195.     {
  196.      .long_name = "list-modules",
  197.      .short_name = 'l',
  198.      .arg = G_OPTION_ARG_NONE,
  199.      .arg_data = &list_modules,
  200. -    .description = "lists modules"},
  201. +    .description = N_("lists modules")},
  202.     {
  203.      .long_name = "load-module",
  204.      .short_name = 'm',
  205.      .arg = G_OPTION_ARG_STRING_ARRAY,
  206.      .arg_data = &use_modules,
  207. -    .description = "specify module to load"},
  208. +    .description = N_("specify module to load")},
  209.     {
  210.      .long_name = "autoload-deps",
  211.      .short_name = 'a',
  212.      .arg = G_OPTION_ARG_NONE,
  213.      .arg_data = &autoload_deps,
  214. -    .description = "automatically load module dependencies"},
  215. +    .description = N_("automatically load module dependencies")},
  216.  #ifdef HAS_LIBSOUP
  217.     {
  218.      .long_name = "xmlrpc-server",
  219.      .short_name = 'x',
  220.      .arg = G_OPTION_ARG_NONE,
  221.      .arg_data = &run_xmlrpc_server,
  222. -    .description = "run in XML-RPC server mode"},
  223. +    .description = N_("run in XML-RPC server mode")},
  224.  #endif /* HAS_LIBSOUP */
  225.     {
  226.      .long_name = "version",
  227.      .short_name = 'v',
  228.      .arg = G_OPTION_ARG_NONE,
  229.      .arg_data = &show_version,
  230. -    .description = "shows program version and quit"},
  231. +    .description = N_("shows program version and quit")},
  232.     {NULL}
  233.      };
  234.      GOptionContext *ctx;
  235. @@ -437,8 +436,8 @@
  236.      g_option_context_free(ctx);
  237.  
  238.      if (*argc >= 2) {
  239. -   g_print("Unrecognized arguments.\n"
  240. -       "Try ``%s --help'' for more information.\n", *(argv)[0]);
  241. +   g_print(_("Unrecognized arguments.\n")
  242. +       _("Try ``%s --help'' for more information.\n"), *(argv)[0]);
  243.     exit(1);
  244.      }
  245.  
  246. @@ -503,7 +502,7 @@
  247.         browser = (gchar *)browsers[i++];
  248.      } while (browser);
  249.  
  250. -    g_warning("Couldn't find a Web browser to open URL %s.", url);
  251. +    g_warning(_("Couldn't find a Web browser to open URL %s."), url);
  252.  }
  253.  
  254.  /* Copyright: Jens Låås, SLU 2002 */
  255. @@ -850,7 +849,7 @@
  256.                             GTK_DIALOG_DESTROY_WITH_PARENT,
  257.                             GTK_MESSAGE_QUESTION,
  258.                             GTK_BUTTONS_NONE,
  259. -                           "Module \"%s\" depends on module \"%s\", load it?",
  260. +                           _("Module \"%s\" depends on module \"%s\", load it?"),
  261.                             module->name,
  262.                             deps[i]);
  263.             gtk_dialog_add_buttons(GTK_DIALOG(dialog),
  264. @@ -867,13 +866,13 @@
  265.                 modules = g_slist_prepend(modules, mod);
  266.                 modules = modules_check_deps(modules);  /* re-check dependencies */
  267.             } else {
  268. -               g_error("HardInfo cannot run without loading the additional module.");
  269. +               g_error(_("HardInfo cannot run without loading the additional module."));
  270.                 exit(1);
  271.             }
  272.  
  273.             gtk_widget_destroy(dialog);
  274.             } else {
  275. -           g_error("Module \"%s\" depends on module \"%s\".",
  276. +           g_error(_("Module \"%s\" depends on module \"%s\"."),
  277.                 module->name, deps[i]);
  278.             }
  279.         }
  280. @@ -918,12 +917,13 @@
  281.      if (g_slist_length(modules) == 0) {
  282.     if (params.use_modules == NULL) {
  283.         g_error
  284. -       ("No module could be loaded. Check permissions on \"%s\" and try again.",
  285. +       (_("No module could be loaded. Check permissions on \"%s\" and try again."),
  286.          params.path_lib);
  287.     } else {
  288.         g_error
  289. -       ("No module could be loaded. Please use hardinfo -l to list all avai"
  290. -        "lable modules and try again with a valid module list.");
  291. +       (_("No module could be loaded. Please use hardinfo -l to list all avai"
  292. +        "lable modules and try again with a valid module list.")
  293. +);
  294.  
  295.     }
  296.      }
  297. @@ -1100,7 +1100,7 @@
  298.     if (i == except_entry)
  299.         continue;
  300.  
  301. -   text = g_strdup_printf("Scanning: %s...", entry.name);
  302. +   text = g_strdup_printf("_(Scanning: %s..."), entry.name);
  303.     shell_status_update(text);
  304.     g_free(text);
  305.  
  306. diff -Naur /home/max/123/src/hardinfo//includes/hardinfo.h /home/max/123/hardinfo/includes/hardinfo.h
  307. --- /home/max/123/src/hardinfo//includes/hardinfo.h 2011-03-02 20:22:17.000000000 +0300
  308. +++ /home/max/123/hardinfo/includes/hardinfo.h  2011-03-02 21:09:43.000000000 +0300
  309. @@ -19,6 +19,7 @@
  310.  #ifndef __HARDINFO_H__
  311.  #define __HARDINFO_H__
  312.  
  313. +#include <glib/gi18n-lib.h>
  314.  #include <gtk/gtk.h>
  315.  #include "config.h"
  316.  #include "shell.h"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement