daemon: Internationalize guix-daemon.

* nix/nix-daemon/guix-daemon.cc (n_, _): New macros.
  (guix_textdomain): New variable.
  (doc): Use 'n_'.
  (options): Likewise, and lowercase messages.
  (argp): Add initializer for 'argp_domain' field.
  (parse_opt): Use '_' for messages.
  (main): Likewise, and add calls to 'setlocale', 'bindtextdomain', and
  'textdomain'.
* daemon.am (guix_daemon_CPPFLAGS): Add -DLOCALEDIR.
* po/guix/Makevars (XGETTEXT_OPTIONS): Remove '--language' option.  Add
  '--keyword=n_'.
* po/guix/POTFILES.in: Add guix-daemon.cc.
This commit is contained in:
Ludovic Courtès 2015-06-10 17:48:16 +02:00
parent 3dbb0e5f8b
commit 7887bcbf56
4 changed files with 68 additions and 43 deletions

View File

@ -126,6 +126,7 @@ guix_daemon_SOURCES = \
nix/nix-daemon/guix-daemon.cc nix/nix-daemon/guix-daemon.cc
guix_daemon_CPPFLAGS = \ guix_daemon_CPPFLAGS = \
-DLOCALEDIR=\"$(localedir)\" \
$(libutil_a_CPPFLAGS) \ $(libutil_a_CPPFLAGS) \
-I$(top_srcdir)/nix/libstore -I$(top_srcdir)/nix/libstore

View File

@ -33,6 +33,9 @@
#include <strings.h> #include <strings.h>
#include <exception> #include <exception>
#include <libintl.h>
#include <locale.h>
/* Variables used by `nix-daemon.cc'. */ /* Variables used by `nix-daemon.cc'. */
volatile ::sig_atomic_t blockInt; volatile ::sig_atomic_t blockInt;
char **argvSaved; char **argvSaved;
@ -45,16 +48,21 @@ extern void run (Strings args);
/* Command-line options. */ /* Command-line options. */
#define n_(str) str
#define _(str) gettext (str)
static const char guix_textdomain[] = "guix";
const char *argp_program_version = const char *argp_program_version =
"guix-daemon (" PACKAGE_NAME ") " PACKAGE_VERSION; "guix-daemon (" PACKAGE_NAME ") " PACKAGE_VERSION;
const char *argp_program_bug_address = PACKAGE_BUGREPORT; const char *argp_program_bug_address = PACKAGE_BUGREPORT;
static char doc[] = static char doc[] =
"guix-daemon -- perform derivation builds and store accesses\ n_("guix-daemon -- perform derivation builds and store accesses")
\v\ "\v\n"
This program is a daemon meant to run in the background. It serves \ n_("This program is a daemon meant to run in the background. It serves \
requests sent over a Unix-domain socket. It accesses the store, and \ requests sent over a Unix-domain socket. It accesses the store, and \
builds derivations on behalf of its clients."; builds derivations on behalf of its clients.");
#define GUIX_OPT_SYSTEM 1 #define GUIX_OPT_SYSTEM 1
#define GUIX_OPT_DISABLE_CHROOT 2 #define GUIX_OPT_DISABLE_CHROOT 2
@ -75,56 +83,59 @@ builds derivations on behalf of its clients.";
static const struct argp_option options[] = static const struct argp_option options[] =
{ {
{ "system", GUIX_OPT_SYSTEM, "SYSTEM", 0, { "system", GUIX_OPT_SYSTEM, n_("SYSTEM"), 0,
"Assume SYSTEM as the current system type" }, n_("assume SYSTEM as the current system type") },
{ "cores", 'c', "N", 0, { "cores", 'c', n_("N"), 0,
"Use N CPU cores to build each derivation; 0 means as many as available" }, n_("use N CPU cores to build each derivation; 0 means as many as available")
{ "max-jobs", 'M', "N", 0, },
"Allow at most N build jobs" }, { "max-jobs", 'M', n_("N"), 0,
n_("allow at most N build jobs") },
{ "disable-chroot", GUIX_OPT_DISABLE_CHROOT, 0, 0, { "disable-chroot", GUIX_OPT_DISABLE_CHROOT, 0, 0,
"Disable chroot builds" }, n_("disable chroot builds") },
{ "chroot-directory", GUIX_OPT_CHROOT_DIR, "DIR", 0, { "chroot-directory", GUIX_OPT_CHROOT_DIR, n_("DIR"), 0,
"Add DIR to the build chroot" }, n_("add DIR to the build chroot") },
{ "build-users-group", GUIX_OPT_BUILD_USERS_GROUP, "GROUP", 0, { "build-users-group", GUIX_OPT_BUILD_USERS_GROUP, n_("GROUP"), 0,
"Perform builds as a user of GROUP" }, n_("perform builds as a user of GROUP") },
{ "no-substitutes", GUIX_OPT_NO_SUBSTITUTES, 0, 0, { "no-substitutes", GUIX_OPT_NO_SUBSTITUTES, 0, 0,
"Do not use substitutes" }, n_("do not use substitutes") },
{ "substitute-urls", GUIX_OPT_SUBSTITUTE_URLS, "URLS", 0, { "substitute-urls", GUIX_OPT_SUBSTITUTE_URLS, n_("URLS"), 0,
"Use URLS as the default list of substitute providers" }, n_("use URLS as the default list of substitute providers") },
{ "no-build-hook", GUIX_OPT_NO_BUILD_HOOK, 0, 0, { "no-build-hook", GUIX_OPT_NO_BUILD_HOOK, 0, 0,
"Do not use the 'build hook'" }, n_("do not use the 'build hook'") },
{ "cache-failures", GUIX_OPT_CACHE_FAILURES, 0, 0, { "cache-failures", GUIX_OPT_CACHE_FAILURES, 0, 0,
"Cache build failures" }, n_("cache build failures") },
{ "lose-logs", GUIX_OPT_LOSE_LOGS, 0, 0, { "lose-logs", GUIX_OPT_LOSE_LOGS, 0, 0,
"Do not keep build logs" }, n_("do not keep build logs") },
{ "disable-log-compression", GUIX_OPT_DISABLE_LOG_COMPRESSION, 0, 0, { "disable-log-compression", GUIX_OPT_DISABLE_LOG_COMPRESSION, 0, 0,
"Disable compression of the build logs" }, n_("disable compression of the build logs") },
/* '--disable-deduplication' was known as '--disable-store-optimization' /* '--disable-deduplication' was known as '--disable-store-optimization'
up to Guix 0.7 included, so keep the alias around. */ up to Guix 0.7 included, so keep the alias around. */
{ "disable-deduplication", GUIX_OPT_DISABLE_DEDUPLICATION, 0, 0, { "disable-deduplication", GUIX_OPT_DISABLE_DEDUPLICATION, 0, 0,
"Disable automatic file \"deduplication\" in the store" }, n_("disable automatic file \"deduplication\" in the store") },
{ "disable-store-optimization", GUIX_OPT_DISABLE_DEDUPLICATION, 0, { "disable-store-optimization", GUIX_OPT_DISABLE_DEDUPLICATION, 0,
OPTION_ALIAS | OPTION_HIDDEN, NULL }, OPTION_ALIAS | OPTION_HIDDEN, NULL },
{ "impersonate-linux-2.6", GUIX_OPT_IMPERSONATE_LINUX_26, 0, 0, { "impersonate-linux-2.6", GUIX_OPT_IMPERSONATE_LINUX_26, 0,
"Impersonate Linux 2.6" #ifdef HAVE_SYS_PERSONALITY_H
#ifndef HAVE_SYS_PERSONALITY_H 0,
" (this option has no effect in this configuration)" #else
OPTION_HIDDEN,
#endif #endif
n_("impersonate Linux 2.6")
}, },
{ "gc-keep-outputs", GUIX_OPT_GC_KEEP_OUTPUTS, { "gc-keep-outputs", GUIX_OPT_GC_KEEP_OUTPUTS,
"yes/no", OPTION_ARG_OPTIONAL, "yes/no", OPTION_ARG_OPTIONAL,
"Tell whether the GC must keep outputs of live derivations" }, n_("tell whether the GC must keep outputs of live derivations") },
{ "gc-keep-derivations", GUIX_OPT_GC_KEEP_DERIVATIONS, { "gc-keep-derivations", GUIX_OPT_GC_KEEP_DERIVATIONS,
"yes/no", OPTION_ARG_OPTIONAL, "yes/no", OPTION_ARG_OPTIONAL,
"Tell whether the GC must keep derivations corresponding \ n_("tell whether the GC must keep derivations corresponding \
to live outputs" }, to live outputs") },
{ "listen", GUIX_OPT_LISTEN, "SOCKET", 0, { "listen", GUIX_OPT_LISTEN, n_("SOCKET"), 0,
"Listen for connections on SOCKET" }, n_("listen for connections on SOCKET") },
{ "debug", GUIX_OPT_DEBUG, 0, 0, { "debug", GUIX_OPT_DEBUG, 0, 0,
"Produce debugging output" }, n_("produce debugging output") },
{ 0, 0, 0, 0, 0 } { 0, 0, 0, 0, 0 }
}; };
@ -191,7 +202,7 @@ parse_opt (int key, char *arg, struct argp_state *state)
} }
catch (std::exception &e) catch (std::exception &e)
{ {
fprintf (stderr, "error: %s\n", e.what ()); fprintf (stderr, _("error: %s\n"), e.what ());
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
} }
break; break;
@ -230,19 +241,29 @@ parse_opt (int key, char *arg, struct argp_state *state)
} }
/* Argument parsing. */ /* Argument parsing. */
static struct argp argp = { options, parse_opt, 0, doc }; static const struct argp argp =
{
options, parse_opt,
NULL, doc,
NULL, NULL, // children and help_filter
guix_textdomain
};
int int
main (int argc, char *argv[]) main (int argc, char *argv[])
{ {
Strings nothing; static const Strings nothing;
setlocale (LC_ALL, "");
bindtextdomain (guix_textdomain, LOCALEDIR);
textdomain (guix_textdomain);
/* Initialize libgcrypt. */ /* Initialize libgcrypt. */
if (!gcry_check_version (GCRYPT_VERSION)) if (!gcry_check_version (GCRYPT_VERSION))
{ {
fprintf (stderr, "error: libgcrypt version mismatch\n"); fprintf (stderr, _("error: libgcrypt version mismatch\n"));
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
} }
@ -333,8 +354,8 @@ main (int argc, char *argv[])
settings.update (); settings.update ();
if (geteuid () == 0 && settings.buildUsersGroup.empty ()) if (geteuid () == 0 && settings.buildUsersGroup.empty ())
fprintf (stderr, "warning: daemon is running as root, so " fprintf (stderr, _("warning: daemon is running as root, so \
"using `--build-users-group' is highly recommended\n"); using `--build-users-group' is highly recommended\n"));
if (settings.useChroot) if (settings.useChroot)
{ {
@ -357,7 +378,7 @@ main (int argc, char *argv[])
} }
catch (std::exception &e) catch (std::exception &e)
{ {
fprintf (stderr, "error: %s\n", e.what ()); fprintf (stderr, _("error: %s\n"), e.what ());
return EXIT_FAILURE; return EXIT_FAILURE;
} }

View File

@ -6,12 +6,14 @@ subdir = po/guix
top_builddir = ../.. top_builddir = ../..
# These options get passed to xgettext. We want to catch standard # These options get passed to xgettext. We want to catch standard
# gettext uses, and SRFI-35 error condition messages. # gettext uses, and SRFI-35 error condition messages. In C++ code
# we use 'n_' instead of the more usual 'N_' for no-ops.
XGETTEXT_OPTIONS = \ XGETTEXT_OPTIONS = \
--language=Scheme --from-code=UTF-8 \ --from-code=UTF-8 \
--keyword=_ --keyword=N_:1,2 \ --keyword=_ --keyword=N_:1,2 \
--keyword=message \ --keyword=message \
--keyword=description --keyword=description \
--keyword=n_
COPYRIGHT_HOLDER = Ludovic Courtès COPYRIGHT_HOLDER = Ludovic Courtès

View File

@ -20,3 +20,4 @@ guix/gnu-maintenance.scm
guix/ui.scm guix/ui.scm
guix/http-client.scm guix/http-client.scm
guix/nar.scm guix/nar.scm
nix/nix-daemon/guix-daemon.cc