Browse Source

[i18n] use xgettext compatible function format for plural

Signed-off-by: R4SAS <r4sas@i2pmail.org>
pull/1662/head
R4SAS 4 years ago
parent
commit
c06a560946
Signed by: r4sas
GPG Key ID: 66F6C87B98EBCFE2
  1. 8
      daemon/HTTPServer.cpp
  2. 5
      i18n/English.cpp
  3. 4
      i18n/I18N.h
  4. 8
      i18n/I18N_langs.h

8
daemon/HTTPServer.cpp

@ -138,18 +138,18 @@ namespace http { @@ -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)

5
i18n/English.cpp

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

4
i18n/I18N.h

@ -32,9 +32,9 @@ namespace i18n @@ -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

8
i18n/I18N_langs.h

@ -35,12 +35,12 @@ namespace i18n @@ -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…
Cancel
Save