diff options
author | sfan5 <sfan5@live.de> | 2019-11-09 16:15:05 +0100 |
---|---|---|
committer | sfan5 <sfan5@live.de> | 2019-11-11 14:06:48 +0100 |
commit | c44318a253783dde37e3bb688e29927da3b4cac0 (patch) | |
tree | 67cd18e68ed0b9aa6a3d0182a6e44928c6fdafd5 | |
parent | 2c4cf508a9b94a76ce2ca7c7317258471a41c51d (diff) | |
download | minetest-c44318a253783dde37e3bb688e29927da3b4cac0.tar.gz minetest-c44318a253783dde37e3bb688e29927da3b4cac0.tar.bz2 minetest-c44318a253783dde37e3bb688e29927da3b4cac0.zip |
[CSM] Fix and improve minetest.get_language()
Previously this method would accidentally reset the locale
and break everything.
-rw-r--r-- | clientmods/preview/init.lua | 17 | ||||
-rw-r--r-- | doc/client_lua_api.txt | 4 | ||||
-rw-r--r-- | src/script/lua_api/l_client.cpp | 9 |
3 files changed, 21 insertions, 9 deletions
diff --git a/clientmods/preview/init.lua b/clientmods/preview/init.lua index 2e679b866..5777adcaf 100644 --- a/clientmods/preview/init.lua +++ b/clientmods/preview/init.lua @@ -9,13 +9,18 @@ core.register_on_shutdown(function() end) local id = nil -local server_info = core.get_server_info() -print("Server version: " .. server_info.protocol_version) -print("Server ip: " .. server_info.ip) -print("Server address: " .. server_info.address) -print("Server port: " .. server_info.port) +do + local server_info = core.get_server_info() + print("Server version: " .. server_info.protocol_version) + print("Server ip: " .. server_info.ip) + print("Server address: " .. server_info.address) + print("Server port: " .. server_info.port) -print("CSM restrictions: " .. dump(core.get_csm_restrictions())) + print("CSM restrictions: " .. dump(core.get_csm_restrictions())) + + local l1, l2 = core.get_language() + print("Configured language: " .. l1 .. " / " .. l2) +end mod_channel = core.mod_channel_join("experimental_preview") diff --git a/doc/client_lua_api.txt b/doc/client_lua_api.txt index a7e928f56..c24de8d85 100644 --- a/doc/client_lua_api.txt +++ b/doc/client_lua_api.txt @@ -634,7 +634,9 @@ Minetest namespace reference the trailing separator. This is useful to load additional Lua files contained in your mod: e.g. `dofile(minetest.get_modpath(minetest.get_current_modname()) .. "stuff.lua")` -* `minetest.get_language()`: returns the currently set gettext language. +* `minetest.get_language()`: returns two strings + * the current gettext locale + * the current language code (the same as used for client-side translations) * `minetest.get_version()`: returns a table containing components of the engine version. Components: * `project`: Name of the project, eg, "Minetest" 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) |