2021-05-23 03:06:04 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2021, The PurpleI2P Project
|
|
|
|
*
|
|
|
|
* 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 19:03:29 +00:00
|
|
|
namespace i2p
|
|
|
|
{
|
|
|
|
namespace i18n
|
|
|
|
{
|
|
|
|
class Locale
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Locale (
|
|
|
|
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) { };
|
2021-05-23 03:06:04 +00:00
|
|
|
|
2021-05-25 19:03:29 +00: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 03:06:04 +00:00
|
|
|
|
2021-06-15 21:13:26 +00:00
|
|
|
std::string GetPlural (const std::string& arg, const std::string& arg2, const int& n) const
|
2021-05-25 19:03:29 +00:00
|
|
|
{
|
2021-06-15 21:13:26 +00:00
|
|
|
const auto it = m_Plurals.find(arg2);
|
|
|
|
if (it == m_Plurals.end()) // not found, fallback to english
|
2021-05-25 19:03:29 +00:00
|
|
|
{
|
2021-06-15 21:13:26 +00:00
|
|
|
return n == 1 ? arg : arg2;
|
2021-05-25 19:03:29 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int form = m_Formula(n);
|
|
|
|
return it->second[form];
|
|
|
|
}
|
|
|
|
}
|
2021-05-23 03:06:04 +00:00
|
|
|
|
2021-05-25 19:03:29 +00:00
|
|
|
private:
|
|
|
|
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 03:06:04 +00:00
|
|
|
|
2021-05-25 19:03:29 +00:00
|
|
|
// Add localization here with language name as namespace
|
2021-06-16 14:57:02 +00:00
|
|
|
namespace afrikaans { std::shared_ptr<const i2p::i18n::Locale> GetLocale (); }
|
|
|
|
namespace english { std::shared_ptr<const i2p::i18n::Locale> GetLocale (); }
|
|
|
|
namespace russian { std::shared_ptr<const i2p::i18n::Locale> GetLocale (); }
|
|
|
|
namespace turkmen { std::shared_ptr<const i2p::i18n::Locale> GetLocale (); }
|
2021-05-26 07:50:02 +00:00
|
|
|
namespace ukrainian { std::shared_ptr<const i2p::i18n::Locale> GetLocale (); }
|
2021-05-23 03:06:04 +00:00
|
|
|
|
|
|
|
} // i18n
|
|
|
|
} // i2p
|
|
|
|
|
|
|
|
#endif // __I18N_LANGS_H__
|