Merge pull request #1657 from PurpleI2P/i18n

I18n
This commit is contained in:
orignal 2021-05-23 08:26:11 -04:00 committed by GitHub
commit 7ed440ba75
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 717 additions and 267 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,16 +42,28 @@ 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;
return;
}
#ifdef _WIN32
char localAppData[MAX_PATH];
wchar_t localAppData[MAX_PATH];
// check executable directory first
if(!GetModuleFileName(NULL, localAppData, MAX_PATH))
if(!GetModuleFileNameW(NULL, localAppData, MAX_PATH))
{
#ifdef WIN32_APP
MessageBox(NULL, TEXT("Unable to get application path!"), TEXT("I2Pd: error"), MB_ICONERROR | MB_OK);
@ -61,14 +74,15 @@ namespace fs {
}
else
{
auto execPath = boost::filesystem::path(localAppData).parent_path();
auto execPath = boost::filesystem::wpath(localAppData).parent_path();
// if config file exists in .exe's folder use it
if(boost::filesystem::exists(execPath/"i2pd.conf")) // TODO: magic string
dataDir = execPath.string ();
else // otherwise %appdata%
{
if(SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, 0, localAppData) != S_OK)
dataDir = execPath.string ();
} else // otherwise %appdata%
{
if(SHGetFolderPathW(NULL, CSIDL_APPDATA, NULL, 0, localAppData) != S_OK)
{
#ifdef WIN32_APP
MessageBox(NULL, TEXT("Unable to get AppData path!"), TEXT("I2Pd: error"), MB_ICONERROR | MB_OK);
@ -78,7 +92,9 @@ namespace fs {
exit(1);
}
else
dataDir = std::string(localAppData) + "\\" + appName;
{
dataDir = boost::filesystem::wpath(localAppData).string() + "\\" + appName;
}
}
}
return;

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

@ -187,6 +187,8 @@ namespace http
params.clear();
for (const auto& it : tokens) {
if (!it.length()) // empty
continue;
std::size_t eq = it.find ('=');
if (eq != std::string::npos) {
auto e = std::pair<std::string, std::string>(it.substr(0, eq), it.substr(eq + 1));

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

@ -18,13 +18,14 @@
#include "Identity.h"
#include "RouterInfo.h"
#include "Garlic.h"
#include "I18N_langs.h"
namespace i2p
{
namespace garlic
{
class RouterIncomingRatchetSession;
}
}
const char ROUTER_INFO[] = "router.info";
const char ROUTER_KEYS[] = "router.keys";
@ -39,7 +40,7 @@ namespace garlic
eRouterStatusError = 3,
eRouterStatusUnknown = 4,
eRouterStatusProxy = 5,
eRouterStatusMesh = 6
eRouterStatusMesh = 6
};
enum RouterError
@ -49,7 +50,7 @@ namespace garlic
eRouterErrorOffline = 2,
eRouterErrorSymmetricNAT = 3
};
class RouterContext: public i2p::garlic::GarlicDestination
{
private:
@ -144,6 +145,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 +183,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;