diff --git a/src/Translation.cpp b/src/Translation.cpp index 1f1748b9..153f097a 100644 --- a/src/Translation.cpp +++ b/src/Translation.cpp @@ -16,6 +16,7 @@ #include #include +#include #ifdef HAVE_I18N #include @@ -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")); diff --git a/test/integration/framework/znctest.cpp b/test/integration/framework/znctest.cpp index 2c4d6d21..58c3f926 100644 --- a/test/integration/framework/znctest.cpp +++ b/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{"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 diff --git a/test/integration/framework/znctest.h b/test/integration/framework/znctest.h index fd439ea0..c03591ef 100644 --- a/test/integration/framework/znctest.h +++ b/test/integration/framework/znctest.h @@ -47,6 +47,7 @@ class ZNCTest : public testing::Test { std::unique_ptr HandleHttp(QNetworkReply* reply); void InstallModule(QString name, QString content); + void InstallTranslation(QString module, QString language, QString content); App m_app; QNetworkAccessManager m_network; diff --git a/test/integration/tests/scripting.cpp b/test/integration/tests/scripting.cpp index 7ee61821..06bf5e0c 100644 --- a/test/integration/tests/scripting.cpp +++ b/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