2021-05-23 06:06:04 +03:00
|
|
|
|
/*
|
2022-01-09 23:42:13 +03:00
|
|
|
|
* Copyright (c) 2021-2022, The PurpleI2P Project
|
2021-05-23 06:06:04 +03:00
|
|
|
|
*
|
|
|
|
|
* This file is part of Purple i2pd project and licensed under BSD3
|
|
|
|
|
*
|
|
|
|
|
* See full license text in LICENSE file at top of project tree
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef __I18N_LANGS_H__
|
|
|
|
|
#define __I18N_LANGS_H__
|
|
|
|
|
|
2021-05-25 22:03:29 +03:00
|
|
|
|
namespace i2p
|
|
|
|
|
{
|
|
|
|
|
namespace i18n
|
|
|
|
|
{
|
|
|
|
|
class Locale
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
Locale (
|
2021-06-27 17:14:45 +03:00
|
|
|
|
const std::string& language,
|
2021-05-25 22:03:29 +03:00
|
|
|
|
const std::map<std::string, std::string>& strings,
|
|
|
|
|
const std::map<std::string, std::vector<std::string>>& plurals,
|
|
|
|
|
std::function<int(int)> formula
|
2021-06-27 17:14:45 +03:00
|
|
|
|
): 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;
|
|
|
|
|
}
|
2021-05-23 06:06:04 +03:00
|
|
|
|
|
2021-05-25 22:03:29 +03:00
|
|
|
|
std::string GetString (const std::string& arg) const
|
|
|
|
|
{
|
|
|
|
|
const auto it = m_Strings.find(arg);
|
|
|
|
|
if (it == m_Strings.end())
|
|
|
|
|
{
|
|
|
|
|
return arg;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return it->second;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-05-23 06:06:04 +03:00
|
|
|
|
|
2021-06-16 00:13:26 +03:00
|
|
|
|
std::string GetPlural (const std::string& arg, const std::string& arg2, const int& n) const
|
2021-05-25 22:03:29 +03:00
|
|
|
|
{
|
2021-06-16 00:13:26 +03:00
|
|
|
|
const auto it = m_Plurals.find(arg2);
|
|
|
|
|
if (it == m_Plurals.end()) // not found, fallback to english
|
2021-05-25 22:03:29 +03:00
|
|
|
|
{
|
2021-06-16 00:13:26 +03:00
|
|
|
|
return n == 1 ? arg : arg2;
|
2021-05-25 22:03:29 +03:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
int form = m_Formula(n);
|
|
|
|
|
return it->second[form];
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-05-23 06:06:04 +03:00
|
|
|
|
|
2021-05-25 22:03:29 +03:00
|
|
|
|
private:
|
2021-06-27 17:14:45 +03:00
|
|
|
|
const std::string m_Language;
|
2021-05-25 22:03:29 +03:00
|
|
|
|
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;
|
|
|
|
|
};
|
2021-05-23 06:06:04 +03:00
|
|
|
|
|
2021-06-27 17:14:45 +03:00
|
|
|
|
struct langData
|
|
|
|
|
{
|
2021-08-06 20:42:08 +03:00
|
|
|
|
std::string LocaleName; // localized name
|
|
|
|
|
std::string ShortCode; // short language code, like "en"
|
2021-06-27 17:14:45 +03:00
|
|
|
|
std::function<std::shared_ptr<const i2p::i18n::Locale> (void)> LocaleFunc;
|
|
|
|
|
};
|
|
|
|
|
|
2021-05-25 22:03:29 +03:00
|
|
|
|
// Add localization here with language name as namespace
|
2021-06-16 17:57:02 +03:00
|
|
|
|
namespace afrikaans { std::shared_ptr<const i2p::i18n::Locale> GetLocale (); }
|
2021-11-18 15:15:34 +03:00
|
|
|
|
namespace armenian { std::shared_ptr<const i2p::i18n::Locale> GetLocale (); }
|
2022-08-03 11:48:10 +03:00
|
|
|
|
namespace chinese { std::shared_ptr<const i2p::i18n::Locale> GetLocale (); }
|
2021-06-16 17:57:02 +03:00
|
|
|
|
namespace english { std::shared_ptr<const i2p::i18n::Locale> GetLocale (); }
|
2022-05-15 11:45:57 +03:00
|
|
|
|
namespace french { std::shared_ptr<const i2p::i18n::Locale> GetLocale (); }
|
2022-01-09 23:42:13 +03:00
|
|
|
|
namespace german { std::shared_ptr<const i2p::i18n::Locale> GetLocale (); }
|
2022-08-30 23:59:26 +03:00
|
|
|
|
namespace italian { std::shared_ptr<const i2p::i18n::Locale> GetLocale (); }
|
2021-06-16 17:57:02 +03:00
|
|
|
|
namespace russian { std::shared_ptr<const i2p::i18n::Locale> GetLocale (); }
|
|
|
|
|
namespace turkmen { std::shared_ptr<const i2p::i18n::Locale> GetLocale (); }
|
2021-05-26 10:50:02 +03:00
|
|
|
|
namespace ukrainian { std::shared_ptr<const i2p::i18n::Locale> GetLocale (); }
|
2021-08-18 23:04:52 +03:00
|
|
|
|
namespace uzbek { std::shared_ptr<const i2p::i18n::Locale> GetLocale (); }
|
2021-05-23 06:06:04 +03:00
|
|
|
|
|
2021-06-27 17:14:45 +03:00
|
|
|
|
/**
|
2022-01-09 23:42:13 +03:00
|
|
|
|
* That map contains international language name lower-case, name in it's language and it's code
|
2021-06-27 17:14:45 +03:00
|
|
|
|
*/
|
|
|
|
|
static std::map<std::string, langData> languages
|
|
|
|
|
{
|
2021-08-06 20:42:08 +03:00
|
|
|
|
{ "afrikaans", {"Afrikaans", "af", i2p::i18n::afrikaans::GetLocale} },
|
2021-11-18 15:15:34 +03:00
|
|
|
|
{ "armenian", {"հայերէն", "hy", i2p::i18n::armenian::GetLocale} },
|
2022-08-03 11:48:10 +03:00
|
|
|
|
{ "chinese", {"简体字", "zh-CN", i2p::i18n::chinese::GetLocale} },
|
2021-08-06 20:42:08 +03:00
|
|
|
|
{ "english", {"English", "en", i2p::i18n::english::GetLocale} },
|
2022-05-15 11:45:57 +03:00
|
|
|
|
{ "french", {"Français", "fr", i2p::i18n::french::GetLocale} },
|
2022-01-09 23:42:13 +03:00
|
|
|
|
{ "german", {"Deutsch", "de", i2p::i18n::german::GetLocale} },
|
2022-08-30 23:59:26 +03:00
|
|
|
|
{ "italian", {"Italiano", "it", i2p::i18n::italian::GetLocale} },
|
2021-08-06 20:42:08 +03:00
|
|
|
|
{ "russian", {"русский язык", "ru", i2p::i18n::russian::GetLocale} },
|
|
|
|
|
{ "turkmen", {"türkmen dili", "tk", i2p::i18n::turkmen::GetLocale} },
|
|
|
|
|
{ "ukrainian", {"украї́нська мо́ва", "uk", i2p::i18n::ukrainian::GetLocale} },
|
2021-08-18 22:55:14 +03:00
|
|
|
|
{ "uzbek", {"Oʻzbek", "uz", i2p::i18n::uzbek::GetLocale} },
|
2021-06-27 17:14:45 +03:00
|
|
|
|
};
|
|
|
|
|
|
2021-05-23 06:06:04 +03:00
|
|
|
|
} // i18n
|
|
|
|
|
} // i2p
|
|
|
|
|
|
|
|
|
|
#endif // __I18N_LANGS_H__
|