moved current language from RouterContext to ClientContext

This commit is contained in:
orignal 2021-09-04 14:01:57 -04:00
parent bce8469e59
commit e8f4c42bfb
4 changed files with 16 additions and 16 deletions

View File

@ -240,7 +240,7 @@ namespace http {
std::string webroot; i2p::config::GetOption("http.webroot", webroot);
// Page language
std::string currLang = i2p::context.GetLanguage ()->GetLanguage(); // get current used language
std::string currLang = i2p::client::context.GetLanguage ()->GetLanguage(); // get current used language
auto it = i2p::i18n::languages.find(currLang);
std::string langCode = it->second.ShortCode;
@ -766,7 +766,7 @@ namespace http {
s << " <button type=\"submit\">" << tr("Change") << "</button>\r\n";
s << "</form>\r\n<br>\r\n";
std::string currLang = i2p::context.GetLanguage ()->GetLanguage(); // get current used language
std::string currLang = i2p::client::context.GetLanguage ()->GetLanguage(); // get current used language
s << "<b>" << tr("Change language") << "</b><br>\r\n";
s << "<form method=\"get\" action=\"" << webroot << "\">\r\n";
s << " <input type=\"hidden\" name=\"cmd\" value=\"" << HTTP_COMMAND_SETLANGUAGE << "\">\r\n";
@ -1382,7 +1382,7 @@ namespace http {
else if (cmd == HTTP_COMMAND_SETLANGUAGE)
{
std::string lang = params["lang"];
std::string currLang = i2p::context.GetLanguage ()->GetLanguage();
std::string currLang = i2p::client::context.GetLanguage ()->GetLanguage();
if (currLang.compare(lang) != 0)
i2p::i18n::SetLanguage(lang);

View File

@ -9,7 +9,7 @@
#ifndef __I18N_H__
#define __I18N_H__
#include "RouterContext.h"
#include "ClientContext.h"
namespace i2p
{
@ -19,19 +19,19 @@ namespace i18n
{
const auto it = i2p::i18n::languages.find(lang);
if (it == i2p::i18n::languages.end()) // fallback
i2p::context.SetLanguage (i2p::i18n::english::GetLocale());
i2p::client::context.SetLanguage (i2p::i18n::english::GetLocale());
else
i2p::context.SetLanguage (it->second.LocaleFunc());
i2p::client::context.SetLanguage (it->second.LocaleFunc());
}
inline std::string translate (const std::string& arg)
{
return i2p::context.GetLanguage ()->GetString (arg);
return i2p::client::context.GetLanguage ()->GetString (arg);
}
inline std::string translate (const std::string& arg, const std::string& arg2, const int& n)
{
return i2p::context.GetLanguage ()->GetPlural (arg, arg2, n);
return i2p::client::context.GetLanguage ()->GetPlural (arg, arg2, n);
}
} // i18n
} // i2p

View File

@ -18,7 +18,6 @@
#include "Identity.h"
#include "RouterInfo.h"
#include "Garlic.h"
#include "I18N_langs.h"
namespace i2p
{
@ -146,10 +145,6 @@ namespace garlic
void ProcessGarlicMessage (std::shared_ptr<I2NPMessage> msg);
void ProcessDeliveryStatusMessage (std::shared_ptr<I2NPMessage> msg);
// i18n
std::shared_ptr<const i2p::i18n::Locale> GetLanguage () { return m_Language; };
void SetLanguage (const std::shared_ptr<const i2p::i18n::Locale> language) { m_Language = language; };
protected:
// implements GarlicDestination
@ -186,9 +181,6 @@ namespace garlic
std::unique_ptr<i2p::crypto::X25519Keys> m_StaticKeys;
// for ECIESx25519
i2p::crypto::NoiseSymmetricState m_InitialNoiseState, m_CurrentNoiseState;
// i18n
std::shared_ptr<const i2p::i18n::Locale> m_Language;
};
extern RouterContext context;

View File

@ -22,6 +22,7 @@
#include "BOB.h"
#include "I2CP.h"
#include "AddressBook.h"
#include "I18N_langs.h"
namespace i2p
{
@ -102,6 +103,10 @@ namespace client
std::vector<std::shared_ptr<DatagramSessionInfo> > GetForwardInfosFor(const i2p::data::IdentHash & destination);
// i18n
std::shared_ptr<const i2p::i18n::Locale> GetLanguage () { return m_Language; };
void SetLanguage (const std::shared_ptr<const i2p::i18n::Locale> language) { m_Language = language; };
private:
void ReadTunnels ();
@ -149,6 +154,9 @@ namespace client
std::unique_ptr<boost::asio::deadline_timer> m_CleanupUDPTimer;
// i18n
std::shared_ptr<const i2p::i18n::Locale> m_Language;
public:
// for HTTP