10#include <rtl/ustring.hxx>
11#include <rtl/strbuf.hxx>
83 OString lcl_GenMsgString(std::string_view rString)
85 if ( rString.empty() )
93 while((nIndex=sResult.indexOf(
"\\n",nIndex))!=-1)
95 if( !sResult.match(
"\\\\n", nIndex-1) &&
96 nIndex!=sResult.getLength()-3)
98 sResult = sResult.replaceAt(nIndex,2,
"\\n\"\n\"");
103 if ( sResult.indexOf(
'\n') != -1 )
104 return "\"\"\n" + sResult;
110 OString lcl_GenNormString(std::string_view rString)
114 rString.substr(1,rString.size()-2),
115 "\\n""\\t""\\r""\\\\""\\\"",
116 "\n""\t""\r""\\""\"");
122 , m_bCFormat( false )
129 if ( rOFStream.tellp() != std::ofstream::pos_type( 0 ))
130 rOFStream << std::endl;
134 <<
m_sExtractCom.toString().replaceAll(
"\n",
"\n#. ") << std::endl;
136 rOFStream <<
"#: " << rReference << std::endl;
138 rOFStream <<
"#, fuzzy" << std::endl;
140 rOFStream <<
"#, c-format" << std::endl;
142 rOFStream <<
"msgctxt "
145 rOFStream <<
"msgid "
146 << lcl_GenMsgString(
m_sMsgId) << std::endl;
148 rOFStream <<
"msgid_plural "
153 rOFStream <<
line.copy(0,10) << lcl_GenMsgString(
line.subView(10)) << std::endl;
155 rOFStream <<
"msgstr "
156 << lcl_GenMsgString(
m_sMsgStr) << std::endl;
162 OString* pLastMsg =
nullptr;
164 getline(rIFStream,sTemp);
165 if( rIFStream.eof() || sTemp.empty() )
170 while(!rIFStream.eof())
172 OString sLine(sTemp.data(),sTemp.length());
173 if (sLine.startsWith(
"#. "))
181 else if (sLine.startsWith(
"#: "))
185 else if (sLine.startsWith(
"#, fuzzy"))
189 else if (sLine.startsWith(
"#, c-format"))
193 else if (sLine.startsWith(
"msgctxt "))
195 m_sMsgCtxt = lcl_GenNormString(sLine.subView(8));
198 else if (sLine.startsWith(
"msgid "))
200 m_sMsgId = lcl_GenNormString(sLine.subView(6));
203 else if (sLine.startsWith(
"msgid_plural "))
208 else if (sLine.startsWith(
"msgstr "))
210 m_sMsgStr = lcl_GenNormString(sLine.subView(7));
213 else if (sLine.startsWith(
"msgstr["))
217 m_sMsgStrPlural.push_back(sLine.subView(0,10) + lcl_GenNormString(sLine.subView(10)));
219 else if (sLine.startsWith(
"\"") && pLastMsg)
226 if (pLastMsg != &
m_sMsgCtxt || sLine != Concat2View(
"\"" + sReference +
"\\n\""))
228 *pLastMsg += lcl_GenNormString(sLine);
233 getline(rIFStream,sTemp);
238 : m_bIsInitialized( false )
243 std::string_view rSourceFile, std::string_view rResType, std::string_view rGroupId,
244 std::string_view rLocalId, std::string_view rHelpText,
245 const OString& rText,
const TYPE eType )
246 : m_bIsInitialized( false )
248 if( rSourceFile.empty() )
250 else if ( rResType.empty() )
252 else if ( rGroupId.empty() )
254 else if ( rText.isEmpty() )
256 else if ( rHelpText.size() == 5 )
260 size_t idx = rSourceFile.rfind(
'/');
261 if (
idx == std::string_view::npos)
263 OString sReference(rSourceFile.substr(
idx+1));
269 (rLocalId.empty() ? OString() : OString::Concat(rLocalId) +
"\n") +
273 sMsgCtxt +=
".text";
break;
275 sMsgCtxt +=
".quickhelptext";
break;
277 sMsgCtxt +=
".title";
break;
282 m_pGenPo->setExtractCom(Concat2View(
283 ( !rHelpText.empty() ? OString::Concat(rHelpText) +
"\n" : OString()) +
284 genKeyId(
m_pGenPo->getReference().front() + rGroupId + rLocalId + rResType + rText ) ));
293 : m_pGenPo( rPo.m_pGenPo ? new
GenPoEntry( *(rPo.m_pGenPo) ) : nullptr )
294 , m_bIsInitialized( rPo.m_bIsInitialized )
325 m_pGenPo = std::move(rPo.m_pGenPo);
326 m_bIsInitialized = std::move(rPo.m_bIsInitialized);
333 return m_pGenPo->getReference().front();
339 return m_pGenPo->getMsgCtxt().getToken(0,
'\n');
345 const OString sMsgCtxt =
m_pGenPo->getMsgCtxt();
346 if (sMsgCtxt.indexOf(
'\n')==sMsgCtxt.lastIndexOf(
'\n'))
349 return sMsgCtxt.getToken(1,
'\n');
355 const OString sMsgCtxt =
m_pGenPo->getMsgCtxt();
356 if (sMsgCtxt.indexOf(
'\n')==sMsgCtxt.lastIndexOf(
'\n'))
357 return sMsgCtxt.getToken(1,
'\n').getToken(0,
'.');
359 return sMsgCtxt.getToken(2,
'\n').getToken(0,
'.');
365 const OString sMsgCtxt =
m_pGenPo->getMsgCtxt();
366 const OString
sType = sMsgCtxt.copy( sMsgCtxt.lastIndexOf(
'.') + 1 );
369 if (
sType ==
"text" )
371 else if (
sType ==
"quickhelptext" )
417 sal_uInt32 nCRC = rtl_crc32(0, rGenerator.getStr(), rGenerator.getLength());
419 static const char sSymbols[] =
420 "ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz23456789";
422 for(
short nKeyInd = 0; nKeyInd < 5; ++nKeyInd )
424 sKeyId[nKeyInd] = sSymbols[(nCRC & 63) % strlen(sSymbols)];
434 OString lcl_GetTime()
436 time_t aNow = time(
nullptr);
437 struct tm* pNow = localtime(&aNow);
439 strftime( pBuff,
sizeof pBuff,
"%Y-%m-%d %H:%M%z", pNow );
447 , m_bIsInitialized( false )
449 m_pGenPo->setExtractCom(Concat2View(OString::Concat(
"extracted from ") + rExtSrc));
450 m_pGenPo->setMsgStr(rPoHeaderMsgStr);
456 , m_bIsInitialized( false )
458 m_pGenPo->setExtractCom(Concat2View(OString::Concat(
"extracted from ") + rExtSrc));
460 "Project-Id-Version: PACKAGE VERSION\n"
461 "Report-Msgid-Bugs-To: https://bugs.libreoffice.org/enter_bug.cgi?"
462 "product=LibreOffice&bug_status=UNCONFIRMED&component=UI\n"
463 "POT-Creation-Date: " + lcl_GetTime() +
464 "\nPO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
465 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
466 "Language-Team: LANGUAGE <LL@li.org>\n"
467 "MIME-Version: 1.0\n"
468 "Content-Type: text/plain; charset=UTF-8\n"
469 "Content-Transfer-Encoding: 8bit\n"
470 "X-Accelerator-Marker: ~\n"
471 "X-Generator: LibreOffice\n");
480 : m_bIsAfterHeader( false )
485 : m_bIsAfterHeader( false )
487 open( rFileName, aMode );
504 std::ios_base::out | std::ios_base::trunc );
507 else if( aMode ==
APP )
510 std::ios_base::out | std::ios_base::app );
538bool lcl_CheckInputEntry(
const GenPoEntry& rEntry)
572 m_aInPut.open( rFileName.getStr(), std::ios_base::in );
577 while( !sTemp.empty() && !
m_aInPut.eof() )
580 OString sLine(sTemp.data(),sTemp.length());
581 if (sLine.startsWith(
"\"PO-Revision-Date"))
582 rPoHeader +=
"PO-Revision-Date: " + lcl_GetTime() +
"\n";
583 else if (sLine.startsWith(
"\"X-Generator"))
584 rPoHeader +=
"X-Generator: LibreOffice\n";
585 else if (sLine.startsWith(
"\""))
586 rPoHeader += lcl_GenNormString(sLine);
594 m_aInPut.open( rFileName.getStr(), std::ios_base::in );
599 while( !sTemp.empty() && !
m_aInPut.eof() )
624 if( lcl_CheckInputEntry(aGenPo) )
void readFromFile(std::ifstream &rIFStream)
const OString & getMsgCtxt() const
void setReference(const OString &rReference)
void setExtractCom(std::string_view rExtractCom)
const OString & getMsgStr() const
void writeToFile(std::ofstream &rOFStream) const
std::vector< OString > m_sMsgStrPlural
const std::vector< OString > & getReference() const
std::vector< OString > m_sReferences
void setMsgCtxt(const OString &rMsgCtxt)
void setMsgStr(const OString &rMsgStr)
void setMsgId(const OString &rMsgId)
const OString & getMsgId() const
OStringBuffer m_sExtractCom
Interface to use po entries in localization.
OString const & getMsgId() const
OString const & getMsgCtxt() const
OString getResourceType() const
Get the type of component from which entry is extracted.
OString getGroupId() const
std::unique_ptr< GenPoEntry > m_pGenPo
PoEntry & operator=(const PoEntry &rPo)
OString const & getSourceFile() const
Get name of file from which entry is extracted.
OString const & getMsgStr() const
static OString genKeyId(const OString &rGenerator)
static bool IsInSameComp(const PoEntry &rPo1, const PoEntry &rPo2)
Check whether po-s belong to the same localization component.
OString getLocalId() const
TYPE getType() const
Get the type of entry.
void open(const OString &rFileName)
void readEntry(PoEntry &rPo)
void open(const OString &rFileName, OpenMode aMode=TRUNC)
void writeHeader(const PoHeader &rHeader)
void writeEntry(const PoEntry &rPo)
#define SAL_WARN(area, stream)
OString escapeAll(std::string_view rText, std::string_view rUnEscaped, std::string_view rEscaped)
Escape all given character in the text.
OString unEscapeAll(std::string_view rText, std::string_view rEscaped, std::string_view rUnEscaped)
Unescape all given character in the text.
TransliterationModules tm