Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Format saved files according to default gettext style.
As a stop-gap measure for the infamous bug #25 , run saved PO files
through msgcat to format them in the exact same way msgmerge would by
default. This makes the problem much less serious, as Poedit will now do
the right thing for most people. It still doesn't respect less usual
formatting settings (--indent, --width, --no-wrap) of existing files.
Fixes #348 . Also see #25 .
Loading branch information
Showing
2 changed files
with
35 additions
and
11 deletions .
+3
−1
NEWS
+32
−10
src/catalog.cpp
There are no files selected for viewing
@@ -26,7 +26,9 @@ Version 1.5 (not yet released)
- improved source files viewer (#346)
- included outdated documentation was replaced with online wiki docs (#343)
- more keyboard navigation shortcuts
- saving PO files no longer reformats source code references (#323)
- saving PO files no longer reformats source code references (#323);
moreover, they are always formatted according to the default style
used by GNU gettext tools (#348)
Version 1.4.6
@@ -1334,15 +1334,12 @@ bool Catalog::Save(const wxString& po_file, bool save_mo)
}
m_header.Charset = charset;
const wxString po_file_temp = po_file + _T (" .temp.po" );
if ( wxFileExists (po_file_temp) )
wxRemoveFile (po_file_temp);
wxTextFile f;
if (!wxFileExists (po_file) || !f.Open (po_file, wxConvISO8859_1))
if (!f.Create (po_file))
return false ;
for (int j = f.GetLineCount () - 1 ; j >= 0 ; j--)
f.RemoveLine (j);
wxCSConv encConv (charset);
if (!f.Create (po_file_temp))
return false ;
SaveMultiLines (f, m_header.Comment );
f.AddLine (_T (" msgid \"\" " ));
@@ -1418,10 +1415,35 @@ bool Catalog::Save(const wxString& po_file, bool save_mo)
f.AddLine (deletedItem.GetDeletedLines ()[j]);
}
f.Write (crlf, encConv);
f.Write (crlf, wxCSConv (charset));
f.Close ();
// Now that the file was written, run msgcat to re-format it according
// to the usual format. This is a good enough fix for #25 until proper
// preservation of formatting is implemented.
if ( ExecuteGettext
(
wxString::Format (_T (" msgcat --force-po -o \" %s\" \" %s\" " ),
po_file.c_str (),
po_file_temp.c_str ())
)
&& wxFileExists (po_file)
)
{
wxRemoveFile (po_file_temp);
}
else
{
if ( !wxRemoveFile (po_file) || !wxRenameFile (po_file_temp, po_file) )
{
wxLogWarning (_ (" Couldn't save file %s." ), po_file.c_str ());
}
else
{
wxLogWarning (_ (" There was a problem formatting the file nicely (but it was saved all right)." ));
}
}
/* Poedit < 1.3.0 used to save additional info in .po.poedit file. It's
not used anymore, so delete the file if it exists: */
if (wxFileExists (po_file + _T (" .poedit" )))
Toggle all file notes
Toggle all file annotations