diff --git a/msgfmt b/msgfmt new file mode 100644 index 0000000..e69de29 diff --git a/msginit b/msginit new file mode 100644 index 0000000..e69de29 diff --git a/src/gfx_curses.c b/src/gfx_curses.c index 4db2467..649f206 100644 --- a/src/gfx_curses.c +++ b/src/gfx_curses.c @@ -3,6 +3,8 @@ #include #include "gfx.h" #include "merge.h" +#include +#include #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) { 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 - 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); iterate(g->opts->grid_width * (g->print_width + 2) + 1, waddch(s->window, '-')); diff --git a/src/gfx_terminal.c b/src/gfx_terminal.c index ec2de50..e5d3371 100644 --- a/src/gfx_terminal.c +++ b/src/gfx_terminal.c @@ -4,6 +4,8 @@ #include #include "merge.h" #include "gfx.h" +#include +#include #define iterate(n, expression)\ do {\ @@ -37,11 +39,11 @@ void gfx_draw(struct gfx_state *s, struct gamestate *g) #endif 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 - 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"); diff --git a/src/highscore.c b/src/highscore.c index f6ba15c..fbf51e3 100644 --- a/src/highscore.c +++ b/src/highscore.c @@ -5,6 +5,8 @@ #include #include #include "engine.h" +#include +#include const char *hs_dir_name = "2048"; const char *hs_file_name = "highscore"; @@ -53,7 +55,7 @@ void highscore_reset(void) const size_t resp_length = 16; 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) { /* fgets is used to avoid queuing that may occur with getchar */ @@ -66,12 +68,12 @@ void highscore_reset(void) if (sl < resp_length) 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; else if (!strncmp(resp, "no", resp_length) || !strncmp(resp, "n", resp_length)) return; - printf("Please enter Yes or No\n"); + printf(gettext("Please enter Yes or No\n")); } reset_scores:; @@ -90,12 +92,12 @@ long highscore_load(struct gamestate *g) fd = fopen(hsfile, "w+"); if (fd == NULL) { - fprintf(stderr, "load: Failed to open highscore file\n"); + fprintf(stderr, gettext("load: Failed to open highscore file\n")); return 0; } 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; } @@ -117,12 +119,12 @@ void highscore_save(struct gamestate *g) FILE *fd = fopen(hsfile, "w"); if (fd == NULL) { - fprintf(stderr, "save: Failed to open highscore file\n"); + fprintf(stderr, gettext("save: Failed to open highscore file\n")); return; } 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); } diff --git a/src/main.c b/src/main.c index c5c62cd..ce4ff02 100644 --- a/src/main.c +++ b/src/main.c @@ -3,6 +3,8 @@ #include "ai.h" #include "engine.h" #include "gfx.h" +#include +#include 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) { + setlocale (LC_ALL, ""); + bindtextdomain ("gfx_terminal", "/usr/share/locale/"); + textdomain ("gfx_terminal"); + struct gamestate *g = gamestate_init(argc, argv); if (!g) { fatal("failed to allocate gamestate"); diff --git a/xgettext b/xgettext new file mode 100644 index 0000000..e69de29