Skip to content
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

Add i18n system and spanish translation #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 7 additions & 5 deletions 2048.c
Expand Up @@ -16,6 +16,8 @@
#include <stdint.h>
#include <time.h>
#include <signal.h>
// Locale language
#include "language_header.h"

#define SIZE 4
uint32_t score=0;
Expand Down Expand Up @@ -75,7 +77,7 @@ void drawBoard(uint8_t board[SIZE][SIZE]) {
printf("\n");
}
printf("\n");
printf(" ←,↑,→,↓ or q \n");
printf(" ←,↑,→,↓ %s q \n",LOCALE_WORDS[0]);
printf("\033[A"); // one line up
}

Expand Down Expand Up @@ -350,7 +352,7 @@ int test() {
}

void signal_callback_handler(int signum) {
printf(" TERMINATED \n");
printf(" %s \n",LOCALE_WORDS[1]);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 esto esta bien así aunque este raro, ya que esta gente no deja espacio luego de la ,

setBufferedInput(true);
printf("\033[?25h\033[m");
exit(signum);
Expand Down Expand Up @@ -409,20 +411,20 @@ int main(int argc, char *argv[]) {
addRandom(board);
drawBoard(board);
if (gameEnded(board)) {
printf(" GAME OVER \n");
printf(" %s \n",LOCALE_WORDS[2]);
break;
}
}
if (c=='q') {
printf(" QUIT? (y/n) \n");
printf(" %s (y/n) \n",LOCALE_WORDS[3]);
c=getchar();
if (c=='y') {
break;
}
drawBoard(board);
}
if (c=='r') {
printf(" RESTART? (y/n) \n");
printf(" %s (y/n) \n",LOCALE_WORDS[4]);
c=getchar();
if (c=='y') {
initBoard(board);
Expand Down
14 changes: 14 additions & 0 deletions README.md
Expand Up @@ -44,6 +44,20 @@ For the blue-to-red color scheme (requires 256 colors):
./2048 bluered
```

#### Internationalization
The game supports English and Spanish but if you want to have a version in your locale language (and you have your system in that language), you can make your own tranlation. Run:

```
sh include_language_header.sh
```

That creates a file in "languages" directory which you have to edit. Finally compile 2048.c to apply changes:

```
gcc -o 2048 2048.c
./2048
```

### Contributing

Contributions are very welcome. Always run the tests before committing using:
Expand Down
13 changes: 13 additions & 0 deletions README_es.md
Expand Up @@ -44,6 +44,19 @@ Para el esquema de colores de azul a rojo (requiere 256 colores):
./2048 bluered
```

#### Internacionalización
El juego soporta inglés y español pero si quieres tener una versión en tu lenguaje local (y tienes tu sistema en ese lenguaje), puedes hacer tu propia traducción. Corre:

```
sh include_language_header.sh
```
Eso crea un archivo en el directorio "languages" el cual tienes que editar. Finalmente compila 2048.c para aplicar los cambios:

```
gcc -o 2048 2048.c
./2048
```

### Contribuciones

Las contribuciones son siempre bienvenidas. Siempre correr los tests antes de commitear usando:
Expand Down
16 changes: 16 additions & 0 deletions include_language_header.sh
@@ -0,0 +1,16 @@
lang=$(locale | grep LANGUAGE | cut -d= -f2 | cut -d_ -f1)
if test -f language_header.h; then
rm language_header.h
fi

echo "#include \"languages/$lang.h\"" >> language_header.h

if test ! -f languages/$lang.h; then
echo "// To get a translated version of the game replace/translate the words between braces in the same order" >> languages/$lang.h
echo "// and then compile 2048.c (execute \$gcc -o 2048 2048.c)" >> languages/$lang.h
echo "const char * LOCALE_WORDS[] = {\"or\",\"TERMINATED\",\"GAME OVER\",\"QUIT?\",\"RESET?\"};" >> languages/$lang.h
echo "languages/$lang.h file was created. Edit it and then compile 2048.c (execute \$gcc -o 2048 2048.c) to get a traslated version of the game"
fi



1 change: 1 addition & 0 deletions language_header.h
@@ -0,0 +1 @@
#include "languages/en.h"
1 change: 1 addition & 0 deletions languages/en.h
@@ -0,0 +1 @@
const char * LOCALE_WORDS[] = {"or","TERMINATED","GAME OVER","QUIT?","RESET?"};
1 change: 1 addition & 0 deletions languages/es.h
@@ -0,0 +1 @@
const char * LOCALE_WORDS[] = {"o","TERMINADO","FIN DEL JUEGO","¿SALIR?","¿REINICIAR?"};