bool TranslationMemoryUpdater::UpdateFromMO(const wxString& filename) { wxString tmp = wxFileName::CreateTempFileName("poedit"); wxLogNull null; if ( tmp.empty() ) return false; if (!ExecuteGettext(_T("msgunfmt --force-po -o \"") + tmp + _T("\" \"") + filename + _T("\""))) return false; bool rt = UpdateFromCatalog(tmp); wxRemoveFile(tmp); return rt; }
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; }
wxString Extract(TempDirectory& tmpdir, const SourceCodeSpec& sourceSpec, const std::vector<wxString>& files) const override { auto basepath = sourceSpec.BasePath; #ifdef __WXMSW__ basepath = CliSafeFileName(basepath); basepath.Replace("\\", "/"); #endif wxTextFile filelist; filelist.Create(tmpdir.CreateFileName("gettext_filelist.txt")); for (auto fn: files) { #ifdef __WXMSW__ // Gettext tools can't handle Unicode filenames well (due to using // char* arguments), so work around this by using the short names. if (!fn.IsAscii()) { fn = CliSafeFileName(fn); fn.Replace("\\", "/"); } #endif filelist.AddLine(fn); } filelist.Write(wxTextFileType_Unix, wxConvFile); auto outfile = tmpdir.CreateFileName("gettext.pot"); wxString cmdline; cmdline.Printf ( "xgettext --force-po -o %s --directory=%s --files-from=%s --from-code=%s", QuoteCmdlineArg(outfile), QuoteCmdlineArg(basepath), QuoteCmdlineArg(filelist.GetName()), QuoteCmdlineArg(!sourceSpec.Charset.empty() ? sourceSpec.Charset : "UTF-8") ); auto additional = GetAdditionalFlags(); if (!additional.empty()) cmdline += " " + additional; for (auto& kw: sourceSpec.Keywords) { cmdline += wxString::Format(" -k%s", QuoteCmdlineArg(kw)); } wxString extraFlags; try { extraFlags = sourceSpec.XHeaders.at("X-Poedit-Flags-xgettext"); } catch (std::out_of_range) {} if (!extraFlags.Contains("--add-comments")) cmdline += " --add-comments=TRANSLATORS:"; if (!extraFlags.empty()) cmdline += " " + extraFlags; if (!ExecuteGettext(cmdline)) return ""; return outfile; }