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

Added support for i18n with translations in Spanish, Portuguese and I… #17

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ namespace Bastet{
for(int difficulty=0;difficulty<num_difficulties;++difficulty)
for(size_t i=0;i<HowManyHighScores;i++){
highScoresOpts.add_options()
(str(scorer % difficulty % i).c_str(),po::value<string>()->default_value("No one played yet"),"Name of high scorer")
(str(score % difficulty % i).c_str(),po::value<int>()->default_value(0),"High score (points)")
(str(scorer % difficulty % i).c_str(),po::value<string>()->default_value(gettext("No one played yet")),gettext("Name of high scorer"))
(str(score % difficulty % i).c_str(),po::value<int>()->default_value(0),gettext("High score (points)"))
;
}

Expand Down
9 changes: 9 additions & 0 deletions INSTALL
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,12 @@ chmod g+s /usr/local/bin/bastet
touch /var/games/bastet.scores2
chgrp games /var/games/bastet.scores2
chmod 664 /var/games/bastet.scores2


"translations.sh" is a script that iterates an array with the translated languages ​​and in each iteration generates the .mo binary file and copy this into the folder /usr/share/locale/xx_XX/LC_MESSAGES/, where xx_XX is the language in which It was translated.

To change the language of the game,from the console change the value of LANGUAGE for example:

LANGUAGE=es_AR


7 changes: 7 additions & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,10 @@ The game currently allows choosing between two block choosers. The second (harde

==Installation==
See the INSTALL file in this same directory.

==Languages==
This game was translated into Spanish(es_AR),Portuguese(pt_BR) and Italian(it_IT).

==How to make translation files==
See the TRANSLATION file in this same directory.

52 changes: 52 additions & 0 deletions TRANSLATIONS
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
==How to make translation files==

To add translations in other language you need to create a new PO file in the language you want (This file must be saved inside po/pt_BR),
for example to add Portuguese translations from the terminal you must execute the following command:

`msginit -l pt_PT -o main.po -i main.pot`

It first ask for the email of the translator and next generates a file for language chose (here pt_PT)
```
Is the following your email address?

f.poloni_at_gmx.com

Please confirm by pressing Return, or enter your email address.
```
In the header of the new file you can see all the information related to the selected languague and all msgid (Message Identifier) generated from POT file

```
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-05-02 18:18-0300\n"
"PO-Revision-Date: 2018-05-30 19:33-0300\n"
"Last-Translator: Bastet <f.poloni_at_gmx.com>\n"
"Language-Team: Portuguese\n"
"Language: pt\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"

#: main.cpp:47
msgid "Customize keys"
msgstr ""

#: main.cpp:47
msgid "Quit"
msgstr ""
```
Now all you have to do is add the translations in each msgstr
```
#: main.cpp:47
msgid "Customize keys"
msgstr "Personalizar as chaves"

#: main.cpp:47
msgid "Quit"
msgstr "Sair"

Finally, add the language that you translated in the array of languages ​​declared in the translations.sh script.



46 changes: 23 additions & 23 deletions Ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,12 @@ namespace Bastet{

Curses::Curses(){
if(initscr()==NULL){
fprintf(stderr,"bastet: error while initializing graphics (ncurses library).\n");
fprintf(stderr,gettext("bastet: error while initializing graphics (ncurses library).\n"));
exit(1);
}
if(!has_colors()){
endwin();
fprintf(stderr,"bastet: no color support, sorry. Ask the author for a black and white version.");
fprintf(stderr,gettext("bastet: no color support, sorry. Ask the author for a black and white version."));
exit(1);
}

Expand Down Expand Up @@ -278,11 +278,11 @@ namespace Bastet{
void Ui::ChooseLevel(){
RedrawStatic();
int ch='0';
format fmt(" Get ready!\n"
format fmt(gettext(" Get ready!\n"
" \n"
" Starting level = %1% \n"
" 0-9 to change\n"
" <SPACE> to start\n");
" <SPACE> to start\n"));
string msg;
while(ch!=' '){
msg=str(fmt % _level);
Expand All @@ -309,15 +309,15 @@ namespace Bastet{
_scoreWin.RedrawBorder();

wattrset((WINDOW*)_nextWin,COLOR_PAIR(17));
mvwprintw(_nextWin,0,0," Next block:");
mvwprintw(_nextWin,0,0,gettext(" Next block:"));
wrefresh(_nextWin);

wattrset((WINDOW*)_scoreWin,COLOR_PAIR(17));
mvwprintw(_scoreWin,1,0,"Score:");
mvwprintw(_scoreWin,1,0,gettext("Score:"));
wattrset((WINDOW*)_scoreWin,COLOR_PAIR(18));
mvwprintw(_scoreWin,3,0,"Lines:");
mvwprintw(_scoreWin,3,0,gettext("Lines:"));
wattrset((WINDOW*)_scoreWin,COLOR_PAIR(19));
mvwprintw(_scoreWin,5,0,"Level:");
mvwprintw(_scoreWin,5,0,gettext("Level:"));
wrefresh(_scoreWin);
}

Expand Down Expand Up @@ -376,7 +376,7 @@ namespace Bastet{
break;
}
else if(ch==keys->Pause){
MessageDialog("Press SPACE or ENTER to resume the game");
MessageDialog(gettext("Press SPACE or ENTER to resume the game"));
RedrawStatic();
RedrawWell(w,b,p);
nodelay(stdscr,TRUE);
Expand Down Expand Up @@ -512,24 +512,24 @@ namespace Bastet{
void Ui::HandleHighScores(difficulty_t diff){
HighScores *hs=config.GetHighScores(diff);
if(hs->Qualifies(_points)){
string name=InputDialog(" Congratulations! You got a high score \n Please enter your name");
string name=InputDialog(gettext(" Congratulations! You got a high score \n Please enter your name"));
hs->InsertHighScore(_points,name);
}else{
MessageDialog("You did not get into\n"
MessageDialog(gettext("You did not get into\n"
"the high score list!\n"
"\n"
" Try again!\n"
);
));
}
}

void Ui::ShowHighScores(difficulty_t diff){
HighScores *hs=config.GetHighScores(diff);
string allscores;
if(diff==difficulty_normal)
allscores+="**Normal difficulty**\n";
allscores+=gettext("**Normal difficulty**\n");
else if(diff==difficulty_hard)
allscores+="**Hard difficulty**\n";
allscores+=gettext("**Hard difficulty**\n");
format fmt("%-20.20s %8d\n");
for(HighScores::reverse_iterator it=hs->rbegin();it!=hs->rend();++it){
allscores+=str(fmt % it->Scorer % it->Score);
Expand All @@ -540,14 +540,14 @@ namespace Bastet{
void Ui::CustomizeKeys(){
Keys *keys=config.GetKeys();
format fmt(
"Press the key you wish to use for:\n\n"
"%=1.34s\n\n");
keys->Down=KeyDialog(str(fmt % "move tetromino DOWN (soft-drop)"));
keys->Left=KeyDialog(str(fmt % "move tetromino LEFT"));
keys->Right=KeyDialog(str(fmt % "move tetromino RIGHT"));
keys->RotateCW=KeyDialog(str(fmt % "rotate tetromino CLOCKWISE"));
keys->RotateCCW=KeyDialog(str(fmt % "rotate tetromino COUNTERCLOCKWISE"));
keys->Drop=KeyDialog(str(fmt % "DROP tetromino (move down as much as possible immediately)"));
keys->Pause=KeyDialog(str(fmt % "PAUSE the game"));
gettext("Press the key you wish to use for:\n\n"
"%=1.34s\n\n"));
keys->Down=KeyDialog(str(fmt % gettext("move tetromino DOWN (soft-drop)")));
keys->Left=KeyDialog(str(fmt % gettext("move tetromino LEFT")));
keys->Right=KeyDialog(str(fmt % gettext("move tetromino RIGHT")));
keys->RotateCW=KeyDialog(str(fmt % gettext("rotate tetromino CLOCKWISE")));
keys->RotateCCW=KeyDialog(str(fmt % gettext("rotate tetromino COUNTERCLOCKWISE")));
keys->Drop=KeyDialog(str(fmt % gettext("DROP tetromino (move down as much as possible immediately)")));
keys->Pause=KeyDialog(str(fmt % gettext("PAUSE the game")));
}
}
6 changes: 4 additions & 2 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ using namespace boost::assign;

int main(int argc, char **argv){
Ui ui;
setlocale(LC_ALL, "");
bindtextdomain("main", "/usr/share/locale/");
textdomain("main");
while(1){

int choice=ui.MenuDialog(list_of("Play! (normal version)")("Play! (harder version)")("View highscores")("Customize keys")("Quit"));
int choice=ui.MenuDialog(list_of(gettext("Play! (normal version)"))(gettext("Play! (harder version)"))(gettext("View highscores"))(gettext("Customize keys"))(gettext("Quit")));
switch(choice){
case 0:{
//ui.ChooseLevel();
Expand Down
165 changes: 165 additions & 0 deletions po/es_AR/main.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
# Spanish translations for PACKAGE package.
# Copyright (C) 2018 THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# Bastet <[email protected]>, 2018.
#
msgid ""
msgstr ""
"Project-Id-Version: 0.43.1\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-05-02 18:18-0300\n"
"PO-Revision-Date: 2018-05-02 18:19-0300\n"
"Last-Translator: Bastet <[email protected]>\n"
"Language-Team: Spanish\n"
"Language: es_Es\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"

#: main.cpp:47
msgid "Customize keys"
msgstr "Personalizar teclas"

#: main.cpp:47
msgid "Quit"
msgstr "Salir"

#: main.cpp:47
msgid "Play! (harder version)"
msgstr "¡Juega! (Versión más difícil)"

#: main.cpp:47
msgid "Play! (normal version)"
msgstr "¡Juega! (Versión normal)"

#: main.cpp:47
msgid "View highscores"
msgstr "Ver puntuaciones altas"

#: Ui.cpp:281
msgid ""
" Get ready!\n"
" \n"
" Starting level = %1% \n"
" 0-9 to change\n"
" <SPACE> to start\n"
msgstr ""
" Preparate!\n"
" \n"
" Nivel inicial = %1% \n"
" 0-9 to change\n"
" <ESPACIO> para comenzar\n"

#: Ui.cpp:515
msgid ""
" Congratulations! You got a high score \n"
" Please enter your name"
msgstr ""
" Felicitaciones! Has obtenido un puntaje alto \n"
" Por favor ingrese su nombre"

#: Ui.cpp:312
msgid " Next block:"
msgstr " Siguiente:"

#: Ui.cpp:532
msgid "**Hard difficulty**\n"
msgstr "**Dificultad difíci**\n"

#: Ui.cpp:530
msgid "**Normal difficulty**\n"
msgstr "**Dificultad normal**\n"

#: Ui.cpp:550
msgid "DROP tetromino (move down as much as possible immediately)"
msgstr "Soltar figura inmediatamente"

#: Ui.cpp:320
msgid "Level:"
msgstr "Nivel:"

#: Ui.cpp:318
msgid "Lines:"
msgstr "Líneas:"

#: Ui.cpp:551
msgid "PAUSE the game"
msgstr "Pause el juego"

#: Ui.cpp:379
msgid "Press SPACE or ENTER to resume the game"
msgstr "Presione ESPACIO o INICIO"

#: Ui.cpp:543
msgid ""
"Press the key you wish to use for:\n"
"\n"
"%=1.34s\n"
"\n"
msgstr ""
"Presiona la tecla que quieres usar para:\n"
"\n"
"%=1.34s\n"
"\n"

#: Ui.cpp:316
msgid "Score:"
msgstr "Puntos:"

#: Ui.cpp:518
msgid ""
"You did not get into\n"
"the high score list!\n"
"\n"
" Try again!\n"
msgstr ""
"No ingresaste a la lista de puntajes altos!\n"
"\n"
" Inténtalo nuevamente\n"

#: Ui.cpp:115
#, c-format
msgid "bastet: error while initializing graphics (ncurses library).\n"
msgstr "baster: error al inciar los gráficos (biblioteca ncurses).\n"

#: Ui.cpp:120
#, c-format
msgid ""
"bastet: no color support, sorry. Ask the author for a black and white "
"version."
msgstr ""
"bastet: no hay soporte de color, lo siento. Pídale una versión en blanco y "
"negro al autor"

#: Ui.cpp:545
msgid "move tetromino DOWN (soft-drop)"
msgstr "mover figura ABAJO (caida-suave)"

#: Ui.cpp:546
msgid "move tetromino LEFT"
msgstr "mover figura a la IZQUIERDA"

#: Ui.cpp:547
msgid "move tetromino RIGHT"
msgstr "mover figura a la DERECHA"

#: Ui.cpp:548
msgid "rotate tetromino CLOCKWISE"
msgstr "rotar figura en sentido aL RELOJ"

#: Ui.cpp:549
msgid "rotate tetromino COUNTERCLOCKWISE"
msgstr "rotar figura en sentido contrario al RELOJ"

#: Config.cpp:121
msgid "No one played yet"
msgstr "Nadie jugó todavía"

#: Config.cpp:121
msgid "Name of high scorer"
msgstr "Nombre del máximo anotador"

#: Config.cpp:122
msgid "High score (points)"
msgstr "Puntuación alta (puntos)"
Loading