Exemplo n.º 1
0
QObject * LanguageResource::resource()
{
    if (d->m_languageResource != 0) {
        return d->m_languageResource;
    }

    if (!d->m_path.isLocalFile()) {
        qWarning() << "Cannot open language file at " << d->m_path.toLocalFile() << ", aborting.";
        return 0;
    }

    QXmlSchema schema = loadXmlSchema("language");
    if (!schema.isValid()) {
        return 0;
    }

    QDomDocument document = loadDomDocument(d->m_path, schema);
    if (document.isNull()) {
        qWarning() << "Could not parse document " << d->m_path.toLocalFile() << ", aborting.";
        return 0;
    }

    QDomElement root(document.documentElement());
    d->m_languageResource = new Language(this);
    d->m_languageResource->setFile(d->m_path);
    d->m_languageResource->setId(root.firstChildElement("id").text());
    d->m_languageResource->setTitle(root.firstChildElement("title").text());
    d->m_languageResource->seti18nTitle(root.firstChildElement("i18nTitle").text());
    // create phoneme groups
    for (QDomElement groupNode = root.firstChildElement("phonemeGroups").firstChildElement();
         !groupNode.isNull();
         groupNode = groupNode.nextSiblingElement())
    {
        PhonemeGroup *group = d->m_languageResource->addPhonemeGroup(
            groupNode.firstChildElement("id").text(),
            groupNode.firstChildElement("title").text());
        group->setDescription(groupNode.attribute("description"));
        // register phonemes
        for (QDomElement phonemeNode = groupNode.firstChildElement("phonemes").firstChildElement();
            !phonemeNode.isNull();
            phonemeNode = phonemeNode.nextSiblingElement())
        {
            group->addPhoneme(phonemeNode.firstChildElement("id").text(), phonemeNode.firstChildElement("title").text());
        }
    }

    return d->m_languageResource;
}
Exemplo n.º 2
0
void TestLanguageFiles::checkIdUniqueness()
{
    ResourceManager manager;
    QStringList languageFiles = QStandardPaths::locateAll(QStandardPaths::DataLocation, QString("data/languages/*.xml"));
    foreach (const QString &file, languageFiles) {
        qDebug() << "File being parsed: " << file;
        QStringList idList;
        const QUrl &languageFile = QUrl::fromLocalFile(file);
        QVERIFY(languageFile.isLocalFile());

        QXmlSchema schema = loadXmlSchema("language");
        QVERIFY(schema.isValid());

        QDomDocument document = loadDomDocument(languageFile, schema);
        QVERIFY(!document.isNull());

        QDomElement root(document.documentElement());
        Language *language = new Language(this);
        language->setFile(languageFile);
        language->setId(root.firstChildElement("id").text());
        language->setTitle(root.firstChildElement("title").text());
        // create phoneme groups
        for (QDomElement groupNode = root.firstChildElement("phonemeGroups").firstChildElement();
                !groupNode.isNull();
                groupNode = groupNode.nextSiblingElement())
        {
            for (QDomElement phonemeNode = groupNode.firstChildElement("phonemes").firstChildElement();
                    !phonemeNode.isNull();
                    phonemeNode = phonemeNode.nextSiblingElement())
            {
                QString id = phonemeNode.firstChildElement("id").text();
                qDebug() << "ID: " << id;
                QVERIFY2(!idList.contains(id),"Phoneme ID used more than once in the tested file");
                idList.append(id);
            }
        }
    }