diff options
-rw-r--r-- | l10ntools/inc/po.hxx | 2 | ||||
-rw-r--r-- | l10ntools/source/po.cxx | 36 | ||||
-rw-r--r-- | l10ntools/source/pocheck.cxx | 5 |
3 files changed, 39 insertions, 4 deletions
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; |