mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-04-28 11:47:48 +02:00
[i18n] add language changing at runtime in webconsole
Signed-off-by: R4SAS <r4sas@i2pmail.org>
This commit is contained in:
parent
6d2c9e367b
commit
12d6f03dc9
9 changed files with 396 additions and 354 deletions
|
@ -17,10 +17,17 @@ namespace i18n
|
|||
{
|
||||
public:
|
||||
Locale (
|
||||
const std::string& language,
|
||||
const std::map<std::string, std::string>& strings,
|
||||
const std::map<std::string, std::vector<std::string>>& plurals,
|
||||
std::function<int(int)> formula
|
||||
): m_Strings (strings), m_Plurals (plurals), m_Formula (formula) { };
|
||||
): m_Language (language), m_Strings (strings), m_Plurals (plurals), m_Formula (formula) { };
|
||||
|
||||
// Get activated language name for webconsole
|
||||
std::string GetLanguage() const
|
||||
{
|
||||
return m_Language;
|
||||
}
|
||||
|
||||
std::string GetString (const std::string& arg) const
|
||||
{
|
||||
|
@ -50,11 +57,18 @@ namespace i18n
|
|||
}
|
||||
|
||||
private:
|
||||
const std::string m_Language;
|
||||
const std::map<std::string, std::string> m_Strings;
|
||||
const std::map<std::string, std::vector<std::string>> m_Plurals;
|
||||
std::function<int(int)> m_Formula;
|
||||
};
|
||||
|
||||
struct langData
|
||||
{
|
||||
std::string LocaleName; //localized name
|
||||
std::function<std::shared_ptr<const i2p::i18n::Locale> (void)> LocaleFunc;
|
||||
};
|
||||
|
||||
// Add localization here with language name as namespace
|
||||
namespace afrikaans { std::shared_ptr<const i2p::i18n::Locale> GetLocale (); }
|
||||
namespace english { std::shared_ptr<const i2p::i18n::Locale> GetLocale (); }
|
||||
|
@ -62,6 +76,18 @@ namespace i18n
|
|||
namespace turkmen { std::shared_ptr<const i2p::i18n::Locale> GetLocale (); }
|
||||
namespace ukrainian { std::shared_ptr<const i2p::i18n::Locale> GetLocale (); }
|
||||
|
||||
/**
|
||||
* That map contains international language name lower-case and name in it's language
|
||||
*/
|
||||
static std::map<std::string, langData> languages
|
||||
{
|
||||
{ "afrikaans", {"Afrikaans", i2p::i18n::afrikaans::GetLocale} },
|
||||
{ "english", {"English", i2p::i18n::english::GetLocale} },
|
||||
{ "russian", {"русский язык", i2p::i18n::russian::GetLocale} },
|
||||
{ "turkmen", {"türkmen dili", i2p::i18n::turkmen::GetLocale} },
|
||||
{ "ukrainian", {"украї́нська мо́ва", i2p::i18n::ukrainian::GetLocale} },
|
||||
};
|
||||
|
||||
} // i18n
|
||||
} // i2p
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue