summaryrefslogtreecommitdiff
path: root/src/script
diff options
context:
space:
mode:
authorEvidenceB Kidscode <49488517+EvidenceBKidscode@users.noreply.github.com>2020-04-25 07:20:00 +0200
committerGitHub <noreply@github.com>2020-04-25 07:20:00 +0200
commitcee3c5e73d7af2a876aa76275234ee76e7cb1bbc (patch)
tree66abf52902be5c4d7ccc7aa40d20ed77a2a263e0 /src/script
parent914dbeaa0be4b5ef87506b605ef4e241cd3732dc (diff)
downloadminetest-cee3c5e73d7af2a876aa76275234ee76e7cb1bbc.tar.gz
minetest-cee3c5e73d7af2a876aa76275234ee76e7cb1bbc.tar.bz2
minetest-cee3c5e73d7af2a876aa76275234ee76e7cb1bbc.zip
Add server side translations capability (#9733)
* Add server side translations capability
Diffstat (limited to 'src/script')
-rw-r--r--src/script/lua_api/l_env.cpp16
-rw-r--r--src/script/lua_api/l_env.h3
-rw-r--r--src/script/lua_api/l_server.cpp7
3 files changed, 25 insertions, 1 deletions
diff --git a/src/script/lua_api/l_env.cpp b/src/script/lua_api/l_env.cpp
index 831464d3b..3fb58b8c8 100644
--- a/src/script/lua_api/l_env.cpp
+++ b/src/script/lua_api/l_env.cpp
@@ -40,6 +40,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "remoteplayer.h"
#include "server/luaentity_sao.h"
#include "server/player_sao.h"
+#include "util/string.h"
+#include "translation.h"
#ifndef SERVER
#include "client/client.h"
#endif
@@ -1302,6 +1304,19 @@ int ModApiEnvMod::l_forceload_free_block(lua_State *L)
return 0;
}
+// get_translated_string(lang_code, string)
+int ModApiEnvMod::l_get_translated_string(lua_State * L)
+{
+ GET_ENV_PTR;
+ std::string lang_code = luaL_checkstring(L, 1);
+ std::string string = luaL_checkstring(L, 2);
+ getServer(L)->loadTranslationLanguage(lang_code);
+ string = wide_to_utf8(translate_string(utf8_to_wide(string),
+ &(*g_server_translations)[lang_code]));
+ lua_pushstring(L, string.c_str());
+ return 1;
+}
+
void ModApiEnvMod::Initialize(lua_State *L, int top)
{
API_FCT(set_node);
@@ -1349,6 +1364,7 @@ void ModApiEnvMod::Initialize(lua_State *L, int top)
API_FCT(transforming_liquid_add);
API_FCT(forceload_block);
API_FCT(forceload_free_block);
+ API_FCT(get_translated_string);
}
void ModApiEnvMod::InitializeClient(lua_State *L, int top)
diff --git a/src/script/lua_api/l_env.h b/src/script/lua_api/l_env.h
index ac2f8b588..9050b4306 100644
--- a/src/script/lua_api/l_env.h
+++ b/src/script/lua_api/l_env.h
@@ -187,6 +187,9 @@ private:
// stops forceloading a position
static int l_forceload_free_block(lua_State *L);
+ // Get a string translated server side
+ static int l_get_translated_string(lua_State * L);
+
public:
static void Initialize(lua_State *L, int top);
static void InitializeClient(lua_State *L, int top);
diff --git a/src/script/lua_api/l_server.cpp b/src/script/lua_api/l_server.cpp
index 00e849cdf..7137484e8 100644
--- a/src/script/lua_api/l_server.cpp
+++ b/src/script/lua_api/l_server.cpp
@@ -163,6 +163,7 @@ int ModApiServer::l_get_player_information(lua_State *L)
u16 prot_vers;
u8 ser_vers,major,minor,patch;
std::string vers_string;
+ std::string lang_code;
#define ERET(code) \
if (!(code)) { \
@@ -182,7 +183,7 @@ int ModApiServer::l_get_player_information(lua_State *L)
&avg_jitter))
ERET(getServer(L)->getClientInfo(player->getPeerId(), &state, &uptime, &ser_vers,
- &prot_vers, &major, &minor, &patch, &vers_string))
+ &prot_vers, &major, &minor, &patch, &vers_string, &lang_code))
lua_newtable(L);
int table = lua_gettop(L);
@@ -237,6 +238,10 @@ int ModApiServer::l_get_player_information(lua_State *L)
lua_pushnumber(L, player->formspec_version);
lua_settable(L, table);
+ lua_pushstring(L, "lang_code");
+ lua_pushstring(L, lang_code.c_str());
+ lua_settable(L, table);
+
#ifndef NDEBUG
lua_pushstring(L,"serialization_version");
lua_pushnumber(L, ser_vers);