[Libreoffice-commits] core.git: 2 commits - l10ntools/inc l10ntools/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Sat Nov 17 10:50:52 UTC 2018


 l10ntools/inc/po.hxx          |    2 +
 l10ntools/source/localize.cxx |   55 ++++++++++++++++--------------------------
 l10ntools/source/po.cxx       |   36 +++++++++++++++++++++++++--
 l10ntools/source/pocheck.cxx  |    5 ++-
 4 files changed, 60 insertions(+), 38 deletions(-)

New commits:
commit 9ffe350ae344e9863330fbb2405c37df6b9d0984
Author:     Christian Lohmaier <lohmaier+LibreOffice at googlemail.com>
AuthorDate: Thu Nov 15 13:19:31 2018 +0100
Commit:     Christian Lohmaier <lohmaier+LibreOffice at googlemail.com>
CommitDate: Sat Nov 17 11:50:46 2018 +0100

    pocheck: don't throw away Plural-Forms header
    
    also don't change POT creation date when rewriting a po file, update
    Po-Revision instead.
    When creating templates, put X-Accelerator before X-Generator (like
    pootle would order it)
    
    Change-Id: I7fec4cb1c50e27b87decd9a892de3f01a02253ed
    Reviewed-on: https://gerrit.libreoffice.org/63416
    Tested-by: Jenkins
    Reviewed-by: Christian Lohmaier <lohmaier+LibreOffice at googlemail.com>

diff --git a/l10ntools/inc/po.hxx b/l10ntools/inc/po.hxx
index e213f47e177a..aff8b88af100 100644
--- a/l10ntools/inc/po.hxx
+++ b/l10ntools/inc/po.hxx
@@ -88,6 +88,7 @@ public:
     friend class PoIfstream;
 
                     PoHeader( const OString& rExtSrc ); ///< Template Constructor
+                    PoHeader( const OString& rExtSrc, const OString& rPoHeaderMsgStr );
                     ~PoHeader();
                     PoHeader(const PoHeader&) = delete;
     PoHeader&       operator=(const PoHeader&) = delete;
@@ -139,6 +140,7 @@ public:
     bool    eof() const     { return m_bEof; }
 
     void    open(const OString& rFileName);
+    void    open(const OString& rFileName, OString& sPoHeader);
     void    close();
     void    readEntry(PoEntry& rPo);
 };
diff --git a/l10ntools/source/po.cxx b/l10ntools/source/po.cxx
index bb4a06c03f36..4e60d82160d3 100644
--- a/l10ntools/source/po.cxx
+++ b/l10ntools/source/po.cxx
@@ -446,6 +446,16 @@ namespace
     }
 }
 
+// when updating existing files (pocheck), reuse provided po-header
+PoHeader::PoHeader( const OString& rExtSrc, const OString& rPoHeaderMsgStr )
+    : m_pGenPo( new GenPoEntry() )
+    , m_bIsInitialized( false )
+{
+    m_pGenPo->setExtractCom("extracted from " + rExtSrc);
+    m_pGenPo->setMsgStr(rPoHeaderMsgStr);
+    m_bIsInitialized = true;
+}
+
 PoHeader::PoHeader( const OString& rExtSrc )
     : m_pGenPo( new GenPoEntry() )
     , m_bIsInitialized( false )
@@ -462,8 +472,8 @@ PoHeader::PoHeader( const OString& rExtSrc )
         "MIME-Version: 1.0\n"
         "Content-Type: text/plain; charset=UTF-8\n"
         "Content-Transfer-Encoding: 8bit\n"
-        "X-Generator: LibreOffice\n"
-        "X-Accelerator-Marker: ~\n"));
+        "X-Accelerator-Marker: ~\n"
+        "X-Generator: LibreOffice\n"));
     m_bIsInitialized = true;
 }
 
@@ -562,6 +572,28 @@ PoIfstream::~PoIfstream()
     }
 }
 
+void PoIfstream::open( const OString& rFileName, OString& rPoHeader )
+{
+    assert( !isOpen() );
+    m_aInPut.open( rFileName.getStr(), std::ios_base::in );
+
+    // capture header, updating timestamp and generator
+    std::string sTemp;
+    std::getline(m_aInPut,sTemp);
+    while( !sTemp.empty() && !m_aInPut.eof() )
+    {
+        std::getline(m_aInPut,sTemp);
+        OString sLine = OString(sTemp.data(),sTemp.length());
+        if (sLine.startsWith("\"PO-Revision-Date"))
+            rPoHeader += "PO-Revision-Date: " + lcl_GetTime() + "\n";
+        else if (sLine.startsWith("\"X-Generator"))
+            rPoHeader += "X-Generator: LibreOffice\n";
+        else if (sLine.startsWith("\""))
+            rPoHeader += lcl_GenNormString(sLine);
+    }
+    m_bEof = false;
+}
+
 void PoIfstream::open( const OString& rFileName )
 {
     assert( !isOpen() );
diff --git a/l10ntools/source/pocheck.cxx b/l10ntools/source/pocheck.cxx
index 49aa9551c3fb..14b9983ec20d 100644
--- a/l10ntools/source/pocheck.cxx
+++ b/l10ntools/source/pocheck.cxx
@@ -90,7 +90,8 @@ static void checkStyleNames(const OString& aLanguage)
                 "\nSee STR_POOLNUMRULE_*\n\n";
         }
     }
-    aPoInput.open(aPoPath);
+    OString sPoHdrMsg;
+    aPoInput.open(aPoPath, sPoHdrMsg);
     if( !aPoInput.isOpen() )
     {
         std::cerr << "Warning: Cannot open " << aPoPath << std::endl;
@@ -98,7 +99,7 @@ static void checkStyleNames(const OString& aLanguage)
     }
     PoOfstream aPoOutput;
     aPoOutput.open(aPoPath+".new");
-    PoHeader aTmp("sw/inc");
+    PoHeader aTmp("sw/inc", sPoHdrMsg);
     aPoOutput.writeHeader(aTmp);
     bool bAnyError = false;
 
commit 344773c608ea28718b630590ee1023247aa62d63
Author:     Christian Lohmaier <lohmaier+LibreOffice at googlemail.com>
AuthorDate: Mon Nov 12 13:09:23 2018 +0100
Commit:     Christian Lohmaier <lohmaier+LibreOffice at googlemail.com>
CommitDate: Sat Nov 17 11:50:31 2018 +0100

    localize: sort directories to have predictable sorting in pot files
    
    also remove pre-onegit special handling
    
    Change-Id: Ie60be508a188e00b9eea1b743ea10f1f985c459e
    Reviewed-on: https://gerrit.libreoffice.org/63288
    Tested-by: Jenkins
    Reviewed-by: Christian Lohmaier <lohmaier+LibreOffice at googlemail.com>

diff --git a/l10ntools/source/localize.cxx b/l10ntools/source/localize.cxx
index c2bc7c262fcb..f169fd31fac7 100644
--- a/l10ntools/source/localize.cxx
+++ b/l10ntools/source/localize.cxx
@@ -23,6 +23,7 @@
 #include <cstdlib>
 #include <iostream>
 #include <string>
+#include <map>
 #include <vector>
 #include <algorithm>
 
@@ -319,10 +320,9 @@ bool includeProject(const OString& rProject) {
 ///
 /// @param rUrl the absolute file URL of this directory
 ///
-/// @param nLevel 0 if this is either the root directory that contains the
-/// projects or one of the clone/* or src/* directories that contain the
-/// additional projects; -1 if this is the clone directory; 1 if this
-/// is a project directory; 2 if this is a directory inside a project
+/// @param nLevel 0 if this is the root directory (core repository)
+/// that contains the individual modules. 1 if it is a toplevel module and
+/// larger values for the subdirectories.
 ///
 /// @param rProject the name of the project (empty and ignored if nLevel <= 0)
 /// @param rPotDir the path of pot directory
@@ -337,6 +337,7 @@ void handleDirectory(
         throw false; //TODO
     }
     std::vector<OUString> aFileNames;
+    std::map<OUString, std::map<OString, OString>> aSubDirs;
     for (;;) {
         osl::DirectoryItem item;
         osl::FileBase::RC e = dir.getNextItem(item);
@@ -356,36 +357,18 @@ void handleDirectory(
         }
         const OString sDirName =
             OUStringToOString(stat.getFileName(),RTL_TEXTENCODING_UTF8);
-        switch (nLevel) {
-        case -1: // the clone or src directory
-            if (stat.getFileType() == osl::FileStatus::Directory) {
-                handleDirectory(
-                    stat.getFileURL(), 0, OString(), rPotDir);
-            }
-            break;
-        case 0: // a root directory
-            if (stat.getFileType() == osl::FileStatus::Directory) {
-                if (includeProject(sDirName)) {
-                    handleDirectory(
-                        stat.getFileURL(), 1, sDirName, rPotDir.concat("/").concat(sDirName));
-                } else if ( sDirName == "clone" ||
-                            sDirName == "src" )
-                {
-                    handleDirectory( stat.getFileURL(), -1, OString(), rPotDir);
-                }
-            }
-            break;
-        default:
-            if (stat.getFileType() == osl::FileStatus::Directory)
-            {
-                handleDirectory(
-                    stat.getFileURL(), 2, rProject, rPotDir.concat("/").concat(sDirName));
-            }
-            else
-            {
-                aFileNames.push_back(stat.getFileURL());
-            }
-            break;
+        switch (nLevel)
+        {
+            case 0: // a root directory
+                if (stat.getFileType() == osl::FileStatus::Directory && includeProject(sDirName))
+                    aSubDirs[stat.getFileURL()][sDirName] = rPotDir.concat("/").concat(sDirName);
+                break;
+            default:
+                if (stat.getFileType() == osl::FileStatus::Directory)
+                    aSubDirs[stat.getFileURL()][rProject] = rPotDir.concat("/").concat(sDirName);
+                else
+                    aFileNames.push_back(stat.getFileURL());
+                break;
         }
     }
 
@@ -409,6 +392,10 @@ void handleDirectory(
         throw false; //TODO
     }
 
+    for (auto const& elem : aSubDirs)
+        handleDirectory(elem.first, nLevel + 1, elem.second.begin()->first,
+                        elem.second.begin()->second);
+
     //Remove empty pot directory
     OUString sPoPath =
         OStringToOUString(


More information about the Libreoffice-commits mailing list