gettext funcion applied to strings
This commit is contained in:
parent
eaca6e1445
commit
560bb6cf8b
|
@ -3,6 +3,8 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include "gfx.h"
|
#include "gfx.h"
|
||||||
#include "merge.h"
|
#include "merge.h"
|
||||||
|
#include <libintl.h>
|
||||||
|
#include <locale.h>
|
||||||
|
|
||||||
#define NUMBER_OF_COLORS 7
|
#define NUMBER_OF_COLORS 7
|
||||||
|
|
||||||
|
@ -61,11 +63,11 @@ struct gfx_state* gfx_init(struct gamestate *g)
|
||||||
void gfx_draw(struct gfx_state *s, struct gamestate *g)
|
void gfx_draw(struct gfx_state *s, struct gamestate *g)
|
||||||
{
|
{
|
||||||
if (g->score_last)
|
if (g->score_last)
|
||||||
mvwprintw(s->window, 0, 0, "Score: %d (+%d)\n", g->score, g->score_last);
|
mvwprintw(s->window, 0, 0, gettext("Score: %d (+%d)\n"), g->score, g->score_last);
|
||||||
else
|
else
|
||||||
mvwprintw(s->window, 0, 0, "Score: %d\n", g->score);
|
mvwprintw(s->window, 0, 0, gettext("Score: %d\n"), g->score);
|
||||||
|
|
||||||
mvwprintw(s->window, 1, 0, " Hi: %d\n", g->score_high);
|
mvwprintw(s->window, 1, 0, gettext(" Hil: %d\n"), g->score_high);
|
||||||
|
|
||||||
wattron(s->window, A_DIM);
|
wattron(s->window, A_DIM);
|
||||||
iterate(g->opts->grid_width * (g->print_width + 2) + 1, waddch(s->window, '-'));
|
iterate(g->opts->grid_width * (g->print_width + 2) + 1, waddch(s->window, '-'));
|
||||||
|
|
|
@ -4,6 +4,8 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include "merge.h"
|
#include "merge.h"
|
||||||
#include "gfx.h"
|
#include "gfx.h"
|
||||||
|
#include <libintl.h>
|
||||||
|
#include <locale.h>
|
||||||
|
|
||||||
#define iterate(n, expression)\
|
#define iterate(n, expression)\
|
||||||
do {\
|
do {\
|
||||||
|
@ -37,11 +39,11 @@ void gfx_draw(struct gfx_state *s, struct gamestate *g)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (g->score_last)
|
if (g->score_last)
|
||||||
printf("Score: %ld (+%ld)\n", g->score, g->score_last);
|
printf(gettext("Score: %ld (+%ld)\n"), g->score, g->score_last);
|
||||||
else
|
else
|
||||||
printf("Score: %ld\n", g->score);
|
printf(gettext("Score: %ld\n"), g->score);
|
||||||
|
|
||||||
printf(" Hi: %ld\n", g->score_high);
|
printf(gettext(" Hi: %ld\n"), g->score_high);
|
||||||
|
|
||||||
iterate((g->print_width + 2) * g->opts->grid_width + 1, printf("-")); printf("\n");
|
iterate((g->print_width + 2) * g->opts->grid_width + 1, printf("-")); printf("\n");
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include "engine.h"
|
#include "engine.h"
|
||||||
|
#include <libintl.h>
|
||||||
|
#include <locale.h>
|
||||||
|
|
||||||
const char *hs_dir_name = "2048";
|
const char *hs_dir_name = "2048";
|
||||||
const char *hs_file_name = "highscore";
|
const char *hs_file_name = "highscore";
|
||||||
|
@ -53,7 +55,7 @@ void highscore_reset(void)
|
||||||
const size_t resp_length = 16;
|
const size_t resp_length = 16;
|
||||||
char resp[resp_length];
|
char resp[resp_length];
|
||||||
|
|
||||||
printf("Are you sure you want to reset your scores? Y(es) or N(o)\n");
|
printf(gettext("Are you sure you want to reset your scores? Y(es) or N(o)\n"));
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
/* fgets is used to avoid queuing that may occur with getchar */
|
/* fgets is used to avoid queuing that may occur with getchar */
|
||||||
|
@ -66,12 +68,12 @@ void highscore_reset(void)
|
||||||
if (sl < resp_length)
|
if (sl < resp_length)
|
||||||
resp[sl - 1] = '\0';
|
resp[sl - 1] = '\0';
|
||||||
|
|
||||||
if (!strncmp(resp, "yes", resp_length) || !strncmp(resp, "y", resp_length))
|
if (!strncmp(resp, gettext("yes"), resp_length) || !strncmp(resp, gettext("y"), resp_length))
|
||||||
goto reset_scores;
|
goto reset_scores;
|
||||||
else if (!strncmp(resp, "no", resp_length) || !strncmp(resp, "n", resp_length))
|
else if (!strncmp(resp, "no", resp_length) || !strncmp(resp, "n", resp_length))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
printf("Please enter Yes or No\n");
|
printf(gettext("Please enter Yes or No\n"));
|
||||||
}
|
}
|
||||||
|
|
||||||
reset_scores:;
|
reset_scores:;
|
||||||
|
@ -90,12 +92,12 @@ long highscore_load(struct gamestate *g)
|
||||||
fd = fopen(hsfile, "w+");
|
fd = fopen(hsfile, "w+");
|
||||||
|
|
||||||
if (fd == NULL) {
|
if (fd == NULL) {
|
||||||
fprintf(stderr, "load: Failed to open highscore file\n");
|
fprintf(stderr, gettext("load: Failed to open highscore file\n"));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fscanf(fd, "%ld", &result) != 1) {
|
if (fscanf(fd, "%ld", &result) != 1) {
|
||||||
fprintf(stderr, "load: Failed to parse highscore file\n");
|
fprintf(stderr, gettext("load: Failed to parse highscore file\n"));
|
||||||
result = 0;
|
result = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,12 +119,12 @@ void highscore_save(struct gamestate *g)
|
||||||
|
|
||||||
FILE *fd = fopen(hsfile, "w");
|
FILE *fd = fopen(hsfile, "w");
|
||||||
if (fd == NULL) {
|
if (fd == NULL) {
|
||||||
fprintf(stderr, "save: Failed to open highscore file\n");
|
fprintf(stderr, gettext("save: Failed to open highscore file\n"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fprintf(fd, "%ld", g->score) < 0) {
|
if (fprintf(fd, "%ld", g->score) < 0) {
|
||||||
fprintf(stderr, "save: Failed to write highscore file\n");
|
fprintf(stderr, gettext("save: Failed to write highscore file\n"));
|
||||||
}
|
}
|
||||||
fclose(fd);
|
fclose(fd);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
#include "ai.h"
|
#include "ai.h"
|
||||||
#include "engine.h"
|
#include "engine.h"
|
||||||
#include "gfx.h"
|
#include "gfx.h"
|
||||||
|
#include <libintl.h>
|
||||||
|
#include <locale.h>
|
||||||
|
|
||||||
void draw_then_sleep(struct gfx_state *s, struct gamestate *g)
|
void draw_then_sleep(struct gfx_state *s, struct gamestate *g)
|
||||||
{
|
{
|
||||||
|
@ -13,6 +15,10 @@ void draw_then_sleep(struct gfx_state *s, struct gamestate *g)
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
|
setlocale (LC_ALL, "");
|
||||||
|
bindtextdomain ("gfx_terminal", "/usr/share/locale/");
|
||||||
|
textdomain ("gfx_terminal");
|
||||||
|
|
||||||
struct gamestate *g = gamestate_init(argc, argv);
|
struct gamestate *g = gamestate_init(argc, argv);
|
||||||
if (!g) {
|
if (!g) {
|
||||||
fatal("failed to allocate gamestate");
|
fatal("failed to allocate gamestate");
|
||||||
|
|
Loading…
Reference in New Issue
Block a user