36 OString lcl_NormalizeFilename(std::string_view rFilename)
38 size_t idx1 = rFilename.rfind(
'\\' );
39 size_t idx2 = rFilename.rfind(
'/' );
40 if (idx1 == std::string_view::npos && idx2 == std::string_view::npos)
41 return OString(rFilename);
42 if (idx1 == std::string_view::npos)
44 if (idx2 == std::string_view::npos)
46 return OString(rFilename.substr(std::max(idx1, idx2)+1));
49 bool lcl_ReadPoChecked(
51 const OString& rFileName)
59 SAL_WARN(
"l10ntools", rFileName <<
" contains invalid entry");
71 sGId(
std::move( _sGId ))
73 sGId =
sGId.replaceAll(
"\r", OString());
78 sGId(
std::move( _sGId )),
79 sFilename(
std::move( _sFilename ))
81 sGId =
sGId.replaceAll(
"\r", OString());
88 const OString &nLangIndex,
bool bDel )
91 rReturn =
sText[ nLangIndex ];
93 sText[ nLangIndex ] =
"";
101 OString GetDoubleBars()
111 const OString sFilename = rResData.
sFilename.copy(rResData.
sFilename.lastIndexOf(
'/')+1);
114 return sKey + GetDoubleBars() + rOrigText;
120 const OString &rFileName, std::string_view rFile,
121 bool bCaseSensitive,
bool bWithQtz )
123 auto const env = getenv(
"ENABLE_RELEASE_BUILD");
124 OString sEnableReleaseBuild(
env ==
nullptr ?
"" :
env);
126 std::ifstream aInputStream( rFileName.getStr() );
127 if ( !aInputStream.is_open() )
129 SAL_WARN(
"l10ntools",
"Can't open po path container file for " << rFileName);
133 aInputStream >> sPoFile;
134 bool bFirstLang =
true;
135 while( !aInputStream.eof() )
137 bool bSkipCurrentPOFile =
false;
138 const OString sFileName( lcl_NormalizeFilename(rFile) );
139 const bool bReadAll = sFileName.isEmpty();
141 const OString sPoFileName(sPoFile.data(),
static_cast<sal_Int32
>(sPoFile.length()));
143 aPoInput.
open( sPoFileName );
146 SAL_WARN(
"l10ntools",
"Can't open file: " << sPoFileName);
153 static constexpr OStringLiteral sTransSource(
"translations/source/");
154 const sal_Int32 nStart =
155 sPoFileName.indexOf(sTransSource)+sTransSource.getLength();
157 sPoFileName.indexOf(
'/',nStart) - nStart;
158 sLang = sPoFileName.copy(nStart,
nCount);
164 if( !lcl_ReadPoChecked(aNextPo, aPoInput, sPoFileName) )
166 bSkipCurrentPOFile =
true;
169 }
while( !aPoInput.
eof() && aNextPo.
getSourceFile() != sFileName && !bReadAll );
170 while( !aPoInput.
eof() && (aNextPo.
getSourceFile() == sFileName || bReadAll ) && !bSkipCurrentPOFile )
174 bool bInSameComp =
false;
186 if( aActPo.
isFuzzy() || sTemp.isEmpty() )
203 if( !lcl_ReadPoChecked(aNextPo, aPoInput, sPoFileName) )
205 bSkipCurrentPOFile =
true;
211 }
while( bInSameComp );
217 bFirstLang, bCaseSensitive );
219 if( bFirstLang && bWithQtz &&
220 sEnableReleaseBuild !=
"TRUE" )
228 false, bCaseSensitive );
232 aInputStream >> sPoFile;
235 aInputStream.close();
249 OString sOldG = pResData->
sGId;
250 OString sOldL = pResData->
sId;
251 OString sGID = pResData->
sGId;
254 sGID = pResData->
sId;
256 sLID = pResData->
sId;
257 pResData->
sGId = sGID;
258 pResData->
sId = sLID;
262 auto mit =
aMap.find( sKey );
263 if(mit !=
aMap.end())
265 pResData->
sGId = sOldG;
266 pResData->
sId = sOldL;
267 return mit->second.get();
269 pResData->
sGId = sOldG;
270 pResData->
sId = sOldL;
287 std::string_view rTYP, std::string_view rGID,
288 std::string_view rLID,
const OString &nLANG,
289 const OString &rTEXT,
const OString &rQHTEXT,
290 const OString &rTITLE, std::string_view rInFilename,
291 bool bFirstLang,
bool bCaseSensitive )
296 OString sKey =
CreateKey(rTYP , rGID , rLID , rInFilename , bCaseSensitive);
300 auto mit =
aMap.find( sKey );
301 if(mit !=
aMap.end())
302 pMergeEntrys = mit->second.get();
309 if (!
aMap.emplace( sKey, std::unique_ptr<MergeEntrys>(pMergeEntrys) ).second)
311 std::cerr <<
"Duplicate entry " << sKey <<
"\n";
312 std::exit(EXIT_FAILURE);
320 const OString sTemp = OString::Concat(rInFilename) + rGID + rLID + rTYP;
323 rTEXT.isEmpty()? rTEXT :
PoEntry::genKeyId(sTemp + rTEXT) + GetDoubleBars() + rTEXT,
324 rQHTEXT.isEmpty()? rQHTEXT :
PoEntry::genKeyId(sTemp + rQHTEXT) + GetDoubleBars() + rQHTEXT,
325 rTITLE.isEmpty()? rTITLE :
PoEntry::genKeyId(sTemp + rTITLE) + GetDoubleBars() + rTITLE );
329 pMergeEntrys->
InsertEntry( nLANG , rTEXT, rQHTEXT, rTITLE );
334 std::string_view rLID, std::string_view rFilename,
bool bCaseSensitive)
336 static const char sStroke[] =
"-";
337 OString sKey = OString::Concat(rTYP) + sStroke + rGID + sStroke + rLID + sStroke +
338 lcl_NormalizeFilename(rFilename);
341 return sKey.toAsciiUpperCase();
MergeDataFile(const OString &rFileName, std::string_view rFile, bool bCaseSensitive, bool bWithQtz=true)
static OString CreateKey(std::string_view rTYP, std::string_view rGID, std::string_view rLID, std::string_view rFilename, bool bCaseSensitive)
std::unordered_map< OString, std::unique_ptr< MergeEntrys > > aMap
std::set< OString > aLanguageSet
void InsertEntry(std::string_view rTYP, std::string_view rGID, std::string_view rLID, const OString &nLang, const OString &rTEXT, const OString &rQHTEXT, const OString &rTITLE, std::string_view sFilename, bool bFirstLang, bool bCaseSensitive)
MergeEntrys * GetMergeData(ResData *pResData, bool bCaseSensitive=false)
MergeEntrys * GetMergeEntrys(ResData *pResData)
MergeEntrys * GetMergeEntrysCaseSensitive(ResData *pResData)
std::vector< OString > GetLanguages() const
Purpose: holds information of data to merge.
OStringBoolHashMap bTextFirst
void InsertEntry(const OString &rId, const OString &rText, const OString &rQuickHelpText, const OString &rTitle)
static OString GetQTZText(const ResData &rResData, std::string_view rOrigText)
Generate QTZ string with ResData For executable which works one language and without PO files.
bool GetText(OString &rReturn, const OString &nLangIndex, bool bDel=false)
Interface to use po entries in localization.
OString const & getMsgId() const
OString getResourceType() const
Get the type of component from which entry is extracted.
OString getGroupId() const
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.
Interface to read po entry from files as input streams.
void open(const OString &rFileName)
void readEntry(PoEntry &rPo)
Purpose: holds mandatory data to export a single res.
#define SAL_WARN(area, stream)
const css::uno::Reference< css::xml::crypto::XSecurityEnvironment > & env