Browse Source

Test module translation of commands

pull/1833/head
Alexey Sokolov 1 month ago
parent
commit
9c855b5c01
  1. 2
      src/Translation.cpp
  2. 26
      test/integration/framework/znctest.cpp
  3. 1
      test/integration/framework/znctest.h
  4. 30
      test/integration/tests/scripting.cpp

2
src/Translation.cpp

@ -16,6 +16,7 @@
#include <znc/Translation.h>
#include <znc/FileUtils.h>
#include <znc/znc.h>
#ifdef HAVE_I18N
#include <boost/locale.hpp>
@ -88,6 +89,7 @@ const std::locale& CTranslation::LoadTranslation(const CString& sDomain) {
if (lang_it == domain.end()) {
boost::locale::generator gen;
gen.add_messages_path(LOCALE_DIR);
gen.add_messages_path(CZNC::Get().GetModPath() + "/locale");
gen.add_messages_domain(sDomain);
std::tie(lang_it, std::ignore) =
domain.emplace(sLanguage, gen(sLanguage + ".UTF-8"));

26
test/integration/framework/znctest.cpp

@ -171,4 +171,30 @@ void ZNCTest::InstallModule(QString name, QString content) {
}
}
void ZNCTest::InstallTranslation(QString module, QString language, QString content) {
QDir dir(m_dir.path());
for (QString d : std::vector<QString>{"modules", "locale", language, "LC_MESSAGES"}) {
ASSERT_TRUE(dir.mkpath(d)) << d.toStdString();
ASSERT_TRUE(dir.cd(d)) << d.toStdString();
}
QTemporaryDir srcdir;
QFile file(QDir(srcdir.path()).filePath("foo.po"));
ASSERT_TRUE(file.open(QIODevice::WriteOnly | QIODevice::Text));
QTextStream out(&file);
out << content;
file.close();
{
Process p("msgfmt", QStringList() << "-D" << "." << "-o" << "foo.mo" << "foo.po",
[&](QProcess* proc) {
proc->setWorkingDirectory(srcdir.path());
proc->setProcessChannelMode(QProcess::ForwardedChannels);
});
p.ShouldFinishItself();
p.ShouldFinishInSec(300);
}
QFile result(QDir(srcdir.path()).filePath("foo.mo"));
result.rename(dir.filePath("znc-" + module + ".mo"));
}
} // namespace znc_inttest

1
test/integration/framework/znctest.h

@ -47,6 +47,7 @@ class ZNCTest : public testing::Test {
std::unique_ptr<QNetworkReply> HandleHttp(QNetworkReply* reply);
void InstallModule(QString name, QString content);
void InstallTranslation(QString module, QString language, QString content);
App m_app;
QNetworkAccessManager m_network;

30
test/integration/tests/scripting.cpp

@ -316,19 +316,45 @@ TEST_F(ZNCTest, ModpythonCommand) {
class testcmd(znc.Command):
command = 'ping'
args = cmdtest.t_d('ar')
description = cmdtest.t_d('blah')
def __call__(self, line):
self.GetModule().PutModule('pong')
self.GetModule().PutModule(line + cmdtest.t_s(' pong'))
)");
auto ircd = ConnectIRCd();
auto client = LoginClient();
client.Write("znc loadmod modpython");
client.Write("znc loadmod cmdtest");
client.Write("PRIVMSG *cmdtest :ping or");
client.ReadUntil(":*cmdtest!znc@znc.in PRIVMSG nick :ping or pong");
InstallTranslation("cmdtest", "ru_RU", R"(
msgid ""
msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=4; plural=((n%10==1 && n%100!=11) ? 0 : ((n%10 >= 2 "
"&& n%10 <=4 && (n%100 < 12 || n%100 > 14)) ? 1 : ((n%10 == 0 || (n%10 >= 5 "
"&& n%10 <=9)) || (n%100 >= 11 && n%100 <= 14)) ? 2 : 3));\n"
"Language: ru_RU\n"
msgid "ar"
msgstr "аргумент"
msgid "blah"
msgstr "бла"
msgid " pong"
msgstr " понг"
)");
client.Write("PRIVMSG *controlpanel :set language $me ru-RU");
client.Write("PRIVMSG *cmdtest :help");
client.ReadUntil(":*cmdtest!znc@znc.in PRIVMSG nick :\x02ping аргумент\x0F: бла");
client.Write("PRIVMSG *cmdtest :ping");
client.ReadUntil(":*cmdtest!znc@znc.in PRIVMSG nick :pong");
client.ReadUntil(":*cmdtest!znc@znc.in PRIVMSG nick :ping понг");
}
} // namespace

Loading…
Cancel
Save