mirror of
https://git.zap.org.au/git/trader.git
synced 2025-01-03 14:57:41 -05:00
First pass at adding _() and N_() to allow string translation
This commit is contained in:
parent
36b1a13254
commit
9251ca0463
28
src/fileio.c
28
src/fileio.c
@ -52,15 +52,15 @@ static const unsigned char game_file_crypt_key[] = {
|
||||
#define load_game_scanf(_fmt, _var, _cond) \
|
||||
do { \
|
||||
if (fgets(buf, BUFSIZE, file) == NULL) { \
|
||||
err_exit("%s: missing field on line %d", filename, lineno); \
|
||||
err_exit(_("%s: missing field on line %d"), filename, lineno); \
|
||||
} \
|
||||
if (sscanf(unscramble(crypt_key, buf, BUFSIZE), _fmt "\n", \
|
||||
&(_var)) != 1) { \
|
||||
err_exit("%s: illegal field on line %d: `%s'", \
|
||||
err_exit(_("%s: illegal field on line %d: `%s'"), \
|
||||
filename, lineno, buf); \
|
||||
} \
|
||||
if (! (_cond)) { \
|
||||
err_exit("%s: illegal value on line %d: `%s'", \
|
||||
err_exit(_("%s: illegal value on line %d: `%s'"), \
|
||||
filename, lineno, buf); \
|
||||
} \
|
||||
lineno++; \
|
||||
@ -87,10 +87,10 @@ static const unsigned char game_file_crypt_key[] = {
|
||||
int len; \
|
||||
\
|
||||
if (fgets(buf, BUFSIZE, file) == NULL) { \
|
||||
err_exit("%s: missing field on line %d", filename, lineno); \
|
||||
err_exit(_("%s: missing field on line %d"), filename, lineno); \
|
||||
} \
|
||||
if (strlen(unscramble(crypt_key, buf, BUFSIZE)) == 0) { \
|
||||
err_exit("%s: illegal value on line %d", filename, lineno); \
|
||||
err_exit(_("%s: illegal value on line %d"), filename, lineno); \
|
||||
} \
|
||||
lineno++; \
|
||||
\
|
||||
@ -205,16 +205,16 @@ bool load_game (int num)
|
||||
|
||||
// Read the game file header
|
||||
if (fgets(buf, BUFSIZE, file) == NULL) {
|
||||
err_exit("%s: missing header in game file", filename);
|
||||
err_exit(_("%s: missing header in game file"), filename);
|
||||
}
|
||||
if (strcmp(buf, GAME_FILE_HEADER "\n") != 0) {
|
||||
err_exit("%s: not a valid game file", filename);
|
||||
err_exit(_("%s: not a valid game file"), filename);
|
||||
}
|
||||
if (fgets(buf, BUFSIZE, file) == NULL) {
|
||||
err_exit("%s: missing subheader in game file", filename);
|
||||
err_exit(_("%s: missing subheader in game file"), filename);
|
||||
}
|
||||
if (strcmp(buf, GAME_FILE_API_VERSION "\n") != 0) {
|
||||
err_exit("%s: saved under a different version of Star Traders",
|
||||
err_exit(_("%s: saved under a different version of Star Traders"),
|
||||
filename);
|
||||
}
|
||||
|
||||
@ -222,7 +222,7 @@ bool load_game (int num)
|
||||
|
||||
// Read in the game file encryption key
|
||||
if (fscanf(file, "%i\n", &crypt_key) != 1) {
|
||||
err_exit("%s: illegal or missing field on line %d", filename, lineno);
|
||||
err_exit(_("%s: illegal or missing field on line %d"), filename, lineno);
|
||||
}
|
||||
lineno++;
|
||||
|
||||
@ -251,7 +251,7 @@ bool load_game (int num)
|
||||
|
||||
// Read in company data
|
||||
for (i = 0; i < MAX_COMPANIES; i++) {
|
||||
company[i].name = company_name[i];
|
||||
company[i].name = strdup(gettext(company_name[i]));
|
||||
load_game_read_double(company[i].share_price, company[i].share_price >= 0.0);
|
||||
load_game_read_double(company[i].share_return, true);
|
||||
load_game_read_long(company[i].stock_issued, company[i].stock_issued >= 0);
|
||||
@ -262,10 +262,10 @@ bool load_game (int num)
|
||||
// Read in galaxy map
|
||||
for (int x = 0; x < MAX_X; x++) {
|
||||
if (fgets(buf, BUFSIZE, file) == NULL) {
|
||||
err_exit("%s: missing field on line %d", filename, lineno);
|
||||
err_exit(_("%s: missing field on line %d"), filename, lineno);
|
||||
}
|
||||
if (strlen(unscramble(crypt_key, buf, BUFSIZE)) != MAX_Y + 1) {
|
||||
err_exit("%s: illegal field on line %d", filename, lineno);
|
||||
err_exit(_("%s: illegal field on line %d"), filename, lineno);
|
||||
}
|
||||
|
||||
for (int y = 0; y < MAX_Y; y++) {
|
||||
@ -274,7 +274,7 @@ bool load_game (int num)
|
||||
|| (c >= MAP_A && c <= MAP_LAST)) {
|
||||
galaxy_map[x][y] = (map_val_t) c;
|
||||
} else {
|
||||
err_exit("%s: illegal value on line %d", filename, lineno);
|
||||
err_exit(_("%s: illegal value on line %d"), filename, lineno);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -178,7 +178,7 @@ void init_game (void)
|
||||
|
||||
// Initialise company data
|
||||
for (i = 0; i < MAX_COMPANIES; i++) {
|
||||
company[i].name = company_name[i];
|
||||
company[i].name = strdup(gettext(company_name[i]));
|
||||
company[i].share_price = 0.0;
|
||||
company[i].share_return = INITIAL_RETURN;
|
||||
company[i].stock_issued = 0;
|
||||
@ -552,7 +552,7 @@ void end_game (void)
|
||||
for (i = 0; i < number_players; i++) {
|
||||
l_strfmon(buf, BUFSIZE, "%!18n", player[i].sort_value);
|
||||
mvwprintw(curwin, i + 7, 2, "%5s %-*.*s %18s ",
|
||||
ordinal[i + 1], w, w, player[i].name, buf);
|
||||
gettext(ordinal[i + 1]), w, w, player[i].name, buf);
|
||||
}
|
||||
|
||||
wait_for_key(curwin, getmaxy(curwin) - 2, attr_waitforkey);
|
||||
|
@ -37,28 +37,28 @@
|
||||
|
||||
// Company names
|
||||
const char *company_name[MAX_COMPANIES] = {
|
||||
"Altair Starways",
|
||||
"Betelgeuse, Ltd",
|
||||
"Capella Freight Co",
|
||||
"Denebola Shippers",
|
||||
"Eridani Expediters",
|
||||
"Fornax Express",
|
||||
"Gemeni Inc",
|
||||
"Hercules and Co"
|
||||
N_("Altair Starways"),
|
||||
N_("Betelgeuse, Ltd"),
|
||||
N_("Capella Freight Co"),
|
||||
N_("Denebola Shippers"),
|
||||
N_("Eridani Expediters"),
|
||||
N_("Fornax Express"),
|
||||
N_("Gemeni Inc"),
|
||||
N_("Hercules and Co")
|
||||
};
|
||||
|
||||
|
||||
// Ordinal strings
|
||||
const char *ordinal[MAX_PLAYERS + 1] = {
|
||||
"0th",
|
||||
"1st",
|
||||
"2nd",
|
||||
"3rd",
|
||||
"4th",
|
||||
"5th",
|
||||
"6th",
|
||||
"7th",
|
||||
"8th"
|
||||
N_("0th"),
|
||||
N_("1st"),
|
||||
N_("2nd"),
|
||||
N_("3rd"),
|
||||
N_("4th"),
|
||||
N_("5th"),
|
||||
N_("6th"),
|
||||
N_("7th"),
|
||||
N_("8th")
|
||||
};
|
||||
|
||||
|
||||
|
@ -129,7 +129,7 @@ void init_screen (void)
|
||||
initscr();
|
||||
|
||||
if (COLS < MIN_COLS || LINES < MIN_LINES) {
|
||||
err_exit("terminal size is too small (%d x %d required)",
|
||||
err_exit(_("terminal size is too small (%d x %d required)"),
|
||||
MIN_COLS, MIN_LINES);
|
||||
}
|
||||
|
||||
|
36
src/trader.c
36
src/trader.c
@ -232,7 +232,7 @@ void process_cmdline (int argc, char *argv[])
|
||||
option_max_turn = strtol(optarg, &p, 10);
|
||||
|
||||
if (option_max_turn < MIN_MAX_TURN || p == NULL || *p != '\0') {
|
||||
fprintf(stderr, "%s: invalid value for --max-turn: `%s'\n",
|
||||
fprintf(stderr, _("%s: invalid value for --max-turn: `%s'\n"),
|
||||
program_name(), optarg);
|
||||
show_usage(EXIT_FAILURE);
|
||||
}
|
||||
@ -248,7 +248,7 @@ void process_cmdline (int argc, char *argv[])
|
||||
|
||||
if (optind < argc && argv[optind] != NULL) {
|
||||
if (*argv[optind] == '-') {
|
||||
fprintf(stderr, "%s: invalid operand `%s'\n", program_name(),
|
||||
fprintf(stderr, _("%s: invalid operand `%s'\n"), program_name(),
|
||||
argv[optind]);
|
||||
show_usage(EXIT_FAILURE);
|
||||
}
|
||||
@ -257,7 +257,7 @@ void process_cmdline (int argc, char *argv[])
|
||||
&& *argv[optind] >= '1' && *argv[optind] <= '9') {
|
||||
game_num = *argv[optind] - '0';
|
||||
} else {
|
||||
fprintf(stderr, "%s: invalid game number `%s'\n",
|
||||
fprintf(stderr, _("%s: invalid game number `%s'\n"),
|
||||
program_name(), argv[optind]);
|
||||
show_usage(EXIT_FAILURE);
|
||||
}
|
||||
@ -266,7 +266,7 @@ void process_cmdline (int argc, char *argv[])
|
||||
}
|
||||
|
||||
if (optind < argc && argv[optind] != NULL) {
|
||||
fprintf(stderr, "%s: extra operand `%s'\n", program_name(),
|
||||
fprintf(stderr, _("%s: extra operand `%s'\n"), program_name(),
|
||||
argv[optind]);
|
||||
show_usage(EXIT_FAILURE);
|
||||
}
|
||||
@ -278,7 +278,7 @@ void process_cmdline (int argc, char *argv[])
|
||||
|
||||
void show_version (void)
|
||||
{
|
||||
printf("\
|
||||
printf(_("\
|
||||
" PACKAGE_NAME " (%s) %s\n\
|
||||
Copyright (C) %s, John Zaitseff.\n\
|
||||
\n\
|
||||
@ -290,7 +290,7 @@ This program is free software that is distributed under the terms of the\n\
|
||||
GNU General Public License, version 3 or later. You are welcome to\n\
|
||||
modify and/or distribute it under certain conditions. This program has\n\
|
||||
NO WARRANTY, to the extent permitted by law; see the License for details.\n\
|
||||
", program_name(), PACKAGE_VERSION, "1990-2011");
|
||||
"), program_name(), PACKAGE_VERSION, "1990-2011");
|
||||
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
@ -305,35 +305,35 @@ void show_usage (int status)
|
||||
|
||||
|
||||
if (status != EXIT_SUCCESS) {
|
||||
fprintf(stderr, "%s: Try `%s --help' for more information.\n",
|
||||
fprintf(stderr, _("%s: Try `%s --help' for more information.\n"),
|
||||
pn, pn);
|
||||
} else {
|
||||
printf("Usage: %s [OPTION ...] [GAME]\n", pn);
|
||||
printf("\
|
||||
printf(_("Usage: %s [OPTION ...] [GAME]\n"), pn);
|
||||
printf(_("\
|
||||
Play Star Traders, a simple game of interstellar trading.\n\n\
|
||||
");
|
||||
printf("\
|
||||
"));
|
||||
printf(_("\
|
||||
Options:\n\
|
||||
-V, --version output version information and exit\n\
|
||||
-h, --help display this help and exit\n\
|
||||
--no-color don't use colour for displaying text\n\
|
||||
--max-turn=NUM set the number of turns to NUM\n\n\
|
||||
");
|
||||
printf("\
|
||||
"));
|
||||
printf(_("\
|
||||
If GAME is specified as a number between 1 and 9, load and continue\n\
|
||||
playing that game. If GAME is not specified, start a new game.\n\n\
|
||||
");
|
||||
"));
|
||||
|
||||
#ifdef PACKAGE_AUTHOR
|
||||
printf("Report bugs to %s <%s>.\n", PACKAGE_AUTHOR, PACKAGE_BUGREPORT);
|
||||
printf(_("Report bugs to %s <%s>.\n"), PACKAGE_AUTHOR, PACKAGE_BUGREPORT);
|
||||
#else
|
||||
printf("Report bugs to <%s>.\n", PACKAGE_BUGREPORT);
|
||||
printf(_("Report bugs to <%s>.\n"), PACKAGE_BUGREPORT);
|
||||
#endif
|
||||
#ifdef PACKAGE_PACKAGER_BUG_REPORTS
|
||||
printf("Report %s bugs to <%s>.\n", PACKAGE_PACKAGER, PACKAGE_PACKAGER_BUG_REPORTS);
|
||||
printf(_("Report %s bugs to <%s>.\n"), PACKAGE_PACKAGER, PACKAGE_PACKAGER_BUG_REPORTS);
|
||||
#endif
|
||||
#ifdef PACKAGE_URL
|
||||
printf(PACKAGE_NAME " home page: <%s>.\n", PACKAGE_URL);
|
||||
printf(_(PACKAGE_NAME " home page: <%s>.\n"), PACKAGE_URL);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -206,7 +206,7 @@ void err_exit (const char *restrict format, ...)
|
||||
|
||||
end_screen();
|
||||
|
||||
fprintf(stderr, "%s: ", program_name());
|
||||
fprintf(stderr, _("%s: "), program_name());
|
||||
va_start(args, format);
|
||||
vfprintf(stderr, format, args);
|
||||
va_end(args);
|
||||
@ -227,12 +227,12 @@ void errno_exit (const char *restrict format, ...)
|
||||
|
||||
end_screen();
|
||||
|
||||
fprintf(stderr, "%s: ", program_name());
|
||||
fprintf(stderr, _("%s: "), program_name());
|
||||
if (format != NULL) {
|
||||
va_start(args, format);
|
||||
vfprintf(stderr, format, args);
|
||||
va_end(args);
|
||||
fputs(": ", stderr);
|
||||
fputs(_(": "), stderr);
|
||||
}
|
||||
fprintf(stderr, "%s\n", strerror(saved_errno));
|
||||
|
||||
@ -245,7 +245,7 @@ void errno_exit (const char *restrict format, ...)
|
||||
|
||||
void err_exit_nomem (void)
|
||||
{
|
||||
err_exit("out of memory");
|
||||
err_exit(_("out of memory"));
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user