1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_L10NTOOLS_INC_EXPORT_HXX
21 #define INCLUDED_L10NTOOLS_INC_EXPORT_HXX
23 #include <sal/config.h>
29 #include <osl/file.hxx>
34 #include <unordered_map>
46 #define NO_TRANSLATE_ISO "x-no-translate"
50 typedef std::unordered_map
<OString
, OString
>
53 typedef std::unordered_map
<OString
, bool>
56 #define SOURCE_LANGUAGE "en-US"
57 #define X_COMMENT "x-comment"
63 enum class IdLevel
{ Null
=0, Text
=2, Identifier
=5 };
65 /// Purpose: holds mandatory data to export a single res
69 ResData( const OString
&rGId
);
70 ResData( const OString
&rGId
, const OString
&rFilename
);
84 enum class ExportListType
{
85 NONE
, String
, Filter
, Item
, Paired
88 enum class StringType
{
89 Text
, QuickHelpText
, Title
98 /// Purpose: holds information of data to merge
101 friend class MergeDataFile
;
103 OStringHashMap sText
;
104 OStringBoolHashMap bTextFirst
;
105 OStringHashMap sQuickHelpText
;
106 OStringBoolHashMap bQuickHelpTextFirst
;
107 OStringHashMap sTitle
;
108 OStringBoolHashMap bTitleFirst
;
112 void InsertEntry(const OString
&rId
, const OString
&rText
,
113 const OString
&rQuickHelpText
, const OString
&rTitle
)
116 sText
[ rId
] = rText
;
117 bTextFirst
[ rId
] = true;
118 sQuickHelpText
[ rId
] = rQuickHelpText
;
119 bQuickHelpTextFirst
[ rId
] = true;
120 sTitle
[ rId
] = rTitle
;
121 bTitleFirst
[ rId
] = true;
123 bool GetText( OString
&rReturn
, const OString
&nLangIndex
, bool bDel
= false );
126 Generate QTZ string with ResData
127 For executable which works one language and without PO files.
129 static OString
GetQTZText(const ResData
& rResData
, const OString
& rOrigText
);
134 // class MergeDataHashMap
139 /** Container for MergeData
141 This class is an HashMap with a hidden insertion
142 order. The class can used just like a simple
143 HashMap, but good to know that it's use is
144 more effective if the accessing(find) order
145 match with the insertion order.
147 In the most case, this match is good.
148 (e.g. reading PO files of different languages,
151 class MergeDataHashMap
154 typedef std::unordered_map
<OString
, std::unique_ptr
<MergeData
>> HashMap_t
;
159 , aLastInsertion(m_aHashMap
.end())
160 , aLastFound(m_aHashMap
.end())
161 , aFirstInOrder(m_aHashMap
.end())
165 typedef HashMap_t::iterator iterator
;
166 typedef HashMap_t::const_iterator const_iterator
;
168 std::pair
<iterator
,bool> insert(const OString
& rKey
, std::unique_ptr
<MergeData
> pMergeData
);
169 iterator
const & find(const OString
& rKey
);
171 iterator
end() {return m_aHashMap
.end();}
175 HashMap_t m_aHashMap
;
176 iterator aLastInsertion
;
178 iterator aFirstInOrder
;
185 /// Purpose: holds information of data to merge (one resource)
188 friend class MergeDataHashMap
;
191 std::unique_ptr
<MergeEntrys
> pMergeEntrys
;
193 MergeDataHashMap::iterator m_aNextData
;
197 MergeEntrys
* GetMergeEntries() { return pMergeEntrys
.get();}
202 // class MergeDataFile
205 /// Purpose: holds information of data to merge, read from PO file
209 MergeDataHashMap aMap
;
210 std::set
<OString
> aLanguageSet
;
212 MergeData
*GetMergeData( ResData
*pResData
, bool bCaseSensitive
= false );
213 void InsertEntry(const OString
&rTYP
, const OString
&rGID
,
214 const OString
&rLID
, const OString
&nLang
,
215 const OString
&rTEXT
, const OString
&rQHTEXT
,
216 const OString
&rTITLE
, const OString
&sFilename
,
217 bool bFirstLang
, bool bCaseSensitive
);
219 explicit MergeDataFile(
220 const OString
&rFileName
, const OString
& rFile
,
221 bool bCaseSensitive
, bool bWithQtz
= true );
225 std::vector
<OString
> GetLanguages() const;
227 MergeEntrys
*GetMergeEntrys( ResData
*pResData
);
228 MergeEntrys
*GetMergeEntrysCaseSensitive( ResData
*pResData
);
230 static OString
CreateKey(const OString
& rTYP
, const OString
& rGID
,
231 const OString
& rLID
, const OString
& rFilename
, bool bCaseSensitive
);
235 #endif // INCLUDED_L10NTOOLS_INC_EXPORT_HXX
237 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */