export i18n into the runtime; now i need to figure out how to extract message files from the plasmoids and how to set the translation from a file on disk as part of the package

svn path=/trunk/KDE/kdebase/workspace/plasma/scriptengines/javascript/; revision=961936
This commit is contained in:
Aaron J. Seigo 2009-05-01 06:12:07 +00:00
parent 46733f00cd
commit 420b3e445b
2 changed files with 13 additions and 0 deletions

View File

@ -431,6 +431,7 @@ void SimpleJavaScriptApplet::setupObjects()
m_engine->setDefaultPrototype(qMetaTypeId<Service*>(), m_engine->newQObject(new DummyService()));
m_engine->setDefaultPrototype(qMetaTypeId<ServiceJob*>(), m_engine->newQObject(new ServiceJob(QString(), QString(), QMap<QString, QVariant>())));
global.setProperty("i18n", m_engine->newFunction(SimpleJavaScriptApplet::jsi18n));
global.setProperty("dataEngine", m_engine->newFunction(SimpleJavaScriptApplet::dataEngine));
global.setProperty("service", m_engine->newFunction(SimpleJavaScriptApplet::service));
qScriptRegisterMetaType<DataEngine::Data>(m_engine, qScriptValueFromData, 0, QScriptValue());
@ -508,6 +509,17 @@ QScriptValue SimpleJavaScriptApplet::dataEngine(QScriptContext *context, QScript
}
#endif
QScriptValue SimpleJavaScriptApplet::jsi18n(QScriptContext *context, QScriptEngine *engine)
{
if (context->argumentCount() != 1) {
return context->throwError(i18n("i18n takes one argument"));
}
//TODO: detect i18np pattern
QString message = context->argument(0).toString();
return engine->newVariant(i18n(message.toLocal8Bit()));
}
QScriptValue SimpleJavaScriptApplet::dataEngine(QScriptContext *context, QScriptEngine *engine)
{
if (context->argumentCount() != 1) {

View File

@ -62,6 +62,7 @@ private:
void callFunction(const QString &functionName, const QScriptValueList &args = QScriptValueList());
static QString findSvg(QScriptEngine *engine, const QString &file);
static QScriptValue jsi18n(QScriptContext *context, QScriptEngine *engine);
static QScriptValue dataEngine(QScriptContext *context, QScriptEngine *engine);
static QScriptValue service(QScriptContext *context, QScriptEngine *engine);
static QScriptValue loadui(QScriptContext *context, QScriptEngine *engine);