mirror of https://github.com/znc/znc
Merge pull request #1833 from DarthGandalf/pycmd
Rename cmd/desc to command/descriptionpull/1835/head
commit
d902aa7129
|
@ -434,9 +434,9 @@ class Module:
|
|||
# Command stuff
|
||||
def AddCommand(self, cls, *args, **kwargs):
|
||||
cmd = cls(*args, **kwargs)
|
||||
cmd._cmodcommand = CreatePyModCommand(self._cmod, cls.cmd,
|
||||
cmd._cmodcommand = CreatePyModCommand(self._cmod, cls.command,
|
||||
COptionalTranslation(cls.args),
|
||||
COptionalTranslation(cls.desc),
|
||||
COptionalTranslation(cls.description),
|
||||
cmd)
|
||||
|
||||
return cmd
|
||||
|
@ -685,9 +685,9 @@ class Module:
|
|||
|
||||
|
||||
class Command:
|
||||
cmd = ''
|
||||
command = ''
|
||||
args = ''
|
||||
desc = ''
|
||||
description = ''
|
||||
|
||||
def __call__(self, sLine):
|
||||
pass
|
||||
|
|
|
@ -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"));
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -310,22 +310,51 @@ TEST_F(ZNCTest, ModpythonCommand) {
|
|||
|
||||
class cmdtest(znc.Module):
|
||||
def OnLoad(self, args, message):
|
||||
self.AddHelpCommand()
|
||||
self.AddCommand(testcmd)
|
||||
return True
|
||||
|
||||
class testcmd(znc.Command):
|
||||
cmd = 'ping'
|
||||
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("pong");
|
||||
client.ReadUntil(":*cmdtest!znc@znc.in PRIVMSG nick :ping понг");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
|
Loading…
Reference in New Issue