Skip to content

Commit f231112

Browse files
Wuzzy2nerzhul
authored andcommittedSep 5, 2017
Make HUD status messages translatable (#5795)
* Make HUD status messages translatable * Make strings in showStatusTextSimple translatable
1 parent 87c5a3f commit f231112

File tree

2 files changed

+123
-78
lines changed

2 files changed

+123
-78
lines changed
 

‎src/game.cpp

+122-78
Original file line numberDiff line numberDiff line change
@@ -1323,6 +1323,7 @@ class Game {
13231323

13241324
void showOverlayMessage(const char *msg, float dtime, int percent,
13251325
bool draw_clouds = true);
1326+
void showStatusTextSimple(const char *msg);
13261327

13271328
static void settingChangedCallback(const std::string &setting_name, void *data);
13281329
void readSettings();
@@ -2555,25 +2556,29 @@ void Game::processKeyInput()
25552556
float volume = g_settings->getFloat("sound_volume");
25562557
if (volume < 0.001f) {
25572558
g_settings->setFloat("sound_volume", 1.0f);
2558-
m_statustext = narrow_to_wide(gettext("Volume changed to 100%"));
2559+
showStatusTextSimple("Volume changed to 100%");
25592560
} else {
25602561
g_settings->setFloat("sound_volume", 0.0f);
2561-
m_statustext = narrow_to_wide(gettext("Volume changed to 0%"));
2562+
showStatusTextSimple("Volume changed to 0%");
25622563
}
25632564
runData.statustext_time = 0;
25642565
} else if (wasKeyDown(KeyType::INC_VOLUME)) {
25652566
float new_volume = rangelim(g_settings->getFloat("sound_volume") + 0.1f, 0.0f, 1.0f);
2566-
char buf[100];
2567+
wchar_t buf[100];
25672568
g_settings->setFloat("sound_volume", new_volume);
2568-
snprintf(buf, sizeof(buf), gettext("Volume changed to %d%%"), myround(new_volume * 100));
2569-
m_statustext = narrow_to_wide(buf);
2569+
const wchar_t *str = wgettext("Volume changed to %d%%");
2570+
swprintf(buf, sizeof(buf), str, myround(new_volume * 100));
2571+
delete[] str;
2572+
m_statustext = buf;
25702573
runData.statustext_time = 0;
25712574
} else if (wasKeyDown(KeyType::DEC_VOLUME)) {
25722575
float new_volume = rangelim(g_settings->getFloat("sound_volume") - 0.1f, 0.0f, 1.0f);
2573-
char buf[100];
2576+
wchar_t buf[100];
25742577
g_settings->setFloat("sound_volume", new_volume);
2575-
snprintf(buf, sizeof(buf), gettext("Volume changed to %d%%"), myround(new_volume * 100));
2576-
m_statustext = narrow_to_wide(buf);
2578+
const wchar_t *str = wgettext("Volume changed to %d%%");
2579+
swprintf(buf, sizeof(buf), str, myround(new_volume * 100));
2580+
delete[] str;
2581+
m_statustext = buf;
25772582
runData.statustext_time = 0;
25782583
} else if (wasKeyDown(KeyType::CINEMATIC)) {
25792584
toggleCinematic();
@@ -2731,15 +2736,20 @@ void Game::handleAndroidChatInput()
27312736

27322737
void Game::toggleFreeMove()
27332738
{
2734-
static const wchar_t *msg[] = { L"free_move disabled", L"free_move enabled" };
2735-
27362739
bool free_move = !g_settings->getBool("free_move");
27372740
g_settings->set("free_move", bool_to_cstr(free_move));
27382741

27392742
runData.statustext_time = 0;
2740-
m_statustext = msg[free_move];
2741-
if (free_move && !client->checkPrivilege("fly"))
2742-
m_statustext += L" (note: no 'fly' privilege)";
2743+
2744+
if (free_move) {
2745+
if (client->checkPrivilege("fly")) {
2746+
showStatusTextSimple("Fly mode enabled");
2747+
} else {
2748+
showStatusTextSimple("Fly mode enabled (note: no 'fly' privilege)");
2749+
}
2750+
} else {
2751+
showStatusTextSimple("Fly mode disabled");
2752+
}
27432753
}
27442754

27452755

@@ -2754,17 +2764,20 @@ void Game::toggleFreeMoveAlt()
27542764

27552765
void Game::toggleFast()
27562766
{
2757-
static const wchar_t *msg[] = { L"fast_move disabled", L"fast_move enabled" };
27582767
bool fast_move = !g_settings->getBool("fast_move");
27592768
g_settings->set("fast_move", bool_to_cstr(fast_move));
27602769

27612770
runData.statustext_time = 0;
2762-
m_statustext = msg[fast_move];
2763-
2764-
bool has_fast_privs = client->checkPrivilege("fast");
27652771

2766-
if (fast_move && !has_fast_privs)
2767-
m_statustext += L" (note: no 'fast' privilege)";
2772+
if (fast_move) {
2773+
if (client->checkPrivilege("fast")) {
2774+
showStatusTextSimple("Fast mode enabled");
2775+
} else {
2776+
showStatusTextSimple("Fast mode enabled (note: no 'fast' privilege)");
2777+
}
2778+
} else {
2779+
showStatusTextSimple("Fast mode disabled");
2780+
}
27682781

27692782
#ifdef __ANDROID__
27702783
m_cache_hold_aux1 = fast_move && has_fast_privs;
@@ -2774,55 +2787,65 @@ void Game::toggleFast()
27742787

27752788
void Game::toggleNoClip()
27762789
{
2777-
static const wchar_t *msg[] = { L"noclip disabled", L"noclip enabled" };
27782790
bool noclip = !g_settings->getBool("noclip");
27792791
g_settings->set("noclip", bool_to_cstr(noclip));
27802792

27812793
runData.statustext_time = 0;
2782-
m_statustext = msg[noclip];
2783-
2784-
if (noclip && !client->checkPrivilege("noclip"))
2785-
m_statustext += L" (note: no 'noclip' privilege)";
2794+
if (noclip) {
2795+
if (client->checkPrivilege("noclip")) {
2796+
showStatusTextSimple("Noclip mode enabled");
2797+
} else {
2798+
showStatusTextSimple("Noclip mode enabled (note: no 'noclip' privilege)");
2799+
}
2800+
} else {
2801+
showStatusTextSimple("Noclip mode disabled");
2802+
}
27862803
}
27872804

27882805
void Game::toggleCinematic()
27892806
{
2790-
static const wchar_t *msg[] = { L"cinematic disabled", L"cinematic enabled" };
27912807
bool cinematic = !g_settings->getBool("cinematic");
27922808
g_settings->set("cinematic", bool_to_cstr(cinematic));
27932809

27942810
runData.statustext_time = 0;
2795-
m_statustext = msg[cinematic];
2811+
if (cinematic)
2812+
showStatusTextSimple("Cinematic mode enabled");
2813+
else
2814+
showStatusTextSimple("Cinematic mode disabled");
27962815
}
27972816

27982817
// Autoforward by toggling continuous forward.
27992818
void Game::toggleAutoforward()
28002819
{
2801-
static const wchar_t *msg[] = { L"autoforward disabled", L"autoforward enabled" };
2802-
bool autoforward_enabled = !g_settings->getBool("continuous_forward");
2803-
g_settings->set("continuous_forward", bool_to_cstr(autoforward_enabled));
2820+
bool autorun_enabled = !g_settings->getBool("continuous_forward");
2821+
g_settings->set("continuous_forward", bool_to_cstr(autorun_enabled));
28042822

28052823
runData.statustext_time = 0;
2806-
m_statustext = msg[autoforward_enabled ? 1 : 0];
2824+
if (autorun_enabled)
2825+
showStatusTextSimple("Automatic forwards enabled");
2826+
else
2827+
showStatusTextSimple("Automatic forwards disabled");
28072828
}
28082829

28092830
void Game::toggleChat()
28102831
{
2811-
static const wchar_t *msg[] = { L"Chat hidden", L"Chat shown" };
2812-
28132832
flags.show_chat = !flags.show_chat;
28142833
runData.statustext_time = 0;
2815-
m_statustext = msg[flags.show_chat];
2834+
if (flags.show_chat)
2835+
showStatusTextSimple("Chat shown");
2836+
else
2837+
showStatusTextSimple("Chat hidden");
28162838
}
28172839

28182840

28192841
void Game::toggleHud()
28202842
{
2821-
static const wchar_t *msg[] = { L"HUD hidden", L"HUD shown" };
2822-
28232843
flags.show_hud = !flags.show_hud;
28242844
runData.statustext_time = 0;
2825-
m_statustext = msg[flags.show_hud];
2845+
if (flags.show_hud)
2846+
showStatusTextSimple("HUD shown");
2847+
else
2848+
showStatusTextSimple("HUD hidden");
28262849
}
28272850

28282851
void Game::toggleMinimap(bool shift_pressed)
@@ -2849,28 +2872,30 @@ void Game::toggleMinimap(bool shift_pressed)
28492872
flags.show_minimap = true;
28502873
switch (mode) {
28512874
case MINIMAP_MODE_SURFACEx1:
2852-
m_statustext = L"Minimap in surface mode, Zoom x1";
2875+
showStatusTextSimple("Minimap in surface mode, Zoom x1");
28532876
break;
28542877
case MINIMAP_MODE_SURFACEx2:
2855-
m_statustext = L"Minimap in surface mode, Zoom x2";
2878+
showStatusTextSimple("Minimap in surface mode, Zoom x2");
28562879
break;
28572880
case MINIMAP_MODE_SURFACEx4:
2858-
m_statustext = L"Minimap in surface mode, Zoom x4";
2881+
showStatusTextSimple("Minimap in surface mode, Zoom x4");
28592882
break;
28602883
case MINIMAP_MODE_RADARx1:
2861-
m_statustext = L"Minimap in radar mode, Zoom x1";
2884+
showStatusTextSimple("Minimap in radar mode, Zoom x1");
28622885
break;
28632886
case MINIMAP_MODE_RADARx2:
2864-
m_statustext = L"Minimap in radar mode, Zoom x2";
2887+
showStatusTextSimple("Minimap in radar mode, Zoom x2");
28652888
break;
28662889
case MINIMAP_MODE_RADARx4:
2867-
m_statustext = L"Minimap in radar mode, Zoom x4";
2890+
showStatusTextSimple("Minimap in radar mode, Zoom x4");
28682891
break;
28692892
default:
28702893
mode = MINIMAP_MODE_OFF;
28712894
flags.show_minimap = false;
2872-
m_statustext = (hud_flags & HUD_FLAG_MINIMAP_VISIBLE) ?
2873-
L"Minimap hidden" : L"Minimap disabled by server";
2895+
if (hud_flags & HUD_FLAG_MINIMAP_VISIBLE)
2896+
showStatusTextSimple("Minimap hidden");
2897+
else
2898+
showStatusTextSimple("Minimap disabled by server");
28742899
}
28752900

28762901
runData.statustext_time = 0;
@@ -2879,11 +2904,12 @@ void Game::toggleMinimap(bool shift_pressed)
28792904

28802905
void Game::toggleFog()
28812906
{
2882-
static const wchar_t *msg[] = { L"Fog enabled", L"Fog disabled" };
2883-
28842907
flags.force_fog_off = !flags.force_fog_off;
28852908
runData.statustext_time = 0;
2886-
m_statustext = msg[flags.force_fog_off];
2909+
if (flags.force_fog_off)
2910+
showStatusTextSimple("Fog disabled");
2911+
else
2912+
showStatusTextSimple("Fog enabled");
28872913
}
28882914

28892915

@@ -2897,22 +2923,22 @@ void Game::toggleDebug()
28972923
flags.show_debug = true;
28982924
flags.show_profiler_graph = false;
28992925
draw_control->show_wireframe = false;
2900-
m_statustext = L"Debug info shown";
2926+
showStatusTextSimple("Debug info shown");
29012927
} else if (!flags.show_profiler_graph && !draw_control->show_wireframe) {
29022928
flags.show_profiler_graph = true;
2903-
m_statustext = L"Profiler graph shown";
2929+
showStatusTextSimple("Profiler graph shown");
29042930
} else if (!draw_control->show_wireframe && client->checkPrivilege("debug")) {
29052931
flags.show_profiler_graph = false;
29062932
draw_control->show_wireframe = true;
2907-
m_statustext = L"Wireframe shown";
2933+
showStatusTextSimple("Wireframe shown");
29082934
} else {
29092935
flags.show_debug = false;
29102936
flags.show_profiler_graph = false;
29112937
draw_control->show_wireframe = false;
29122938
if (client->checkPrivilege("debug")) {
2913-
m_statustext = L"Debug info, profiler graph, and wireframe hidden";
2939+
showStatusTextSimple("Debug info, profiler graph, and wireframe hidden");
29142940
} else {
2915-
m_statustext = L"Debug info and profiler graph hidden";
2941+
showStatusTextSimple("Debug info and profiler graph hidden");
29162942
}
29172943
}
29182944
runData.statustext_time = 0;
@@ -2921,14 +2947,12 @@ void Game::toggleDebug()
29212947

29222948
void Game::toggleUpdateCamera()
29232949
{
2924-
static const wchar_t *msg[] = {
2925-
L"Camera update enabled",
2926-
L"Camera update disabled"
2927-
};
2928-
29292950
flags.disable_camera_update = !flags.disable_camera_update;
29302951
runData.statustext_time = 0;
2931-
m_statustext = msg[flags.disable_camera_update];
2952+
if (flags.disable_camera_update)
2953+
showStatusTextSimple("Camera update disabled");
2954+
else
2955+
showStatusTextSimple("Camera update enabled");
29322956
}
29332957

29342958

@@ -2942,12 +2966,15 @@ void Game::toggleProfiler()
29422966
runData.profiler_max_page, driver->getScreenSize().Height);
29432967

29442968
if (runData.profiler_current_page != 0) {
2945-
std::wstringstream sstr;
2946-
sstr << "Profiler shown (page " << runData.profiler_current_page
2947-
<< " of " << runData.profiler_max_page << ")";
2948-
m_statustext = sstr.str();
2969+
wchar_t buf[255];
2970+
const wchar_t* str = wgettext("Profiler shown (page %d of %d)");
2971+
swprintf(buf, sizeof(buf), str,
2972+
runData.profiler_current_page,
2973+
runData.profiler_max_page);
2974+
delete[] str;
2975+
m_statustext = buf;
29492976
} else {
2950-
m_statustext = L"Profiler hidden";
2977+
showStatusTextSimple("Profiler hidden");
29512978
}
29522979
runData.statustext_time = 0;
29532980
}
@@ -2958,13 +2985,20 @@ void Game::increaseViewRange()
29582985
s16 range = g_settings->getS16("viewing_range");
29592986
s16 range_new = range + 10;
29602987

2988+
wchar_t buf[255];
2989+
const wchar_t *str;
29612990
if (range_new > 4000) {
29622991
range_new = 4000;
2963-
m_statustext = utf8_to_wide("Viewing range is at maximum: "
2964-
+ itos(range_new));
2992+
str = wgettext("Viewing range is at maximum: %d");
2993+
swprintf(buf, sizeof(buf), str, range_new);
2994+
delete[] str;
2995+
m_statustext = buf;
2996+
29652997
} else {
2966-
m_statustext = utf8_to_wide("Viewing range changed to "
2967-
+ itos(range_new));
2998+
str = wgettext("Viewing range changed to %d");
2999+
swprintf(buf, sizeof(buf), str, range_new);
3000+
delete[] str;
3001+
m_statustext = buf;
29683002
}
29693003
g_settings->set("viewing_range", itos(range_new));
29703004
runData.statustext_time = 0;
@@ -2976,13 +3010,19 @@ void Game::decreaseViewRange()
29763010
s16 range = g_settings->getS16("viewing_range");
29773011
s16 range_new = range - 10;
29783012

3013+
wchar_t buf[255];
3014+
const wchar_t *str;
29793015
if (range_new < 20) {
29803016
range_new = 20;
2981-
m_statustext = utf8_to_wide("Viewing range is at minimum: "
2982-
+ itos(range_new));
3017+
str = wgettext("Viewing range is at minimum: %d");
3018+
swprintf(buf, sizeof(buf), str, range_new);
3019+
delete[] str;
3020+
m_statustext = buf;
29833021
} else {
2984-
m_statustext = utf8_to_wide("Viewing range changed to "
2985-
+ itos(range_new));
3022+
str = wgettext("Viewing range changed to %d");
3023+
swprintf(buf, sizeof(buf), str, range_new);
3024+
delete[] str;
3025+
m_statustext = buf;
29863026
}
29873027
g_settings->set("viewing_range", itos(range_new));
29883028
runData.statustext_time = 0;
@@ -2991,15 +3031,12 @@ void Game::decreaseViewRange()
29913031

29923032
void Game::toggleFullViewRange()
29933033
{
2994-
static const wchar_t *msg[] = {
2995-
L"Normal view range",
2996-
L"Infinite view range"
2997-
};
2998-
29993034
draw_control->range_all = !draw_control->range_all;
3000-
infostream << msg[draw_control->range_all] << std::endl;
3001-
m_statustext = msg[draw_control->range_all];
30023035
runData.statustext_time = 0;
3036+
if (draw_control->range_all)
3037+
showStatusTextSimple("Enabled unlimited viewing range");
3038+
else
3039+
showStatusTextSimple("Disabled unlimited viewing range");
30033040
}
30043041

30053042

@@ -4558,6 +4595,13 @@ void Game::showOverlayMessage(const char *msg, float dtime, int percent, bool dr
45584595
delete[] wmsg;
45594596
}
45604597

4598+
void Game::showStatusTextSimple(const char *msg)
4599+
{
4600+
const wchar_t *wmsg = wgettext(msg);
4601+
m_statustext = wmsg;
4602+
delete[] wmsg;
4603+
}
4604+
45614605
void Game::settingChangedCallback(const std::string &setting_name, void *data)
45624606
{
45634607
((Game *)data)->readSettings();

‎util/updatepo.sh

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ xgettext --package-name=minetest \
5757
--keyword=fgettext_ne \
5858
--keyword=strgettext \
5959
--keyword=wstrgettext \
60+
--keyword=showStatusTextSimple \
6061
--output $potfile \
6162
--from-code=utf-8 \
6263
`find src/ -name '*.cpp' -o -name '*.h'` \

0 commit comments

Comments
 (0)
Please sign in to comment.