Re: Fwd: gettext and contexts
Bruno Haible <[email protected]> Fri, 21 Oct 2005 13:37:33 +0200
| Newsgroups | gmane.comp.kde.devel.kbabel |
|---|---|
| Message-ID | <[email protected]> |
Chusslove Illich wrote: > Anyway, thinking in this direction, 3.5 KBabel is feature frosen, but what > exactly constitutes a feature freeze? I had this idea: currently, if the > msgid_plural comes, the msgid pane is going to split into two tabs to show > both ... Well, if you say that KBabel 3.5 is feature frozen, for the moment we should perhaps try a patch that doesn't affect the GUI at all. Here is an attempt on this, touching only the input and output filters. Patch relative to on kdesdk-472179. Completely untested, since I don't have the right environment for compiling and testing KDE programs. Also attached are two sample PO files with msgctxt in it. Bruno _______________________________________________ kbabel mailing list [email protected] https://mail.kde.org/mailman/listinfo/kbabel
uu
(text/x-diff, 5 KB)
*** kbabel/filters/gettext/gettextimport.cpp.bak 2005-10-04 03:10:55.000000000 +0200
--- kbabel/filters/gettext/gettextimport.cpp 2005-10-21 13:28:00.000000000 +0200
***************
*** 326,337 ****
ConversionStatus GettextImportPlugin::readEntry(QTextStream& stream)
{
! enum {Begin,Comment,Msgid,Msgstr} part=Begin;
QString line;
bool cancelLoop=false;
bool error=false;
bool recoverableError=false;
_msgstr.clear();
_msgstr.append(QString());
_msgid.clear();
--- 326,339 ----
ConversionStatus GettextImportPlugin::readEntry(QTextStream& stream)
{
! enum {Begin,Comment,Msgctxt,Msgid,Msgstr} part=Begin;
QString line;
bool cancelLoop=false;
bool error=false;
bool recoverableError=false;
+ QString msgctxt;
+ bool seenMsgctxt=false;
_msgstr.clear();
_msgstr.append(QString());
_msgid.clear();
***************
*** 379,384 ****
--- 381,397 ----
part=Comment;
_comment=line;
}
+ else if(line.find(QRegExp("^msgctxt\\s*\".*\"$")) != -1)
+ {
+ part=Msgctxt;
+
+ // remove quotes at beginning and the end of the lines
+ line.remove(QRegExp("^msgctxt\\s*\""));
+ line.remove(QRegExp("\"$"));
+ // TODO: support multi-line contexts
+ msgctxt=line;
+ seenMsgctxt=true;
+ }
else if(line.find(QRegExp("^msgid\\s*\".*\"$")) != -1)
{
part=Msgid;
***************
*** 425,430 ****
--- 438,454 ----
{
_comment+=("\n"+line);
}
+ else if(line.find(QRegExp("^msgctxt\\s*\".*\"$")) != -1)
+ {
+ part=Msgctxt;
+
+ // remove quotes at beginning and the end of the lines
+ line.remove(QRegExp("^msgctxt\\s*\""));
+ line.remove(QRegExp("\"$"));
+ // TODO: support multi-line contexts
+ msgctxt=line;
+ seenMsgctxt=true;
+ }
else if(line.find(QRegExp("^msgid\\s*\".*\"$")) != -1)
{
part=Msgid;
***************
*** 457,462 ****
--- 481,522 ----
cancelLoop=true;
}
}
+ else if(part==Msgctxt)
+ {
+ if(line.isEmpty())
+ continue;
+ if(line.find(QRegExp("^msgid\\s*\".*\"$")) != -1)
+ {
+ part=Msgid;
+
+ // remove quotes at beginning and the end of the lines
+ line.remove(QRegExp("^msgid\\s*\""));
+ line.remove(QRegExp("\"$"));
+
+ (*(_msgid).begin())=line;
+ }
+ // one of the quotation marks is missing
+ else if(line.find(QRegExp("^msgid\\s*\"?.*\"?$")) != -1)
+ {
+ part=Msgid;
+
+ // remove quotes at beginning and the end of the lines
+ line.remove(QRegExp("^msgid\\s*\"?"));
+ line.remove(QRegExp("\"$"));
+
+ (*(_msgid).begin())=line;
+
+ if(!line.isEmpty())
+ recoverableError=true;
+ }
+ else
+ {
+ kdDebug(KBABEL) << "no msgid found after a msgctxt while parsing: " << msgctxt << endl;
+
+ error=true;
+ cancelLoop=true;
+ }
+ }
else if(part==Msgid)
{
if(line.isEmpty())
***************
*** 665,670 ****
--- 725,738 ----
}
}
}
+
+ // Temporary hack until msgctxt is properly supported.
+ if(seenMsgctxt)
+ {
+ if (!_comment.isEmpty())
+ _comment+="\n";
+ _comment+="# MsgContext: "+msgctxt;
+ }
/*
if(_gettextPluralForm)
{
*** kbabel/filters/gettext/gettextexport.cpp.bak 2005-10-04 03:10:55.000000000 +0200
--- kbabel/filters/gettext/gettextexport.cpp 2005-10-21 13:28:00.000000000 +0200
***************
*** 158,166 ****
}
// write entry
! if(!catalog->comment(counter).isEmpty())
{
! stream << catalog->comment(counter) << "\n";
}
QStringList list=msgidAsList(catalog, counter);
--- 158,184 ----
}
// write entry
! QString comment = catalog->comment(counter);
! QString msgctxt;
! bool haveMsgctxt=false;
! // Temporary hack until msgctxt is properly supported.
! if(comment.find(QRegExp("^# MsgContext: ")) != -1)
{
! int pos=comment.find(QRegExp("^# MsgContext: "));
! msgctxt=comment.right(comment.length()-pos-14);
! haveMsgctxt=true;
! comment=comment.left(pos);
! if(comment.endsWith('\n'))
! comment=comment.left(pos-1));
! }
! if(!comment.isEmpty())
! {
! stream << comment << "\n";
! }
! if(haveMsgctxt)
! {
! // TODO: support multi-line contexts
! stream << "msgctxt \"" << msgctxt << "\"\n";
}
QStringList list=msgidAsList(catalog, counter);
uu.pot
(application/x-gettext, 126 B) - not displayed
qttest2_de.po
(application/x-gettext, 952 B) - not displayed