diff options
author | Sadie Powell <sadie@witchery.services> | 2024-11-22 15:22:23 +0000 |
---|---|---|
committer | Sadie Powell <sadie@witchery.services> | 2024-11-22 15:22:23 +0000 |
commit | c3055e1cfa112c7deecc434ce01b928fd8736c70 (patch) | |
tree | 623b3aca08009949178c7457555994a0de00254f | |
parent | a27be92e4b406e4bee8a0d56bda00eae335c80a5 (diff) |
Add a plural form overload of SendMessage.
-rw-r--r-- | include/users.h | 1 | ||||
-rw-r--r-- | language/anope.en_US.po | 9 | ||||
-rw-r--r-- | modules/memoserv/memoserv.cpp | 2 | ||||
-rw-r--r-- | src/users.cpp | 15 |
4 files changed, 21 insertions, 6 deletions
diff --git a/include/users.h b/include/users.h index 92515678f..c1ddda6d1 100644 --- a/include/users.h +++ b/include/users.h @@ -190,6 +190,7 @@ public: * @param ... any number of parameters */ void SendMessage(BotInfo *source, const char *fmt, ...) ATTR_FORMAT(3, 4); + void SendMessage(BotInfo *source, int count, const char *singular, const char *plural, ...) ATTR_FORMAT(5, 6); void SendMessage(BotInfo *source, const Anope::string &msg) override; void SendMessage(CommandSource &source, const Anope::string &msg) override; diff --git a/language/anope.en_US.po b/language/anope.en_US.po index 2e52bd183..429c6731d 100644 --- a/language/anope.en_US.po +++ b/language/anope.en_US.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: Anope\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2024-11-22 13:00+0000\n" +"POT-Creation-Date: 2024-11-22 15:21+0000\n" "PO-Revision-Date: 2024-11-13 02:45+0000\n" "Last-Translator: Sadie Powell <sadie@witchery.services>\n" "Language-Team: English\n" @@ -6986,11 +6986,10 @@ msgid "You found me, %s!" msgstr "" #, c-format -msgid "You have %d new memos." -msgstr "" - msgid "You have 1 new memo." -msgstr "" +msgid_plural "You have %d new memos." +msgstr[0] "" +msgstr[1] "" #, c-format msgid "" diff --git a/modules/memoserv/memoserv.cpp b/modules/memoserv/memoserv.cpp index c6d927460..4b005eaf5 100644 --- a/modules/memoserv/memoserv.cpp +++ b/modules/memoserv/memoserv.cpp @@ -139,7 +139,7 @@ public: if (nc->memos.GetMemo(i)->unread) ++newcnt; if (newcnt > 0) - u->SendMessage(MemoServ, newcnt == 1 ? _("You have 1 new memo.") : _("You have %d new memos."), newcnt); + u->SendMessage(MemoServ, newcnt, N_("You have 1 new memo.", "You have %d new memos."), newcnt); if (nc->memos.memomax > 0 && nc->memos.memos->size() >= static_cast<unsigned>(nc->memos.memomax)) { if (nc->memos.memos->size() > static_cast<unsigned>(nc->memos.memomax)) diff --git a/src/users.cpp b/src/users.cpp index 5f83420a4..55bfde478 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -328,6 +328,21 @@ void User::SendMessage(BotInfo *source, const char *fmt, ...) va_end(args); } +void User::SendMessage(BotInfo *source, int count, const char *singular, const char *plural, ...) +{ + va_list args; + char buf[BUFSIZE] = ""; + + const char *translated_message = Language::Translate(this, count, singular, plural); + + va_start(args, plural); + vsnprintf(buf, BUFSIZE - 1, translated_message, args); + + this->SendMessage(source, Anope::string(buf)); + + va_end(args); +} + namespace { void SendMessageInternal(BotInfo *source, User *target, const Anope::string &msg, const Anope::map<Anope::string> &tags) |