2021-05-22 05:39:05 +00:00
|
|
|
/*
|
2022-02-18 06:29:28 +00:00
|
|
|
* Copyright (c) 2021-2022, The PurpleI2P Project
|
2021-05-22 05:39:05 +00: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_H__
|
|
|
|
#define __I18N_H__
|
|
|
|
|
2021-09-04 18:01:57 +00:00
|
|
|
#include "ClientContext.h"
|
2021-05-22 15:29:05 +00:00
|
|
|
|
2021-05-25 19:03:29 +00:00
|
|
|
namespace i2p
|
|
|
|
{
|
|
|
|
namespace i18n
|
|
|
|
{
|
|
|
|
inline void SetLanguage(const std::string &lang)
|
|
|
|
{
|
2021-06-27 14:14:45 +00:00
|
|
|
const auto it = i2p::i18n::languages.find(lang);
|
|
|
|
if (it == i2p::i18n::languages.end()) // fallback
|
2021-09-04 18:01:57 +00:00
|
|
|
i2p::client::context.SetLanguage (i2p::i18n::english::GetLocale());
|
2021-06-27 14:14:45 +00:00
|
|
|
else
|
2021-09-04 18:01:57 +00:00
|
|
|
i2p::client::context.SetLanguage (it->second.LocaleFunc());
|
2021-05-25 19:03:29 +00:00
|
|
|
}
|
2021-05-22 05:39:05 +00:00
|
|
|
|
2021-05-23 12:52:27 +00:00
|
|
|
inline std::string translate (const std::string& arg)
|
2021-05-22 05:39:05 +00:00
|
|
|
{
|
2021-09-04 18:01:57 +00:00
|
|
|
return i2p::client::context.GetLanguage ()->GetString (arg);
|
2021-05-22 05:39:05 +00:00
|
|
|
}
|
|
|
|
|
2021-06-15 21:13:26 +00:00
|
|
|
inline std::string translate (const std::string& arg, const std::string& arg2, const int& n)
|
2021-05-22 05:39:05 +00:00
|
|
|
{
|
2021-09-04 18:01:57 +00:00
|
|
|
return i2p::client::context.GetLanguage ()->GetPlural (arg, arg2, n);
|
2021-05-22 05:39:05 +00:00
|
|
|
}
|
|
|
|
} // i18n
|
|
|
|
} // i2p
|
|
|
|
|
|
|
|
template<typename... TArgs>
|
2021-05-23 03:06:04 +00:00
|
|
|
std::string tr (TArgs&&... args)
|
|
|
|
{
|
2021-05-22 05:39:05 +00:00
|
|
|
return i2p::i18n::translate(std::forward<TArgs>(args)...);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // __I18N_H__
|