Skip to content

Commit

Permalink
Add translation support to all text
Browse files Browse the repository at this point in the history
  • Loading branch information
sharkwouter committed Jul 18, 2024
1 parent d31b88c commit 1a59ee5
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 26 deletions.
5 changes: 3 additions & 2 deletions src/BoardManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "Sound.hpp"
#include "colors.hpp"
#include "FontType.hpp"
#include "utils.hpp"

BoardManager::BoardManager(SDL_Renderer *renderer, FontManager *fonts, SoundManager * sounds, OptionManager * options, int x, int y, int width, int height, int moves, int required_matches, int level, int seed) : fonts(fonts), sounds(sounds), options(options),
textures(renderer, options) {
Expand Down Expand Up @@ -586,7 +587,7 @@ void BoardManager::drawInfo(SDL_Renderer * renderer) {
// Generate texture with text
if (this->level_updated) {
std::string str_level = std::to_string(level);
str_level = "level " + str_level;
str_level = _("level ") + str_level;
if (text_level != NULL) {
SDL_DestroyTexture(text_level);
}
Expand All @@ -606,7 +607,7 @@ void BoardManager::drawInfo(SDL_Renderer * renderer) {
}
if (this->moves_updated) {
std::string str_moves = std::to_string(this->moves);
str_moves += " moves";
str_moves += _(" moves");
if (text_moves != NULL) {
SDL_DestroyTexture(text_moves);
}
Expand Down
4 changes: 3 additions & 1 deletion src/states/GameOverState.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#include "GameOverState.hpp"

#include "../utils.hpp"

GameOverState::GameOverState(SDL_Renderer * renderer, FontManager * fonts, SoundManager * sounds, OptionManager * options) :
theme(renderer, options, Theme::MENU),
screen_text(renderer, fonts, options, "Game Over!", "press the confirm button to exit")
screen_text(renderer, fonts, options, _("Game Over!"), _("press the confirm button to exit"))
{
this->renderer = renderer;
this->fonts = fonts;
Expand Down
6 changes: 3 additions & 3 deletions src/states/GameState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@

GameState::GameState(SDL_Renderer * renderer, FontManager * fonts, SoundManager * sounds, OptionManager * options) :
theme(renderer, options, Theme::NONE),
pause_screen(renderer, fonts, options, "Game Paused", "press the confirm button to exit"),
win_screen(renderer, fonts, options, "Level Finished!", "press the confirm button to continue"),
lose_screen(renderer, fonts, options, "Level Failed", "press the confirm button to restart")
pause_screen(renderer, fonts, options, _("Game Paused"), _("press the confirm button to exit")),
win_screen(renderer, fonts, options, _("Level Finished!"), _("press the confirm button to continue")),
lose_screen(renderer, fonts, options, _("Level Failed"), _("press the confirm button to restart"))
{
this->renderer = renderer;
this->fonts = fonts;
Expand Down
9 changes: 5 additions & 4 deletions src/states/GameStateChallenge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
#include <string>
#include "../colors.hpp"
#include "../FontType.hpp"
#include "../utils.hpp"

GameStateChallenge::GameStateChallenge(SDL_Renderer * renderer, FontManager * fonts, SoundManager * sounds, OptionManager * options) :
theme(renderer, options, Theme::NONE),
pause_screen(renderer, fonts, options, "Game Paused", "press the confirm button to exit"),
win_screen(renderer, fonts, options, "Level Finished!", "press the confirm button to continue"),
lose_screen(renderer, fonts, options, "Level Failed", "press the confirm button to restart")
pause_screen(renderer, fonts, options, _("Game Paused"), _("press the confirm button to exit")),
win_screen(renderer, fonts, options, _("Level Finished!"), _("press the confirm button to continue")),
lose_screen(renderer, fonts, options, _("Level Failed"), _("press the confirm button to restart"))
{
this->renderer = renderer;
this->fonts = fonts;
Expand Down Expand Up @@ -108,7 +109,7 @@ void GameStateChallenge::draw(SDL_Renderer *renderer) {

void GameStateChallenge::drawAttempts(SDL_Renderer * renderer) {
if(text_attempts == NULL) {
text_attempts = fonts->getTexture(renderer, "lives left", FontType::NORMAL, {255, 255, 255, 255});
text_attempts = fonts->getTexture(renderer, _("lives left"), FontType::NORMAL, {255, 255, 255, 255});
}
if (this->attempts_changed) {
if (text_attempts_number != NULL) {
Expand Down
4 changes: 3 additions & 1 deletion src/states/GameStateRelaxed.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#include "GameStateRelaxed.hpp"

#include "../utils.hpp"

GameStateRelaxed::GameStateRelaxed(SDL_Renderer * renderer, FontManager * fonts, SoundManager * sounds, OptionManager * options) :
theme(renderer, options, Theme::NONE),
pause_screen(renderer, fonts, options, "Game Paused", "press the confirm button to exit")
pause_screen(renderer, fonts, options, _("Game Paused"), _("press the confirm button to exit"))
{
this->renderer = renderer;
this->fonts = fonts;
Expand Down
13 changes: 7 additions & 6 deletions src/states/HighscoreState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@
#include "../constants.hpp"
#include "../colors.hpp"
#include "../FontType.hpp"
#include "../utils.hpp"
#include "GameState.hpp"

HighscoreState::HighscoreState(SDL_Renderer * renderer, FontManager * fonts, SoundManager * sounds, OptionManager * options) : renderer(renderer), fonts(fonts), sounds(sounds), options(options),
theme(renderer, options, Theme::MENU)
{
this->text_title = fonts->getTexture(renderer, "High Scores", FontType::TITLE, {COLOR_MENU_TITLE.r, COLOR_MENU_TITLE.g, COLOR_MENU_TITLE.b, COLOR_MENU_TITLE.a});
this->text_bottom = fonts->getTexture(renderer, "press confirm to go back", FontType::NORMAL, {255, 255, 255, 255});
this->text_title = fonts->getTexture(renderer, _("High Scores"), FontType::TITLE, {COLOR_MENU_TITLE.r, COLOR_MENU_TITLE.g, COLOR_MENU_TITLE.b, COLOR_MENU_TITLE.a});
this->text_bottom = fonts->getTexture(renderer, _("press confirm to go back"), FontType::NORMAL, {255, 255, 255, 255});

std::string standard_mode_completed = options->getStandardModeCompleted() ? "yes" : "no";
texts.push_back(fonts->getTexture(renderer, "standard mode completed: " + standard_mode_completed, FontType::NORMAL, {255, 255, 255, 255}));
texts.push_back(fonts->getTexture(renderer, "highest level reached in challenge mode: " + std::to_string(options->getChallengeModeHighscore()), FontType::NORMAL, {255, 255, 255, 255}));
texts.push_back(fonts->getTexture(renderer, "matches in relaxed mode: " + std::to_string(options->getRelaxedModeScore()), FontType::NORMAL, {255, 255, 255, 255}));
std::string standard_mode_completed = options->getStandardModeCompleted() ? _("yes") : _("no");
texts.push_back(fonts->getTexture(renderer, _("standard mode completed: ") + standard_mode_completed, FontType::NORMAL, {255, 255, 255, 255}));
texts.push_back(fonts->getTexture(renderer, _("highest level reached in challenge mode: ") + std::to_string(options->getChallengeModeHighscore()), FontType::NORMAL, {255, 255, 255, 255}));
texts.push_back(fonts->getTexture(renderer, _("matches in relaxed mode: ") + std::to_string(options->getRelaxedModeScore()), FontType::NORMAL, {255, 255, 255, 255}));

this->text_start_y = getTextY(0);
}
Expand Down
4 changes: 3 additions & 1 deletion src/states/NotImplementedState.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#include "NotImplementedState.hpp"

#include "../utils.hpp"

NotImplementedState::NotImplementedState(SDL_Renderer * renderer, FontManager * fonts, SoundManager * sounds, OptionManager * options) :
theme(renderer, options, Theme::MENU),
screen_text(renderer, fonts, options, "Not Yet Implemented", "press the confirm button to continue")
screen_text(renderer, fonts, options, _("Not Yet Implemented"), _("press the confirm button to continue"))
{
this->renderer = renderer;
this->fonts = fonts;
Expand Down
14 changes: 7 additions & 7 deletions src/states/OptionsState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ void OptionsState::draw(SDL_Renderer * renderer) {
}

std::string OptionsState::getSoundVolumeString() {
std::string result = "sound volume: ";
std::string result = _("sound volume: ");
for (int i = 0; i < this->options->getSoundVolume(); i++)
{
result += "|";
Expand All @@ -159,7 +159,7 @@ std::string OptionsState::getSoundVolumeString() {
}

std::string OptionsState::getMusicVolumeString() {
std::string result = "music volume: ";
std::string result = _("music volume: ");
for (int i = 0; i < this->options->getMusicVolume(); i++)
{
result += "|";
Expand All @@ -169,15 +169,15 @@ std::string OptionsState::getMusicVolumeString() {
}

std::string OptionsState::getChangeMusicString() {
return "change music upon level switch: " + std::string(this->options->getChangeMusicOnSwitch() ? "yes" : "no");
return _("change music upon level switch: ") + std::string(this->options->getChangeMusicOnSwitch() ? _("yes") : _("no"));
}

std::string OptionsState::getFullscreenString() {
return "full screen: " + std::string(this->options->getFullscreen() ? "yes" : "no");
return _("full screen: ") + std::string(this->options->getFullscreen() ? _("yes") : _("no"));
}

std::string OptionsState::getResolutionString() {
std::string result = "resolution: " + std::to_string(this->options->getScreenWidth()) + "x" + std::to_string(this->options->getScreenHeight());
std::string result = _("resolution: ") + std::to_string(this->options->getScreenWidth()) + "x" + std::to_string(this->options->getScreenHeight());
if (this->options->getScreenRefreshRate() > 0) {
result += " (" + std::to_string(this->options->getScreenRefreshRate()) + " hz)";
}
Expand Down Expand Up @@ -269,7 +269,7 @@ void OptionsState::changeResolution(int amount) {
}

void OptionsState::loadTexts() {
this->text_title = fonts->getTexture(this->renderer, "Options", FontType::TITLE, {COLOR_MENU_TITLE.r, COLOR_MENU_TITLE.g, COLOR_MENU_TITLE.b, COLOR_MENU_TITLE.a});
this->text_title = fonts->getTexture(this->renderer, _("Options"), FontType::TITLE, {COLOR_MENU_TITLE.r, COLOR_MENU_TITLE.g, COLOR_MENU_TITLE.b, COLOR_MENU_TITLE.a});

for (int i = 0; i < (((int) Option::GO_BACK) + 1); i++) {
std::string current_text;
Expand All @@ -292,7 +292,7 @@ void OptionsState::loadTexts() {
break;
#endif
case Option::GO_BACK:
current_text = "return to menu";
current_text = _("return to menu");
break;
default:
current_text = "?????????";
Expand Down
4 changes: 3 additions & 1 deletion src/states/WonState.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#include "WonState.hpp"

#include "../utils.hpp"

WonState::WonState(SDL_Renderer * renderer, FontManager * fonts, SoundManager * sounds, OptionManager * options) :
theme(renderer, options, Theme::MENU),
screen_text(renderer, fonts, options, "Game Mode Completed!", "press the confirm button to exit")
screen_text(renderer, fonts, options, _("Game Mode Completed!"), _("press the confirm button to exit"))
{
this->renderer = renderer;
this->fonts = fonts;
Expand Down

0 comments on commit 1a59ee5

Please sign in to comment.