Commit 50cc55af authored by Christian Kamm's avatar Christian Kamm
Browse files

QmlJS: Change to a nicer way of marking strings for translation.

Reviewed-by: ossi
parent fadfe9c6
......@@ -34,7 +34,6 @@
#include "parser/qmljsast_p.h"
#include <QtCore/QDebug>
#include <QtCore/QCoreApplication>
#include <QtGui/QColor>
#include <QtGui/QApplication>
......@@ -71,19 +70,19 @@ public:
const QString valueName = stringLiteral->value->asString();
if (!enumValue->keys().contains(valueName)) {
_message.message = QCoreApplication::translate("QmlJS::Check", "unknown value for enum");
_message.message = Check::tr("unknown value for enum");
}
} else if (_rhsValue->asUndefinedValue()) {
_message.kind = DiagnosticMessage::Warning;
_message.message = QCoreApplication::translate("QmlJS::Check", "value might be 'undefined'");
_message.message = Check::tr("value might be 'undefined'");
} else if (! _rhsValue->asStringValue() && ! _rhsValue->asNumberValue()) {
_message.message = QCoreApplication::translate("QmlJS::Check", "enum value is not a string or number");
_message.message = Check::tr("enum value is not a string or number");
}
} else {
if (/*cast<StringLiteral *>(_ast)
||*/ _ast->kind == Node::Kind_TrueLiteral
|| _ast->kind == Node::Kind_FalseLiteral) {
_message.message = QCoreApplication::translate("QmlJS::Check", "numerical value expected");
_message.message = Check::tr("numerical value expected");
}
}
}
......@@ -95,7 +94,7 @@ public:
if (cast<StringLiteral *>(_ast)
|| cast<NumericLiteral *>(_ast)
|| (unaryMinus && cast<NumericLiteral *>(unaryMinus->expression))) {
_message.message = QCoreApplication::translate("QmlJS::Check", "boolean value expected");
_message.message = Check::tr("boolean value expected");
}
}
......@@ -107,7 +106,7 @@ public:
|| (unaryMinus && cast<NumericLiteral *>(unaryMinus->expression))
|| _ast->kind == Node::Kind_TrueLiteral
|| _ast->kind == Node::Kind_FalseLiteral) {
_message.message = QCoreApplication::translate("QmlJS::Check", "string value expected");
_message.message = Check::tr("string value expected");
}
}
......@@ -132,7 +131,7 @@ public:
ok = QColor::isValidColor(colorString);
}
if (!ok)
_message.message = QCoreApplication::translate("QmlJS::Check", "not a valid color");
_message.message = Check::tr("not a valid color");
} else {
visit((StringValue *)0);
}
......@@ -141,7 +140,7 @@ public:
virtual void visit(const AnchorLineValue *)
{
if (! (_rhsValue->asAnchorLineValue() || _rhsValue->asUndefinedValue()))
_message.message = QCoreApplication::translate("QmlJS::Check", "expected anchor line");
_message.message = Check::tr("expected anchor line");
}
DiagnosticMessage _message;
......@@ -209,7 +208,7 @@ void Check::visitQmlObject(Node *ast, UiQualifiedId *typeId,
if (! _context.lookupType(_doc.data(), typeId)) {
if (! _ignoreTypeErrors)
error(typeId->identifierToken,
QCoreApplication::translate("QmlJS::Check", "unknown type"));
Check::tr("unknown type"));
// suppress subsequent errors about scope object lookup by clearing
// the scope object list
// ### todo: better way?
......@@ -234,7 +233,7 @@ bool Check::visit(UiScriptBinding *ast)
ExpressionStatement *expStmt = cast<ExpressionStatement *>(ast->statement);
if (!expStmt) {
error(loc, QCoreApplication::translate("QmlJS::Check", "expected id"));
error(loc, Check::tr("expected id"));
return false;
}
......@@ -243,14 +242,14 @@ bool Check::visit(UiScriptBinding *ast)
id = idExp->name->asString();
} else if (StringLiteral *strExp = cast<StringLiteral *>(expStmt->expression)) {
id = strExp->value->asString();
warning(loc, QCoreApplication::translate("QmlJS::Check", "using string literals for ids is discouraged"));
warning(loc, Check::tr("using string literals for ids is discouraged"));
} else {
error(loc, QCoreApplication::translate("QmlJS::Check", "expected id"));
error(loc, Check::tr("expected id"));
return false;
}
if (id.isEmpty() || ! id[0].isLower()) {
error(loc, QCoreApplication::translate("QmlJS::Check", "ids must be lower case"));
error(loc, Check::tr("ids must be lower case"));
return false;
}
}
......@@ -323,7 +322,7 @@ const Value *Check::checkScopeObjectMember(const UiQualifiedId *id)
}
if (!value) {
error(id->identifierToken,
QCoreApplication::translate("QmlJS::Check", "'%1' is not a valid property name").arg(propertyName));
Check::tr("'%1' is not a valid property name").arg(propertyName));
}
// can't look up members for attached properties
......@@ -336,7 +335,7 @@ const Value *Check::checkScopeObjectMember(const UiQualifiedId *id)
const ObjectValue *objectValue = value_cast<const ObjectValue *>(value);
if (! objectValue) {
error(idPart->identifierToken,
QCoreApplication::translate("QmlJS::Check", "'%1' does not have members").arg(propertyName));
Check::tr("'%1' does not have members").arg(propertyName));
return 0;
}
......@@ -352,7 +351,7 @@ const Value *Check::checkScopeObjectMember(const UiQualifiedId *id)
value = objectValue->lookupMember(propertyName, &_context);
if (! value) {
error(idPart->identifierToken,
QCoreApplication::translate("QmlJS::Check", "'%1' is not a member of '%2'").arg(
Check::tr("'%1' is not a member of '%2'").arg(
propertyName, objectValue->className()));
return 0;
}
......
......@@ -36,6 +36,8 @@
#include <qmljs/qmljsscopebuilder.h>
#include <qmljs/parser/qmljsastvisitor_p.h>
#include <QtCore/QCoreApplication>
namespace QmlJS {
class QMLJS_EXPORT Check: protected AST::Visitor
......@@ -46,6 +48,8 @@ public:
QList<DiagnosticMessage> operator()();
Q_DECLARE_TR_FUNCTIONS(QmlJS::Check)
protected:
virtual bool visit(AST::UiProgram *ast);
virtual bool visit(AST::UiObjectDefinition *ast);
......
......@@ -331,6 +331,8 @@ public:
: _xml(dev)
{}
Q_DECLARE_TR_FUNCTIONS(QmlJS::Interpreter::QmlXmlReader)
bool operator()(QMap<QString, FakeMetaObject *> *objects) {
Q_ASSERT(objects);
_objects = objects;
......@@ -339,7 +341,7 @@ public:
if (_xml.name() == "module")
readModule();
else
_xml.raiseError(QCoreApplication::translate("QmlJS::Interpreter::QmlXmlReader", "The file is not module file."));
_xml.raiseError(tr("The file is not module file."));
}
return !_xml.error();
......@@ -351,7 +353,7 @@ public:
private:
void unexpectedElement(const QStringRef &child, const QString &parent) {
_xml.raiseError(QCoreApplication::translate("QmlJS::Interpreter::QmlXmlReader", "Unexpected element <%1> in <%2>").arg(child.toString(), parent));
_xml.raiseError(tr("Unexpected element <%1> in <%2>").arg(child.toString(), parent));
}
void ignoreAttr(const QXmlStreamAttribute &attr) {
......@@ -360,11 +362,11 @@ private:
}
void invalidAttr(const QString &value, const QString &attrName, const QString &tag) {
_xml.raiseError(QCoreApplication::translate("QmlJS::Interpreter::QmlXmlReader", "invalid value '%1' for attribute %2 in <%3>").arg(value, attrName, tag));
_xml.raiseError(tr("invalid value '%1' for attribute %2 in <%3>").arg(value, attrName, tag));
}
void noValidAttr(const QString &attrName, const QString &tag) {
_xml.raiseError(QCoreApplication::translate("QmlJS::Interpreter::QmlXmlReader", "<%1> has no valid %2 attribute").arg(tag, attrName));
_xml.raiseError(tr("<%1> has no valid %2 attribute").arg(tag, attrName));
}
void readModule()
......@@ -1920,8 +1922,8 @@ QStringList MetaTypeSystem::load(const QFileInfoList &xmlFiles)
}
file.close();
} else {
errorMsgs.append(QCoreApplication::translate("QmlJS::Interpreter::QmlXmlReader", "%1: %2").arg(xmlFile.absoluteFilePath(),
file.errorString()));
errorMsgs.append(QmlXmlReader::tr("%1: %2").arg(xmlFile.absoluteFilePath(),
file.errorString()));
}
}
......
......@@ -8,7 +8,6 @@
#include <QtCore/QFileInfo>
#include <QtCore/QDir>
#include <QtCore/QDebug>
#include <QtCore/QCoreApplication>
using namespace QmlJS;
using namespace QmlJS::Interpreter;
......@@ -211,7 +210,7 @@ void Link::importFile(Interpreter::ObjectValue *typeEnv, Document::Ptr doc,
importNamespace->setProperty(targetName, importedDoc->bind()->rootObjectValue());
} else {
error(doc, import->fileNameToken,
QCoreApplication::translate("QmlJS::Link", "could not find file or directory"));
tr("could not find file or directory"));
}
}
......@@ -253,7 +252,7 @@ void Link::importNonFile(Interpreter::ObjectValue *typeEnv, Document::Ptr doc, A
const int dotIdx = versionString.indexOf(QLatin1Char('.'));
if (dotIdx == -1) {
error(doc, import->versionToken,
QCoreApplication::translate("QmlJS::Link", "expected two numbers separated by a dot"));
tr("expected two numbers separated by a dot"));
return;
} else {
majorVersion = versionString.left(dotIdx).toInt();
......@@ -261,7 +260,7 @@ void Link::importNonFile(Interpreter::ObjectValue *typeEnv, Document::Ptr doc, A
}
} else {
error(doc, locationFromRange(import->firstSourceLocation(), import->lastSourceLocation()),
QCoreApplication::translate("QmlJS::Link", "package import requires a version number"));
tr("package import requires a version number"));
return;
}
......@@ -307,7 +306,7 @@ void Link::importNonFile(Interpreter::ObjectValue *typeEnv, Document::Ptr doc, A
}
error(doc, locationFromRange(import->firstSourceLocation(), import->lastSourceLocation()),
QCoreApplication::translate("QmlJS::Link", "package not found"));
tr("package not found"));
}
UiQualifiedId *Link::qualifiedTypeNameId(Node *node)
......
......@@ -8,6 +8,7 @@
#include <QtCore/QList>
#include <QtCore/QHash>
#include <QtCore/QStringList>
#include <QtCore/QCoreApplication>
namespace QmlJS {
......@@ -26,6 +27,8 @@ public:
QList<DiagnosticMessage> diagnosticMessages() const;
Q_DECLARE_TR_FUNCTIONS(QmlJS::Link)
private:
Interpreter::Engine *engine();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment