Ejemplo n.º 1
0
Catalog *SourceDigger::Dig(const wxArrayString& paths,
                           const wxArrayString& excludePaths,
                           const wxArrayString& keywords,
                           const wxString& charset)
{
    ExtractorsDB db;
    db.Read(wxConfig::Get());

    m_progressInfo->UpdateMessage(_("Scanning files..."));

    wxArrayString *all_files = FindFiles(paths, excludePaths, db);
    if (all_files == NULL)
        return NULL;

    TempDirectory tmpdir;
    wxArrayString partials;

    for (size_t i = 0; i < db.Data.size(); i++)
    {
        if ( all_files[i].empty() )
            continue; // no files of this kind

        m_progressInfo->UpdateMessage(
            // TRANSLATORS: '%s' is replaced with the kind of the files (e.g. C++, PHP, ...)
            wxString::Format(_("Parsing %s files..."), db.Data[i].Name.c_str()));
        if (!DigFiles(tmpdir, partials, all_files[i], db.Data[i], keywords, charset))
        {
            delete[] all_files;
            return NULL;
        }
    }

    delete[] all_files;

    if ( partials.empty() )
        return NULL; // couldn't parse any source files

    wxString mergedFile = tmpdir.CreateFileName("merged.pot");

    if ( !ConcatCatalogs(partials, mergedFile) )
        return NULL;

    Catalog *c = new Catalog(mergedFile, Catalog::CreationFlag_IgnoreHeader);

    if ( !c->IsOk() )
    {
        wxLogError(_("Failed to load extracted catalog."));
        delete c;
        return NULL;
    }

    return c;
}
Ejemplo n.º 2
0
CatalogPtr SourceDigger::Dig(const wxArrayString& paths,
                             const wxArrayString& excludePaths,
                             const wxArrayString& keywords,
                             const wxString& charset,
                             UpdateResultReason& reason)
{
    ExtractorsDB db;
    db.Read(wxConfig::Get());

    m_progressInfo->UpdateMessage(_("Scanning files..."));

    wxArrayString *all_files = FindFiles(paths, PathsToMatch(excludePaths), db);
    if (all_files == nullptr)
    {
        reason = UpdateResultReason::NoSourcesFound;
        return nullptr;
    }

    TempDirectory tmpdir;
    wxArrayString partials;

    for (size_t i = 0; i < db.Data.size(); i++)
    {
        if ( all_files[i].empty() )
            continue; // no files of this kind

        m_progressInfo->UpdateMessage(
            // TRANSLATORS: '%s' is replaced with the kind of the files (e.g. C++, PHP, ...)
            wxString::Format(_("Parsing %s files..."), db.Data[i].Name.c_str()));
        if (!DigFiles(tmpdir, partials, all_files[i], db.Data[i], keywords, charset))
        {
            delete[] all_files;
            return nullptr;
        }
    }

    delete[] all_files;

    wxString mergedFile;
    if ( !ConcatCatalogs(partials, tmpdir, &mergedFile) )
        return nullptr; // couldn't parse any source files

    CatalogPtr c = std::make_shared<Catalog>(mergedFile, Catalog::CreationFlag_IgnoreHeader);

    if ( !c->IsOk() )
    {
        wxLogError(_("Failed to load extracted catalog."));
        return nullptr;
    }

    return c;
}
Ejemplo n.º 3
0
bool SourceDigger::DigFiles(TempDirectory& tmpdir,
                            wxArrayString& outFiles,
                            const wxArrayString& files,
                            Extractor &extract, const wxArrayString& keywords,
                            const wxString& charset)
{
    wxArrayString batchfiles;
    wxArrayString tempfiles;
    size_t i, last = 0;

    while (last < files.GetCount())
    {
        batchfiles.clear();
        for (i = last; i < last + BATCH_SIZE && i < files.size(); i++)
            batchfiles.Add(files[i]);
        last = i;

        wxString tempfile = tmpdir.CreateFileName("extracted.pot");
        if (!ExecuteGettext(
                    extract.GetCommand(batchfiles, keywords, tempfile, charset)))
        {
            return false;
        }

        tempfiles.push_back(tempfile);

        m_progressInfo->UpdateGauge((int)batchfiles.GetCount());

        if (m_progressInfo->Cancelled())
            return false;
    }

    if ( tempfiles.empty() )
        return false; // failed to parse any source files

    wxString outfile = tmpdir.CreateFileName("merged_chunks.pot");
    if ( !ConcatCatalogs(tempfiles, outfile) )
        return false;

    outFiles.push_back(outfile);
    return true;
}