Support multilang, update code

Signed-off-by: R4SAS <r4sas@i2pmail.org>
This commit is contained in:
R4SAS 2021-05-22 18:29:05 +03:00
parent 0e68fe4a57
commit 80b44fc9a9
No known key found for this signature in database
GPG key ID: 66F6C87B98EBCFE2
10 changed files with 124 additions and 28 deletions

View file

@ -93,6 +93,7 @@ namespace config {
("http.strictheaders", value<bool>()->default_value(true), "Enable strict host checking on WebUI")
("http.hostname", value<std::string>()->default_value("localhost"), "Expected hostname for WebUI")
("http.webroot", value<std::string>()->default_value("/"), "WebUI root path (default: / )")
("http.lang", value<std::string>()->default_value("english"), "WebUI language (default: english )")
;
options_description httpproxy("HTTP Proxy options");

View file

@ -12,6 +12,7 @@
#ifdef _WIN32
#include <shlobj.h>
#include <windows.h>
#include <codecvt>
#endif
#include "Base.h"
@ -41,6 +42,18 @@ namespace fs {
return dataDir;
}
const std::string GetUTF8DataDir () {
#ifdef _WIN32
boost::filesystem::wpath path (dataDir);
auto loc = boost::filesystem::path::imbue(std::locale( std::locale(), new std::codecvt_utf8_utf16<wchar_t>() ) ); // convert path to UTF-8
auto dataDirUTF8 = path.string();
boost::filesystem::path::imbue(loc); // Return locale settings back
return dataDirUTF8;
#else
return dataDir; // linux, osx, android uses UTF-8 by default
#endif
}
void DetectDataDir(const std::string & cmdline_param, bool isService) {
if (cmdline_param != "") {
dataDir = cmdline_param;

View file

@ -75,6 +75,9 @@ namespace fs {
/** @brief Returns datadir path */
const std::string & GetDataDir();
/** @brief Returns datadir path in UTF-8 encoding */
const std::string GetUTF8DataDir();
/**
* @brief Set datadir either from cmdline option or using autodetection
* @param cmdline_param Value of cmdline parameter --datadir=<something>

View file

@ -29,7 +29,7 @@ namespace i2p
RouterContext::RouterContext ():
m_LastUpdateTime (0), m_AcceptsTunnels (true), m_IsFloodfill (false),
m_ShareRatio (100), m_Status (eRouterStatusUnknown), m_StatusV6 (eRouterStatusUnknown),
m_Error (eRouterErrorNone), m_NetID (I2PD_NET_ID)
m_Error (eRouterErrorNone), m_NetID (I2PD_NET_ID), m_Language (eEnglish)
{
}
@ -916,6 +916,11 @@ namespace i2p
}
}
void RouterContext::SetLanguage (Lang language)
{
m_Language = language;
}
i2p::crypto::X25519Keys& RouterContext::GetStaticKeys ()
{
if (!m_StaticKeys)

View file

@ -24,7 +24,7 @@ namespace i2p
namespace garlic
{
class RouterIncomingRatchetSession;
}
}
const char ROUTER_INFO[] = "router.info";
const char ROUTER_KEYS[] = "router.keys";
@ -39,7 +39,7 @@ namespace garlic
eRouterStatusError = 3,
eRouterStatusUnknown = 4,
eRouterStatusProxy = 5,
eRouterStatusMesh = 6
eRouterStatusMesh = 6
};
enum RouterError
@ -49,7 +49,12 @@ namespace garlic
eRouterErrorOffline = 2,
eRouterErrorSymmetricNAT = 3
};
enum Lang {
eEnglish = 0,
eRussian
};
class RouterContext: public i2p::garlic::GarlicDestination
{
private:
@ -144,6 +149,10 @@ namespace garlic
void ProcessGarlicMessage (std::shared_ptr<I2NPMessage> msg);
void ProcessDeliveryStatusMessage (std::shared_ptr<I2NPMessage> msg);
// i18n
Lang GetLanguage () const { return m_Language; };
void SetLanguage (Lang language);
protected:
// implements GarlicDestination
@ -178,6 +187,9 @@ namespace garlic
std::unique_ptr<i2p::crypto::X25519Keys> m_StaticKeys;
// for ECIESx25519
std::unique_ptr<i2p::crypto::NoiseSymmetricState> m_InitialNoiseState, m_CurrentNoiseState;
// i18n
Lang m_Language;
};
extern RouterContext context;