From c44318a253783dde37e3bb688e29927da3b4cac0 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sat, 9 Nov 2019 16:15:05 +0100 Subject: [CSM] Fix and improve minetest.get_language() Previously this method would accidentally reset the locale and break everything. --- src/script/lua_api/l_client.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/script/lua_api') diff --git a/src/script/lua_api/l_client.cpp b/src/script/lua_api/l_client.cpp index fa369a360..4aa7d814d 100644 --- a/src/script/lua_api/l_client.cpp +++ b/src/script/lua_api/l_client.cpp @@ -230,9 +230,14 @@ int ModApiClient::l_get_node_or_nil(lua_State *L) int ModApiClient::l_get_language(lua_State *L) { - char *locale = setlocale(LC_ALL, ""); + char *locale = setlocale(LC_MESSAGES, NULL); + std::string lang = gettext("LANG_CODE"); + if (lang == "LANG_CODE") + lang = ""; + lua_pushstring(L, locale); - return 1; + lua_pushstring(L, lang.c_str()); + return 2; } int ModApiClient::l_get_wielded_item(lua_State *L) -- cgit v1.2.3