Current (QT 4.7.1) .ts file header keeps track of target and source languages
and looks like this:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.0" language="en_US" sourcelanguage="it_IT">

Meanwhile pylupdate4 from pyqt 4.8.3 does not keep track of the sourcelanguage
attribute that was introduced in QT 4.5.

Attached patch loads and saves the sourcelanguage, plus it bumps the "version"
attribute to 2.0 (not sure if this is a good idea :-)
don't want to keep a nonstandard tree.
-- 
            Giuseppe Corbelli
WASP Software Engineer, Copan Italia S.p.A
Phone: +390303666104  Fax: +390302659932
E-mail: giuseppe.corbe...@copanitalia.com
--- PyQt-x11-gpl-4.8.3/pylupdate/merge.cpp	2011-01-23 11:08:28.000000000 +0100
+++ pylupdate/merge.cpp	2011-03-03 15:32:04.050000010 +0100
@@ -50,6 +50,7 @@
     TML all = tor->messages();
     TML::Iterator it;
     outTor->setLanguageCode(tor->languageCode());
+    outTor->setSourceLanguageCode(tor->sourceLanguageCode());
 
     /*
       The types of all the messages from the vernacular translator
--- PyQt-x11-gpl-4.8.3/pylupdate/metatranslator.h	2011-01-23 11:08:28.000000000 +0100
+++ pylupdate/metatranslator.h	2011-03-03 15:30:42.354000010 +0100
@@ -119,8 +119,10 @@
     QString toUnicode( const char *str, bool utf8 ) const;
 
     QString languageCode() const;
+    QString sourceLanguageCode() const;
     static void languageAndCountry(const QString &languageCode, QLocale::Language *lang, QLocale::Country *country);
     void setLanguageCode(const QString &languageCode);
+    void setSourceLanguageCode(const QString &languageCode);
     QList<MetaTranslatorMessage> messages() const;
     QList<MetaTranslatorMessage> translatedMessages() const;
     static int grammaticalNumerus(QLocale::Language language, QLocale::Country country);
@@ -144,6 +146,7 @@
                             // 'pt'         portuguese, assumes portuguese from portugal
                             // 'pt_BR'      Brazilian portuguese (ISO 639-1 language code)
                             // 'por_BR'     Brazilian portuguese (ISO 639-2 language code)
+    QString m_sourceLanguage;
 };
 
 /*
--- PyQt-x11-gpl-4.8.3/pylupdate/metatranslator.cpp	2011-01-23 11:08:28.000000000 +0100
+++ pylupdate/metatranslator.cpp	2011-03-03 15:38:44.348000010 +0100
@@ -71,12 +71,14 @@
     virtual bool characters( const QString& ch );
     virtual bool fatalError( const QXmlParseException& exception );
     QString language() const { return m_language; }
+    QString sourceLanguage() const { return m_sourceLanguage; }
 
 private:
     MetaTranslator *tor;
     MetaTranslatorMessage::Type type;
     bool inMessage;
     QString m_language;
+    QString m_sourceLanguage;
     QString context;
     QString source;
     QString comment;
@@ -113,6 +115,7 @@
     } else {
         if ( qName == QString("TS") ) {
             m_language = atts.value(QLatin1String("language"));
+            m_sourceLanguage = atts.value(QLatin1String("sourcelanguage"));
         } else if ( qName == QString("context") ) {
             context.truncate( 0 );
             source.truncate( 0 );
@@ -394,6 +397,7 @@
     reader.setErrorHandler( 0 );
 
     m_language = hand->language();
+    m_sourceLanguage = hand->sourceLanguage();
     makeFileNamesAbsolute(QFileInfo(filename).absoluteDir());
 
     delete hand;
@@ -413,9 +417,10 @@
     //### The xml prolog allows processors to easily detect the correct encoding
     t << "<?xml version=\"1.0\"";
     t << " encoding=\"utf-8\"";
-    t << "?>\n<!DOCTYPE TS><TS version=\"1.1\"";
+    t << "?>\n<!DOCTYPE TS><TS version=\"2.0\"";
     if (!languageCode().isEmpty() && languageCode() != QLatin1String("C"))
-        t << " language=\"" << languageCode() << "\"";
+        t << " language=\"" << languageCode() << "\"" <<\
+            " sourcelanguage=\"" << sourceLanguageCode() << "\"";
     t << ">\n";
     if ( codecName != "ISO-8859-1" )
         t << "<defaultcodec>" << codecName << "</defaultcodec>\n";
@@ -580,11 +585,21 @@
     return m_language;
 }
 
+QString MetaTranslator::sourceLanguageCode() const
+{
+    return m_sourceLanguage;
+}
+
 void MetaTranslator::setLanguageCode(const QString &languageCode)
 {
     m_language = languageCode;
 }
 
+void MetaTranslator::setSourceLanguageCode(const QString &languageCode)
+{
+    m_sourceLanguage = languageCode;
+}
+
 bool MetaTranslator::contains( const char *context, const char *sourceText,
                                const char *comment ) const
 {
_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

Reply via email to