1
0
mirror of https://github.com/minetest/minetest.git synced 2025-07-06 01:40:21 +02:00

Add server side translations capability (#9733)

* Add server side translations capability
This commit is contained in:
EvidenceB Kidscode
2020-04-25 07:20:00 +02:00
committed by GitHub
parent 914dbeaa0b
commit cee3c5e73d
14 changed files with 126 additions and 18 deletions

View File

@ -64,6 +64,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "chat_interface.h"
#include "remoteplayer.h"
#include "server/player_sao.h"
#include "translation.h"
class ClientNotFoundException : public BaseException
{
@ -1266,7 +1267,8 @@ bool Server::getClientInfo(
u8* major,
u8* minor,
u8* patch,
std::string* vers_string
std::string* vers_string,
std::string* lang_code
)
{
*state = m_clients.getClientState(peer_id);
@ -1286,6 +1288,7 @@ bool Server::getClientInfo(
*minor = client->getMinor();
*patch = client->getPatch();
*vers_string = client->getFull();
*lang_code = client->getLangCode();
m_clients.unlock();
@ -3937,3 +3940,20 @@ void Server::broadcastModChannelMessage(const std::string &channel,
m_script->on_modchannel_message(channel, sender, message);
}
}
void Server::loadTranslationLanguage(const std::string &lang_code)
{
if (g_server_translations->count(lang_code))
return; // Already loaded
std::string suffix = "." + lang_code + ".tr";
for (const auto &i : m_media) {
if (str_ends_with(i.first, suffix)) {
std::ifstream t(i.second.path);
std::string data((std::istreambuf_iterator<char>(t)),
std::istreambuf_iterator<char>());
(*g_server_translations)[lang_code].loadTranslation(data);
}
}
}