[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    branches/KDE/3.5/kdesdk/kbabel/filters/gettext
From:       Nicolas Goutte <nicolasg () snafu ! de>
Date:       2005-10-21 18:19:21
Message-ID: 1129918761.241864.28020.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 472721 by goutte:

HACK: support of Gettext context by transforming them into a Gettext comment
(Patch by Bruno Haible  bruno clisp org)


 M  +20 -2     gettextexport.cpp  
 M  +69 -1     gettextimport.cpp  


--- branches/KDE/3.5/kdesdk/kbabel/filters/gettext/gettextexport.cpp #472720:472721
@@ -158,10 +158,28 @@
 	  }
 	  
 	  // write entry
-	  if(!catalog->comment(counter).isEmpty())
+	  QString comment = catalog->comment(counter);
+	  QString msgctxt;
+	  bool haveMsgctxt=false;
+	  // Temporary hack until msgctxt is properly supported.
+	  if(comment.find(QRegExp("^# MsgContext: ")) != -1)
 	  {
-	      stream << catalog->comment(counter) << "\n";
+	      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);
 	  QValueList<QString>::ConstIterator lit;
--- branches/KDE/3.5/kdesdk/kbabel/filters/gettext/gettextimport.cpp #472720:472721
@@ -326,12 +326,14 @@
 
 ConversionStatus GettextImportPlugin::readEntry(QTextStream& stream)
 {
-   enum {Begin,Comment,Msgid,Msgstr} part=Begin;
+   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,6 +381,17 @@
                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,6 +438,17 @@
             {
                _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,6 +481,42 @@
                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,6 +725,14 @@
             }
         }
     }
+
+    // Temporary hack until msgctxt is properly supported.
+    if(seenMsgctxt)
+    {
+        if (!_comment.isEmpty())
+          _comment+="\n";
+        _comment+="# MsgContext: "+msgctxt;
+    }
 /*
    if(_gettextPluralForm)
    {
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic