-
Notifications
You must be signed in to change notification settings - Fork 138
Internationalization of xbps #647
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,11 +37,18 @@ | |
| #include <xbps.h> | ||
| #include "defs.h" | ||
|
|
||
|
|
||
| #include <libintl.h> | ||
| #include <locale.h> | ||
| #define _(STRING) gettext(STRING) | ||
|
|
||
|
|
||
|
|
||
| static void __attribute__((noreturn)) | ||
| usage(bool fail) | ||
| { | ||
| fprintf(stdout, | ||
| "Usage: xbps-install [OPTIONS] [PKGNAME...]\n\n" | ||
| _("Usage: xbps-install [OPTIONS] [PKGNAME...]\n\n" | ||
| "OPTIONS\n" | ||
| " -A, --automatic Set automatic installation mode\n" | ||
| " -C, --config <dir> Path to confdir (xbps.d)\n" | ||
|
|
@@ -66,7 +73,7 @@ usage(bool fail) | |
| " -u, --update Update target package(s)\n" | ||
| " -v, --verbose Verbose messages\n" | ||
| " -y, --yes Assume yes to all questions\n" | ||
| " -V, --version Show XBPS version\n"); | ||
| " -V, --version Show XBPS version\n")); | ||
| exit(fail ? EXIT_FAILURE : EXIT_SUCCESS); | ||
| } | ||
|
|
||
|
|
@@ -76,7 +83,7 @@ unpack_progress_cb(const struct xbps_unpack_cb_data *xpd, void *cbdata UNUSED) | |
| if (xpd->entry == NULL || xpd->entry_total_count <= 0) | ||
| return; | ||
|
|
||
| printf("%s: unpacked %sfile `%s' (%" PRIi64 " bytes)\n", | ||
| printf(_("%s: unpacked %sfile `%s' (%" PRIi64 " bytes)\n"), | ||
| xpd->pkgver, | ||
| xpd->entry_is_conf ? "configuration " : "", xpd->entry, | ||
| xpd->entry_size); | ||
|
|
@@ -88,16 +95,21 @@ repo_import_key_cb(struct xbps_repo *repo, void *arg UNUSED, bool *done UNUSED) | |
| int rv; | ||
|
|
||
| if ((rv = xbps_repo_key_import(repo)) != 0) | ||
| xbps_error_printf("Failed to import pubkey from %s: %s\n", | ||
| xbps_error_printf(_("Failed to import pubkey from %s: %s\n"), | ||
| repo->uri, strerror(rv)); | ||
|
|
||
| return rv; | ||
| } | ||
|
|
||
|
|
||
| int | ||
| main(int argc, char **argv) | ||
| { | ||
|
|
||
| const char *shortopts = "AC:c:DdfhIiMnR:r:SuUVvy"; | ||
|
|
||
| // Movido as declarações para o início | ||
|
|
||
| const struct option longopts[] = { | ||
| { "automatic", no_argument, NULL, 'A' }, | ||
| { "config", required_argument, NULL, 'C' }, | ||
|
|
@@ -122,6 +134,9 @@ main(int argc, char **argv) | |
| { "staging", no_argument, NULL, 2 }, | ||
| { NULL, 0, NULL, 0 } | ||
| }; | ||
|
|
||
|
|
||
|
|
||
| struct xbps_handle xh; | ||
| struct xferstat xfer; | ||
| const char *rootdir, *cachedir, *confdir; | ||
|
|
@@ -135,6 +150,14 @@ main(int argc, char **argv) | |
|
|
||
| memset(&xh, 0, sizeof(xh)); | ||
|
|
||
|
|
||
| setlocale(LC_ALL, ""); | ||
| bindtextdomain("xbps-install", "/usr/share/locale"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You shouldn't hardcode paths like that. This would require tighter build system integration, see my other comments on that.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am also not 100% sure on this, but |
||
| textdomain("xbps-install"); | ||
|
|
||
|
|
||
|
|
||
|
|
||
| while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1) { | ||
| switch (c) { | ||
| case 1: | ||
|
|
@@ -229,7 +252,7 @@ main(int argc, char **argv) | |
| xh.unpack_cb = unpack_progress_cb; | ||
|
|
||
| if ((rv = xbps_init(&xh)) != 0) { | ||
| xbps_error_printf("Failed to initialize libxbps: %s\n", | ||
| xbps_error_printf(_("Failed to initialize libxbps: %s\n"), | ||
| strerror(rv)); | ||
| exit(EXIT_FAILURE); | ||
| } | ||
|
|
@@ -250,7 +273,7 @@ main(int argc, char **argv) | |
|
|
||
| if (!(xh.flags & XBPS_FLAG_DOWNLOAD_ONLY) && !drun) { | ||
| if ((rv = xbps_pkgdb_lock(&xh)) != 0) { | ||
| xbps_error_printf("Failed to lock the pkgdb: %s\n", strerror(rv)); | ||
| xbps_error_printf(_("Failed to lock the pkgdb: %s\n"), strerror(rv)); | ||
| exit(rv); | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,6 +33,12 @@ | |
|
|
||
| #include "defs.h" | ||
|
|
||
|
|
||
| #include <libintl.h> | ||
| #include <locale.h> | ||
| #define _(STRING) gettext(STRING) | ||
|
|
||
|
|
||
| #ifdef __clang__ | ||
| #pragma clang diagnostic ignored "-Wformat-nonliteral" | ||
| #endif | ||
|
|
@@ -45,14 +51,16 @@ question(bool preset, const char *fmt, va_list ap) | |
|
|
||
| vfprintf(stderr, fmt, ap); | ||
| if (preset) | ||
| fputs(" [Y/n] ", stderr); | ||
| fputs(_(" [Y/n] "), stderr); | ||
| else | ||
| fputs(" [y/N] ", stderr); | ||
| fputs(_(" [y/N] "), stderr); | ||
|
|
||
| response = fgetc(stdin); | ||
| if (response == '\n') | ||
| rv = preset; | ||
| else if (response == 'y' || response == 'Y') | ||
|
|
||
| // Apenas acrescente S/s como equivalentes | ||
| else if (response == 'y' || response == 'Y' || response == 's' || response == 'S') | ||
| rv = true; | ||
| else if (response == 'n' || response == 'N') | ||
| rv = false; | ||
|
Comment on lines
-55
to
66
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not acceptable. If you really want to do this, the following might be better: response = fgetc(stdin);
// TRANSLATORS: The following string isn't displayed to the user, it is used to
// determine what the user's response to a yes/no question means.
// The characters in this string should be the same characters
// as in the TODO string (without the separator, / or otherwise).
// Only the first character of the user's response is considered,
// for example, the default English version consideres "y", "ye",
// "yes" and "yn" the same. You therefore cannot include whole
// words here.
// TODO: One letter may occupy multiple bytes. I suspect that the
// current setup doesn't handle that.
// This string defines a positive response. See the string below
// for a negative one.
const char * positive_response = _("yY");
// TRANSLATORS: This string defines a negative response. See the translators
// comment for positive_response above for more info.
const char * negative_response = _("nN");
if (response == "\n")
rv = preset;
else if (strchr(positive_response, response) != NULL)
rt = true;
else if (strchr(negative_response, response) != NULL)
rt = false;
// ... |
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be put into a common header (without the
locale.hheader, which should be only needed inmain()).