Bug 121236 - Don't save po files correctly
Summary: Don't save po files correctly
Status: RESOLVED FIXED
Alias: None
Product: kbabel
Classification: Miscellaneous
Component: general (show other bugs)
Version: 1.11.1
Platform: unspecified Linux
: NOR normal
Target Milestone: ---
Assignee: Stanislav Visnovsky
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-02-02 17:11 UTC by Ronny Kissing
Modified: 2006-02-08 00:55 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
po file created by kdevelop, manually edited. (7.96 KB, text/plain)
2006-02-03 14:28 UTC, Ronny Kissing
Details
de.po (7.96 KB, application/x-gettext)
2006-02-03 14:31 UTC, Ronny Kissing
Details
hu.po (5.81 KB, application/x-gettext)
2006-02-03 14:31 UTC, Ronny Kissing
Details
pl.po (5.81 KB, application/x-gettext)
2006-02-03 14:31 UTC, Ronny Kissing
Details
ru.po (5.81 KB, application/x-gettext)
2006-02-03 14:31 UTC, Ronny Kissing
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Ronny Kissing 2006-02-02 17:11:39 UTC
Version:           1.11.1 (using KDE 3.5.0 Level "a" , SUSE 10.0 UNSUPPORTED)
Compiler:          Target: x86_64-suse-linux
OS:                Linux (x86_64) release 2.6.13-15.7-default

kbabel allways tells that the header of the po file is not correct.

The following errors appear: 

msgfmt hat einen Syntaxfehler im Vorspann entdeckt.
Ausgabe von "msgfmt --statistics":
/home/ronny/de.po:6: »msgid«- und »msgstr«-Eintrag enden nicht jeweils mit »\n«
/home/ronny/de.po:22: Mehrfachdefinition der Meldung
/home/ronny/de.po:7: ...dies ist die Stelle der ersten Definition
msgfmt: /home/ronny/de.po: Warnung: Kopfteil der PO-Datei fehlt oder ist ungültig
Warnung: Konvertierung des Zeichensatzes wird fehlschlagen.
msgfmt: es sind 3 fatale Fehler aufgetreten
Bitte bearbeiten Sie die Datei noch einmal.

This is by every new po file created within a kdevelop project.
Comment 1 Nicolas Goutte 2006-02-03 14:18:07 UTC
Can you attach the file to this bug report please?

The error about \n is not KBabel's fault, as it is the job of the translator.

As for a duplicate entry, I would suspect that it is not KBabel's problem either, as KBabel does not create new entries.

So it probably mean that the file loaded into KBabel was already wrong.

Have a nice day!
Comment 2 Ronny Kissing 2006-02-03 14:28:00 UTC
Created attachment 14522 [details]
po file created by kdevelop, manually edited.

This po file was created from kdevelop an when manually edited, it works all
fine. 

But kbabel does not handel this file well
Comment 3 Ronny Kissing 2006-02-03 14:31:42 UTC
Am Freitag, 3. Februar 2006 14:18 schrieb Nicolas Goutte:
[bugs.kde.org quoted mail]
The file is attached.

But I don't know where else the error could be.
Every po file kdevelop creates by adding a new translation, kbabel does not 
save it and allways show that error. 

KDevelop can not be the program which handles po files in the wrong way. By 
editing the po file by hand, adding the translated text, in an text editor, 
the po file is quiet ok and compiles well.

I don't know what to do.

cheers
Ronny Kissing


Created an attachment (id=14523)
de.po

Created an attachment (id=14524)
hu.po

Created an attachment (id=14525)
pl.po

Created an attachment (id=14526)
ru.po
Comment 4 Nicolas Goutte 2006-02-03 15:51:42 UTC
On Friday 03 February 2006 14:28, Ronny Kissing wrote:
(...)
> ------- Additional Comments From ronny.kissing gmx net  2006-02-03 14:28
> ------- Created an attachment (id=14522)
>  --> (http://bugs.kde.org/attachment.cgi?id=14522&action=view)
> po file created by kdevelop, manually edited.
>
> This po file was created from kdevelop an when manually edited, it works
> all fine.


The problem is that this PO file has no header at all. So if it is really 
something from KDevelop, then KDevelop must be fixed.

>
> But kbabel does not handel this file well


Sure, KBabel expects that PO files have a header. (So indeed it is also 
KBabel's problem.)

Have a nice day!
Comment 5 Nicolas Goutte 2006-02-03 16:16:08 UTC
I have checked how KBabel saves the de.po file. (KBabel *does* save. The error message is only from the msgfmt check and is done after writing the file.)

KBabel tries to make a header out of the first message. That is why it is duplicated and also why there is this error about the \n mismatch. Of course, KBabel should create a header from scratch if there is not any and not do such a thing.

What KBabel will probably not know how to fix is the encoding of the file, as de.po does not declare any encoding (as there is no header).

Have a nice day!
Comment 6 Nicolas Goutte 2006-02-08 00:55:06 UTC
SVN commit 506958 by goutte:

Create a temporary header if the header entry has a non-empty msgid
BUG:121236


 M  +28 -8     gettextimport.cpp  


--- branches/KDE/3.5/kdesdk/kbabel/filters/gettext/gettextimport.cpp #506957:506958
@@ -128,11 +128,31 @@
       kdDebug( KBABEL ) << "Parse error in header entry" << endl;
       return status;
    }
-
-   // ### TODO: check that the msgid is empty (if not, we might have a PO file without header)
-   tempHeader.setMsgid( _msgid );
-   tempHeader.setMsgstr( _msgstr );
-   tempHeader.setComment( _comment );
+   
+   kdDebug() << "HEADER MSGID: " << _msgid << endl;
+   kdDebug() << "HEADER MSGSTR: " << _msgstr << endl;
+   if ( !_msgid.isEmpty() && !_msgid.first().isEmpty() )
+   {
+      // The header must have an empty msgid
+      kdWarning(KBABEL) << "Header entry has non-empty msgid. Creating a temporary header! " << _msgid << endl;
+      tempHeader.setMsgid( QStringList() );
+      QStringList tmp;
+      tmp.append(
+         "Content-Type: text/plain; charset=UTF-8\\n" // Unknown charset
+         "Content-Transfer-Encoding: 8bit\\n"
+         "Mime-Version: 1.0" );
+      tempHeader.setMsgstr( tmp );
+      // We keep the comment of the first entry, as it might really be a header comment (at least partially)
+      const QString comment( "# Header entry was created by KBabel!\n#\n" + _comment );
+      tempHeader.setComment( comment );
+      recoveredErrorInHeader = true;
+   }
+   else
+   {
+      tempHeader.setMsgid( _msgid );
+      tempHeader.setMsgstr( _msgstr );
+      tempHeader.setComment( _comment );
+   }
    if(tempHeader.isFuzzy())
    {
       tempHeader.removeFuzzy();
@@ -358,7 +378,7 @@
 
 ConversionStatus GettextImportPlugin::readEntry(QTextStream& stream)
 {
-   kdDebug( KBABEL ) << k_funcinfo << " START" << endl;
+   //kdDebug( KBABEL ) << k_funcinfo << " START" << endl;
    enum {Begin,Comment,Msgctxt,Msgid,Msgstr} part=Begin;
 
    QString line;
@@ -382,7 +402,7 @@
 
        line=stream.readLine();
 
-       kdDebug() << "Parsing line: " << line << endl;
+       //kdDebug() << "Parsing line: " << line << endl;
 
        // ### Qt4: no need of a such a check
        if(line.isNull()) // file end
@@ -785,7 +805,7 @@
    }
   */
 
-    kdDebug( KBABEL ) << k_funcinfo << " NEAR RETURN" << endl;
+    //kdDebug( KBABEL ) << k_funcinfo << " NEAR RETURN" << endl;
     if(error)
        return PARSE_ERROR;
 	else if(recoverableError)