Skip to content
Permalink
Browse files

Remove wstrgettext

Everywhere where wstrgettext was used, its output was converted back
to utf8. As wstrgettext internally converts the return value
from utf8 to wstring, it has been a waste. Remove the function, and
use strgettext instead.
  • Loading branch information
est31 committed Oct 18, 2015
1 parent f3d8256 commit 6b0cae5a9d6e220b9f1ecf8e6a821d84961564fd
Showing with 34 additions and 42 deletions.
  1. +32 −32 src/game.cpp
  2. +0 −8 src/gettext.h
  3. +2 −2 src/script/lua_api/l_mainmenu.cpp
@@ -1048,7 +1048,7 @@ static void show_chat_menu(GUIFormSpecMenu **cur_formspec,
FORMSPEC_VERSION_STRING
SIZE_TAG
"field[3,2.35;6,0.5;f_text;;" + text + "]"
"button_exit[4,3;3,0.5;btn_send;" + wide_to_utf8(wstrgettext("Proceed")) + "]"
"button_exit[4,3;3,0.5;btn_send;" + strgettext("Proceed") + "]"
;

/* Create menu */
@@ -1088,56 +1088,56 @@ static void show_pause_menu(GUIFormSpecMenu **cur_formspec,
bool singleplayermode)
{
#ifdef __ANDROID__
std::string control_text = wide_to_utf8(wstrgettext("Default Controls:\n"
"No menu visible:\n"
"- single tap: button activate\n"
"- double tap: place/use\n"
"- slide finger: look around\n"
"Menu/Inventory visible:\n"
"- double tap (outside):\n"
" -->close\n"
"- touch stack, touch slot:\n"
" --> move stack\n"
"- touch&drag, tap 2nd finger\n"
" --> place single item to slot\n"
));
std::string control_text = strgettext("Default Controls:\n"
"No menu visible:\n"
"- single tap: button activate\n"
"- double tap: place/use\n"
"- slide finger: look around\n"
"Menu/Inventory visible:\n"
"- double tap (outside):\n"
" -->close\n"
"- touch stack, touch slot:\n"
" --> move stack\n"
"- touch&drag, tap 2nd finger\n"
" --> place single item to slot\n"
);
#else
std::string control_text = wide_to_utf8(wstrgettext("Default Controls:\n"
"- WASD: move\n"
"- Space: jump/climb\n"
"- Shift: sneak/go down\n"
"- Q: drop item\n"
"- I: inventory\n"
"- Mouse: turn/look\n"
"- Mouse left: dig/punch\n"
"- Mouse right: place/use\n"
"- Mouse wheel: select item\n"
"- T: chat\n"
));
std::string control_text = strgettext("Default Controls:\n"
"- WASD: move\n"
"- Space: jump/climb\n"
"- Shift: sneak/go down\n"
"- Q: drop item\n"
"- I: inventory\n"
"- Mouse: turn/look\n"
"- Mouse left: dig/punch\n"
"- Mouse right: place/use\n"
"- Mouse wheel: select item\n"
"- T: chat\n"
);
#endif

float ypos = singleplayermode ? 0.5 : 0.1;
std::ostringstream os;

os << FORMSPEC_VERSION_STRING << SIZE_TAG
<< "button_exit[4," << (ypos++) << ";3,0.5;btn_continue;"
<< wide_to_utf8(wstrgettext("Continue")) << "]";
<< strgettext("Continue") << "]";

if (!singleplayermode) {
os << "button_exit[4," << (ypos++) << ";3,0.5;btn_change_password;"
<< wide_to_utf8(wstrgettext("Change Password")) << "]";
<< strgettext("Change Password") << "]";
}

#ifndef __ANDROID__
os << "button_exit[4," << (ypos++) << ";3,0.5;btn_sound;"
<< wide_to_utf8(wstrgettext("Sound Volume")) << "]";
<< strgettext("Sound Volume") << "]";
os << "button_exit[4," << (ypos++) << ";3,0.5;btn_key_config;"
<< wide_to_utf8(wstrgettext("Change Keys")) << "]";
<< strgettext("Change Keys") << "]";
#endif
os << "button_exit[4," << (ypos++) << ";3,0.5;btn_exit_menu;"
<< wide_to_utf8(wstrgettext("Exit to Menu")) << "]";
<< strgettext("Exit to Menu") << "]";
os << "button_exit[4," << (ypos++) << ";3,0.5;btn_exit_os;"
<< wide_to_utf8(wstrgettext("Exit to OS")) << "]"
<< strgettext("Exit to OS") << "]"
<< "textarea[7.5,0.25;3.9,6.25;;" << control_text << ";]"
<< "textarea[0.4,0.25;3.5,6;;" << PROJECT_NAME_C "\n"
<< g_build_info << "\n"
@@ -48,14 +48,6 @@ inline const wchar_t *wgettext(const char *str)
return utf8_to_wide_c(gettext(str));
}

inline std::wstring wstrgettext(const std::string &text)
{
const wchar_t *tmp = wgettext(text.c_str());
std::wstring retval = (std::wstring)tmp;
delete[] tmp;
return retval;
}

inline std::string strgettext(const std::string &text)
{
return gettext(text.c_str());
@@ -1059,8 +1059,8 @@ int ModApiMainMenu::l_get_video_modes(lua_State *L)
/******************************************************************************/
int ModApiMainMenu::l_gettext(lua_State *L)
{
std::wstring wtext = wstrgettext((std::string) luaL_checkstring(L, 1));
lua_pushstring(L, wide_to_utf8(wtext).c_str());
std::string text = strgettext(std::string(luaL_checkstring(L, 1)));
lua_pushstring(L, text.c_str());

return 1;
}

0 comments on commit 6b0cae5

Please sign in to comment.