Skip to content

Commit

Permalink
[i18n] use xgettext compatible function format for plural
Browse files Browse the repository at this point in the history
Signed-off-by: R4SAS <r4sas@i2pmail.org>
  • Loading branch information
r4sas committed Jun 15, 2021
1 parent 0bacd4d commit c06a560
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 14 deletions.
8 changes: 4 additions & 4 deletions daemon/HTTPServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 1 addition & 4 deletions i18n/English.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "I18N.h"

// English localization file
// This is an example translation file without strings in it.

namespace i2p
{
Expand All @@ -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"}},
{"", {"", ""}},
};

Expand Down
4 changes: 2 additions & 2 deletions i18n/I18N.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions i18n/I18N_langs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down

0 comments on commit c06a560

Please sign in to comment.