mirror of
https://github.com/PurpleI2P/i2pd
synced 2024-11-10 00:00:29 +03:00
[i18n] use xgettext compatible function format for plural
Signed-off-by: R4SAS <r4sas@i2pmail.org>
This commit is contained in:
parent
0bacd4df5f
commit
c06a560946
@ -138,18 +138,18 @@ namespace http {
|
||||
int num;
|
||||
|
||||
if ((num = seconds / 86400) > 0) {
|
||||
s << num << " " << tr("days", num) << ", ";
|
||||
s << num << " " << tr("day", "days", num) << ", ";
|
||||
seconds -= num * 86400;
|
||||
}
|
||||
if ((num = seconds / 3600) > 0) {
|
||||
s << num << " " << tr("hours", num) << ", ";
|
||||
s << num << " " << tr("hour", "hours", num) << ", ";
|
||||
seconds -= num * 3600;
|
||||
}
|
||||
if ((num = seconds / 60) > 0) {
|
||||
s << num << " " << tr("minutes", num) << ", ";
|
||||
s << num << " " << tr("minute", "minutes", num) << ", ";
|
||||
seconds -= num * 60;
|
||||
}
|
||||
s << seconds << " " << tr("seconds", seconds);
|
||||
s << seconds << " " << tr("second", "seconds", seconds);
|
||||
}
|
||||
|
||||
static void ShowTraffic (std::stringstream& s, uint64_t bytes)
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include "I18N.h"
|
||||
|
||||
// English localization file
|
||||
// This is an example translation file without strings in it.
|
||||
|
||||
namespace i2p
|
||||
{
|
||||
@ -33,10 +34,6 @@ namespace english // language
|
||||
|
||||
static std::map<std::string, std::vector<std::string>> plurals
|
||||
{
|
||||
{"days", {"day", "days"}},
|
||||
{"hours", {"hour", "hours"}},
|
||||
{"minutes", {"minute", "minutes"}},
|
||||
{"seconds", {"second", "seconds"}},
|
||||
{"", {"", ""}},
|
||||
};
|
||||
|
||||
|
@ -32,9 +32,9 @@ namespace i18n
|
||||
return i2p::context.GetLanguage ()->GetString (arg);
|
||||
}
|
||||
|
||||
inline std::string translate (const std::string& arg, const int& n)
|
||||
inline std::string translate (const std::string& arg, const std::string& arg2, const int& n)
|
||||
{
|
||||
return i2p::context.GetLanguage ()->GetPlural (arg, n);
|
||||
return i2p::context.GetLanguage ()->GetPlural (arg, arg2, n);
|
||||
}
|
||||
} // i18n
|
||||
} // i2p
|
||||
|
@ -35,12 +35,12 @@ namespace i18n
|
||||
}
|
||||
}
|
||||
|
||||
std::string GetPlural (const std::string& arg, const int& n) const
|
||||
std::string GetPlural (const std::string& arg, const std::string& arg2, const int& n) const
|
||||
{
|
||||
const auto it = m_Plurals.find(arg);
|
||||
if (it == m_Plurals.end())
|
||||
const auto it = m_Plurals.find(arg2);
|
||||
if (it == m_Plurals.end()) // not found, fallback to english
|
||||
{
|
||||
return arg;
|
||||
return n == 1 ? arg : arg2;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user