From b44b9c4519794d159b154a9713c10da1155a5198 Mon Sep 17 00:00:00 2001 From: Christian Lohmaier Date: Sat, 27 Oct 2018 13:45:43 +0200 Subject: pocheck: don't choke on plural forms Change-Id: I51a82ce5fc09d44ebc6f7c06c67b475ee2adf68b Reviewed-on: https://gerrit.libreoffice.org/62419 Reviewed-by: Christian Lohmaier Tested-by: Jenkins --- l10ntools/source/po.cxx | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'l10ntools') diff --git a/l10ntools/source/po.cxx b/l10ntools/source/po.cxx index 27daba097a42..bb4a06c03f36 100644 --- a/l10ntools/source/po.cxx +++ b/l10ntools/source/po.cxx @@ -33,7 +33,9 @@ private: std::vector m_sReferences; OString m_sMsgCtxt; OString m_sMsgId; + OString m_sMsgIdPlural; OString m_sMsgStr; + std::vector m_sMsgStrPlural; bool m_bFuzzy; bool m_bCFormat; bool m_bNull; @@ -118,7 +120,9 @@ GenPoEntry::GenPoEntry() , m_sReferences( std::vector() ) , m_sMsgCtxt( OString() ) , m_sMsgId( OString() ) + , m_sMsgIdPlural( OString() ) , m_sMsgStr( OString() ) + , m_sMsgStrPlural( std::vector() ) , m_bFuzzy( false ) , m_bCFormat( false ) , m_bNull( false ) @@ -148,8 +152,16 @@ void GenPoEntry::writeToFile(std::ofstream& rOFStream) const << std::endl; rOFStream << "msgid " << lcl_GenMsgString(m_sMsgId) << std::endl; - rOFStream << "msgstr " - << lcl_GenMsgString(m_sMsgStr) << std::endl; + if ( !m_sMsgIdPlural.isEmpty() ) + rOFStream << "msgid_plural " + << lcl_GenMsgString(m_sMsgIdPlural) + << std::endl; + if ( !m_sMsgStrPlural.empty() ) + for(auto & line : m_sMsgStrPlural) + rOFStream << line.copy(0,10) << lcl_GenMsgString(line.copy(10)) << std::endl; + else + rOFStream << "msgstr " + << lcl_GenMsgString(m_sMsgStr) << std::endl; } void GenPoEntry::readFromFile(std::ifstream& rIFStream) @@ -196,11 +208,22 @@ void GenPoEntry::readFromFile(std::ifstream& rIFStream) m_sMsgId = lcl_GenNormString(sLine.copy(6)); pLastMsg = &m_sMsgId; } + else if (sLine.startsWith("msgid_plural ")) + { + m_sMsgIdPlural = lcl_GenNormString(sLine.copy(13)); + pLastMsg = &m_sMsgIdPlural; + } else if (sLine.startsWith("msgstr ")) { m_sMsgStr = lcl_GenNormString(sLine.copy(7)); pLastMsg = &m_sMsgStr; } + else if (sLine.startsWith("msgstr[")) + { + // assume there are no more than 10 plural forms... + // and that plural strings are never split to multi-line in po + m_sMsgStrPlural.push_back(sLine.copy(0,10) + lcl_GenNormString(sLine.copy(10))); + } else if (sLine.startsWith("\"") && pLastMsg) { OString sReference; -- cgit