Make HUD status messages translatable (#5795)

* Make HUD status messages translatable

* Make strings in showStatusTextSimple translatable
This commit is contained in:
Wuzzy 2017-09-05 21:57:29 +02:00 committed by Loïc Blot
parent 87c5a3fb2f
commit f231112cc4
2 changed files with 123 additions and 78 deletions

@ -1323,6 +1323,7 @@ protected:
void showOverlayMessage(const char *msg, float dtime, int percent, void showOverlayMessage(const char *msg, float dtime, int percent,
bool draw_clouds = true); bool draw_clouds = true);
void showStatusTextSimple(const char *msg);
static void settingChangedCallback(const std::string &setting_name, void *data); static void settingChangedCallback(const std::string &setting_name, void *data);
void readSettings(); void readSettings();
@ -2555,25 +2556,29 @@ void Game::processKeyInput()
float volume = g_settings->getFloat("sound_volume"); float volume = g_settings->getFloat("sound_volume");
if (volume < 0.001f) { if (volume < 0.001f) {
g_settings->setFloat("sound_volume", 1.0f); g_settings->setFloat("sound_volume", 1.0f);
m_statustext = narrow_to_wide(gettext("Volume changed to 100%")); showStatusTextSimple("Volume changed to 100%");
} else { } else {
g_settings->setFloat("sound_volume", 0.0f); g_settings->setFloat("sound_volume", 0.0f);
m_statustext = narrow_to_wide(gettext("Volume changed to 0%")); showStatusTextSimple("Volume changed to 0%");
} }
runData.statustext_time = 0; runData.statustext_time = 0;
} else if (wasKeyDown(KeyType::INC_VOLUME)) { } else if (wasKeyDown(KeyType::INC_VOLUME)) {
float new_volume = rangelim(g_settings->getFloat("sound_volume") + 0.1f, 0.0f, 1.0f); float new_volume = rangelim(g_settings->getFloat("sound_volume") + 0.1f, 0.0f, 1.0f);
char buf[100]; wchar_t buf[100];
g_settings->setFloat("sound_volume", new_volume); g_settings->setFloat("sound_volume", new_volume);
snprintf(buf, sizeof(buf), gettext("Volume changed to %d%%"), myround(new_volume * 100)); const wchar_t *str = wgettext("Volume changed to %d%%");
m_statustext = narrow_to_wide(buf); swprintf(buf, sizeof(buf), str, myround(new_volume * 100));
delete[] str;
m_statustext = buf;
runData.statustext_time = 0; runData.statustext_time = 0;
} else if (wasKeyDown(KeyType::DEC_VOLUME)) { } else if (wasKeyDown(KeyType::DEC_VOLUME)) {
float new_volume = rangelim(g_settings->getFloat("sound_volume") - 0.1f, 0.0f, 1.0f); float new_volume = rangelim(g_settings->getFloat("sound_volume") - 0.1f, 0.0f, 1.0f);
char buf[100]; wchar_t buf[100];
g_settings->setFloat("sound_volume", new_volume); g_settings->setFloat("sound_volume", new_volume);
snprintf(buf, sizeof(buf), gettext("Volume changed to %d%%"), myround(new_volume * 100)); const wchar_t *str = wgettext("Volume changed to %d%%");
m_statustext = narrow_to_wide(buf); swprintf(buf, sizeof(buf), str, myround(new_volume * 100));
delete[] str;
m_statustext = buf;
runData.statustext_time = 0; runData.statustext_time = 0;
} else if (wasKeyDown(KeyType::CINEMATIC)) { } else if (wasKeyDown(KeyType::CINEMATIC)) {
toggleCinematic(); toggleCinematic();
@ -2731,15 +2736,20 @@ void Game::handleAndroidChatInput()
void Game::toggleFreeMove() void Game::toggleFreeMove()
{ {
static const wchar_t *msg[] = { L"free_move disabled", L"free_move enabled" };
bool free_move = !g_settings->getBool("free_move"); bool free_move = !g_settings->getBool("free_move");
g_settings->set("free_move", bool_to_cstr(free_move)); g_settings->set("free_move", bool_to_cstr(free_move));
runData.statustext_time = 0; runData.statustext_time = 0;
m_statustext = msg[free_move];
if (free_move && !client->checkPrivilege("fly")) if (free_move) {
m_statustext += L" (note: no 'fly' privilege)"; if (client->checkPrivilege("fly")) {
showStatusTextSimple("Fly mode enabled");
} else {
showStatusTextSimple("Fly mode enabled (note: no 'fly' privilege)");
}
} else {
showStatusTextSimple("Fly mode disabled");
}
} }
@ -2754,17 +2764,20 @@ void Game::toggleFreeMoveAlt()
void Game::toggleFast() void Game::toggleFast()
{ {
static const wchar_t *msg[] = { L"fast_move disabled", L"fast_move enabled" };
bool fast_move = !g_settings->getBool("fast_move"); bool fast_move = !g_settings->getBool("fast_move");
g_settings->set("fast_move", bool_to_cstr(fast_move)); g_settings->set("fast_move", bool_to_cstr(fast_move));
runData.statustext_time = 0; runData.statustext_time = 0;
m_statustext = msg[fast_move];
bool has_fast_privs = client->checkPrivilege("fast"); if (fast_move) {
if (client->checkPrivilege("fast")) {
if (fast_move && !has_fast_privs) showStatusTextSimple("Fast mode enabled");
m_statustext += L" (note: no 'fast' privilege)"; } else {
showStatusTextSimple("Fast mode enabled (note: no 'fast' privilege)");
}
} else {
showStatusTextSimple("Fast mode disabled");
}
#ifdef __ANDROID__ #ifdef __ANDROID__
m_cache_hold_aux1 = fast_move && has_fast_privs; m_cache_hold_aux1 = fast_move && has_fast_privs;
@ -2774,55 +2787,65 @@ void Game::toggleFast()
void Game::toggleNoClip() void Game::toggleNoClip()
{ {
static const wchar_t *msg[] = { L"noclip disabled", L"noclip enabled" };
bool noclip = !g_settings->getBool("noclip"); bool noclip = !g_settings->getBool("noclip");
g_settings->set("noclip", bool_to_cstr(noclip)); g_settings->set("noclip", bool_to_cstr(noclip));
runData.statustext_time = 0; runData.statustext_time = 0;
m_statustext = msg[noclip]; if (noclip) {
if (client->checkPrivilege("noclip")) {
if (noclip && !client->checkPrivilege("noclip")) showStatusTextSimple("Noclip mode enabled");
m_statustext += L" (note: no 'noclip' privilege)"; } else {
showStatusTextSimple("Noclip mode enabled (note: no 'noclip' privilege)");
}
} else {
showStatusTextSimple("Noclip mode disabled");
}
} }
void Game::toggleCinematic() void Game::toggleCinematic()
{ {
static const wchar_t *msg[] = { L"cinematic disabled", L"cinematic enabled" };
bool cinematic = !g_settings->getBool("cinematic"); bool cinematic = !g_settings->getBool("cinematic");
g_settings->set("cinematic", bool_to_cstr(cinematic)); g_settings->set("cinematic", bool_to_cstr(cinematic));
runData.statustext_time = 0; runData.statustext_time = 0;
m_statustext = msg[cinematic]; if (cinematic)
showStatusTextSimple("Cinematic mode enabled");
else
showStatusTextSimple("Cinematic mode disabled");
} }
// Autoforward by toggling continuous forward. // Autoforward by toggling continuous forward.
void Game::toggleAutoforward() void Game::toggleAutoforward()
{ {
static const wchar_t *msg[] = { L"autoforward disabled", L"autoforward enabled" }; bool autorun_enabled = !g_settings->getBool("continuous_forward");
bool autoforward_enabled = !g_settings->getBool("continuous_forward"); g_settings->set("continuous_forward", bool_to_cstr(autorun_enabled));
g_settings->set("continuous_forward", bool_to_cstr(autoforward_enabled));
runData.statustext_time = 0; runData.statustext_time = 0;
m_statustext = msg[autoforward_enabled ? 1 : 0]; if (autorun_enabled)
showStatusTextSimple("Automatic forwards enabled");
else
showStatusTextSimple("Automatic forwards disabled");
} }
void Game::toggleChat() void Game::toggleChat()
{ {
static const wchar_t *msg[] = { L"Chat hidden", L"Chat shown" };
flags.show_chat = !flags.show_chat; flags.show_chat = !flags.show_chat;
runData.statustext_time = 0; runData.statustext_time = 0;
m_statustext = msg[flags.show_chat]; if (flags.show_chat)
showStatusTextSimple("Chat shown");
else
showStatusTextSimple("Chat hidden");
} }
void Game::toggleHud() void Game::toggleHud()
{ {
static const wchar_t *msg[] = { L"HUD hidden", L"HUD shown" };
flags.show_hud = !flags.show_hud; flags.show_hud = !flags.show_hud;
runData.statustext_time = 0; runData.statustext_time = 0;
m_statustext = msg[flags.show_hud]; if (flags.show_hud)
showStatusTextSimple("HUD shown");
else
showStatusTextSimple("HUD hidden");
} }
void Game::toggleMinimap(bool shift_pressed) void Game::toggleMinimap(bool shift_pressed)
@ -2849,28 +2872,30 @@ void Game::toggleMinimap(bool shift_pressed)
flags.show_minimap = true; flags.show_minimap = true;
switch (mode) { switch (mode) {
case MINIMAP_MODE_SURFACEx1: case MINIMAP_MODE_SURFACEx1:
m_statustext = L"Minimap in surface mode, Zoom x1"; showStatusTextSimple("Minimap in surface mode, Zoom x1");
break; break;
case MINIMAP_MODE_SURFACEx2: case MINIMAP_MODE_SURFACEx2:
m_statustext = L"Minimap in surface mode, Zoom x2"; showStatusTextSimple("Minimap in surface mode, Zoom x2");
break; break;
case MINIMAP_MODE_SURFACEx4: case MINIMAP_MODE_SURFACEx4:
m_statustext = L"Minimap in surface mode, Zoom x4"; showStatusTextSimple("Minimap in surface mode, Zoom x4");
break; break;
case MINIMAP_MODE_RADARx1: case MINIMAP_MODE_RADARx1:
m_statustext = L"Minimap in radar mode, Zoom x1"; showStatusTextSimple("Minimap in radar mode, Zoom x1");
break; break;
case MINIMAP_MODE_RADARx2: case MINIMAP_MODE_RADARx2:
m_statustext = L"Minimap in radar mode, Zoom x2"; showStatusTextSimple("Minimap in radar mode, Zoom x2");
break; break;
case MINIMAP_MODE_RADARx4: case MINIMAP_MODE_RADARx4:
m_statustext = L"Minimap in radar mode, Zoom x4"; showStatusTextSimple("Minimap in radar mode, Zoom x4");
break; break;
default: default:
mode = MINIMAP_MODE_OFF; mode = MINIMAP_MODE_OFF;
flags.show_minimap = false; flags.show_minimap = false;
m_statustext = (hud_flags & HUD_FLAG_MINIMAP_VISIBLE) ? if (hud_flags & HUD_FLAG_MINIMAP_VISIBLE)
L"Minimap hidden" : L"Minimap disabled by server"; showStatusTextSimple("Minimap hidden");
else
showStatusTextSimple("Minimap disabled by server");
} }
runData.statustext_time = 0; runData.statustext_time = 0;
@ -2879,11 +2904,12 @@ void Game::toggleMinimap(bool shift_pressed)
void Game::toggleFog() void Game::toggleFog()
{ {
static const wchar_t *msg[] = { L"Fog enabled", L"Fog disabled" };
flags.force_fog_off = !flags.force_fog_off; flags.force_fog_off = !flags.force_fog_off;
runData.statustext_time = 0; runData.statustext_time = 0;
m_statustext = msg[flags.force_fog_off]; if (flags.force_fog_off)
showStatusTextSimple("Fog disabled");
else
showStatusTextSimple("Fog enabled");
} }
@ -2897,22 +2923,22 @@ void Game::toggleDebug()
flags.show_debug = true; flags.show_debug = true;
flags.show_profiler_graph = false; flags.show_profiler_graph = false;
draw_control->show_wireframe = false; draw_control->show_wireframe = false;
m_statustext = L"Debug info shown"; showStatusTextSimple("Debug info shown");
} else if (!flags.show_profiler_graph && !draw_control->show_wireframe) { } else if (!flags.show_profiler_graph && !draw_control->show_wireframe) {
flags.show_profiler_graph = true; flags.show_profiler_graph = true;
m_statustext = L"Profiler graph shown"; showStatusTextSimple("Profiler graph shown");
} else if (!draw_control->show_wireframe && client->checkPrivilege("debug")) { } else if (!draw_control->show_wireframe && client->checkPrivilege("debug")) {
flags.show_profiler_graph = false; flags.show_profiler_graph = false;
draw_control->show_wireframe = true; draw_control->show_wireframe = true;
m_statustext = L"Wireframe shown"; showStatusTextSimple("Wireframe shown");
} else { } else {
flags.show_debug = false; flags.show_debug = false;
flags.show_profiler_graph = false; flags.show_profiler_graph = false;
draw_control->show_wireframe = false; draw_control->show_wireframe = false;
if (client->checkPrivilege("debug")) { if (client->checkPrivilege("debug")) {
m_statustext = L"Debug info, profiler graph, and wireframe hidden"; showStatusTextSimple("Debug info, profiler graph, and wireframe hidden");
} else { } else {
m_statustext = L"Debug info and profiler graph hidden"; showStatusTextSimple("Debug info and profiler graph hidden");
} }
} }
runData.statustext_time = 0; runData.statustext_time = 0;
@ -2921,14 +2947,12 @@ void Game::toggleDebug()
void Game::toggleUpdateCamera() void Game::toggleUpdateCamera()
{ {
static const wchar_t *msg[] = {
L"Camera update enabled",
L"Camera update disabled"
};
flags.disable_camera_update = !flags.disable_camera_update; flags.disable_camera_update = !flags.disable_camera_update;
runData.statustext_time = 0; runData.statustext_time = 0;
m_statustext = msg[flags.disable_camera_update]; if (flags.disable_camera_update)
showStatusTextSimple("Camera update disabled");
else
showStatusTextSimple("Camera update enabled");
} }
@ -2942,12 +2966,15 @@ void Game::toggleProfiler()
runData.profiler_max_page, driver->getScreenSize().Height); runData.profiler_max_page, driver->getScreenSize().Height);
if (runData.profiler_current_page != 0) { if (runData.profiler_current_page != 0) {
std::wstringstream sstr; wchar_t buf[255];
sstr << "Profiler shown (page " << runData.profiler_current_page const wchar_t* str = wgettext("Profiler shown (page %d of %d)");
<< " of " << runData.profiler_max_page << ")"; swprintf(buf, sizeof(buf), str,
m_statustext = sstr.str(); runData.profiler_current_page,
runData.profiler_max_page);
delete[] str;
m_statustext = buf;
} else { } else {
m_statustext = L"Profiler hidden"; showStatusTextSimple("Profiler hidden");
} }
runData.statustext_time = 0; runData.statustext_time = 0;
} }
@ -2958,13 +2985,20 @@ void Game::increaseViewRange()
s16 range = g_settings->getS16("viewing_range"); s16 range = g_settings->getS16("viewing_range");
s16 range_new = range + 10; s16 range_new = range + 10;
wchar_t buf[255];
const wchar_t *str;
if (range_new > 4000) { if (range_new > 4000) {
range_new = 4000; range_new = 4000;
m_statustext = utf8_to_wide("Viewing range is at maximum: " str = wgettext("Viewing range is at maximum: %d");
+ itos(range_new)); swprintf(buf, sizeof(buf), str, range_new);
delete[] str;
m_statustext = buf;
} else { } else {
m_statustext = utf8_to_wide("Viewing range changed to " str = wgettext("Viewing range changed to %d");
+ itos(range_new)); swprintf(buf, sizeof(buf), str, range_new);
delete[] str;
m_statustext = buf;
} }
g_settings->set("viewing_range", itos(range_new)); g_settings->set("viewing_range", itos(range_new));
runData.statustext_time = 0; runData.statustext_time = 0;
@ -2976,13 +3010,19 @@ void Game::decreaseViewRange()
s16 range = g_settings->getS16("viewing_range"); s16 range = g_settings->getS16("viewing_range");
s16 range_new = range - 10; s16 range_new = range - 10;
wchar_t buf[255];
const wchar_t *str;
if (range_new < 20) { if (range_new < 20) {
range_new = 20; range_new = 20;
m_statustext = utf8_to_wide("Viewing range is at minimum: " str = wgettext("Viewing range is at minimum: %d");
+ itos(range_new)); swprintf(buf, sizeof(buf), str, range_new);
delete[] str;
m_statustext = buf;
} else { } else {
m_statustext = utf8_to_wide("Viewing range changed to " str = wgettext("Viewing range changed to %d");
+ itos(range_new)); swprintf(buf, sizeof(buf), str, range_new);
delete[] str;
m_statustext = buf;
} }
g_settings->set("viewing_range", itos(range_new)); g_settings->set("viewing_range", itos(range_new));
runData.statustext_time = 0; runData.statustext_time = 0;
@ -2991,15 +3031,12 @@ void Game::decreaseViewRange()
void Game::toggleFullViewRange() void Game::toggleFullViewRange()
{ {
static const wchar_t *msg[] = {
L"Normal view range",
L"Infinite view range"
};
draw_control->range_all = !draw_control->range_all; draw_control->range_all = !draw_control->range_all;
infostream << msg[draw_control->range_all] << std::endl;
m_statustext = msg[draw_control->range_all];
runData.statustext_time = 0; runData.statustext_time = 0;
if (draw_control->range_all)
showStatusTextSimple("Enabled unlimited viewing range");
else
showStatusTextSimple("Disabled unlimited viewing range");
} }
@ -4558,6 +4595,13 @@ void Game::showOverlayMessage(const char *msg, float dtime, int percent, bool dr
delete[] wmsg; delete[] wmsg;
} }
void Game::showStatusTextSimple(const char *msg)
{
const wchar_t *wmsg = wgettext(msg);
m_statustext = wmsg;
delete[] wmsg;
}
void Game::settingChangedCallback(const std::string &setting_name, void *data) void Game::settingChangedCallback(const std::string &setting_name, void *data)
{ {
((Game *)data)->readSettings(); ((Game *)data)->readSettings();

@ -57,6 +57,7 @@ xgettext --package-name=minetest \
--keyword=fgettext_ne \ --keyword=fgettext_ne \
--keyword=strgettext \ --keyword=strgettext \
--keyword=wstrgettext \ --keyword=wstrgettext \
--keyword=showStatusTextSimple \
--output $potfile \ --output $potfile \
--from-code=utf-8 \ --from-code=utf-8 \
`find src/ -name '*.cpp' -o -name '*.h'` \ `find src/ -name '*.cpp' -o -name '*.h'` \