[i18n] use xgettext compatible function format for plural

Signed-off-by: R4SAS <r4sas@i2pmail.org>
This commit is contained in:
R4SAS 2021-06-16 00:13:26 +03:00
parent 0bacd4df5f
commit c06a560946
No known key found for this signature in database
GPG Key ID: 66F6C87B98EBCFE2
4 changed files with 11 additions and 14 deletions

View File

@ -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)

View File

@ -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"}},
{"", {"", ""}},
};

View File

@ -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

View File

@ -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
{