2022-11-25 00:26:38 +00:00
|
|
|
/*
|
2023-01-19 03:40:32 +00:00
|
|
|
* Copyright (c) 2021-2023, The PurpleI2P Project
|
2022-11-25 00:26:38 +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
|
|
|
|
*/
|
|
|
|
|
2023-01-19 03:40:32 +00:00
|
|
|
#include <clocale>
|
2022-11-25 00:26:38 +00:00
|
|
|
#include "ClientContext.h"
|
|
|
|
#include "I18N_langs.h"
|
|
|
|
#include "I18N.h"
|
|
|
|
|
|
|
|
namespace i2p
|
|
|
|
{
|
|
|
|
namespace i18n
|
|
|
|
{
|
|
|
|
void SetLanguage(const std::string &lang)
|
|
|
|
{
|
|
|
|
const auto it = i2p::i18n::languages.find(lang);
|
|
|
|
if (it == i2p::i18n::languages.end()) // fallback
|
2023-01-19 03:40:32 +00:00
|
|
|
{
|
2022-11-25 00:26:38 +00:00
|
|
|
i2p::client::context.SetLanguage (i2p::i18n::english::GetLocale());
|
2023-01-19 03:40:32 +00:00
|
|
|
setlocale(LC_NUMERIC, "english");
|
|
|
|
}
|
2022-11-25 00:26:38 +00:00
|
|
|
else
|
2023-01-19 03:40:32 +00:00
|
|
|
{
|
2022-11-25 00:26:38 +00:00
|
|
|
i2p::client::context.SetLanguage (it->second.LocaleFunc());
|
2023-01-19 03:40:32 +00:00
|
|
|
setlocale(LC_NUMERIC, lang.c_str()); // set decimal point based on language
|
|
|
|
}
|
2022-11-25 00:26:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string translate (const std::string& arg)
|
|
|
|
{
|
|
|
|
return i2p::client::context.GetLanguage ()->GetString (arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string translate (const std::string& arg, const std::string& arg2, const int& n)
|
|
|
|
{
|
|
|
|
return i2p::client::context.GetLanguage ()->GetPlural (arg, arg2, n);
|
|
|
|
}
|
|
|
|
} // i18n
|
|
|
|
} // i2p
|