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/.
10 #ifndef INCLUDED_L10NTOOLS_INC_PO_HXX
11 #define INCLUDED_L10NTOOLS_INC_PO_HXX
15 #include <string_view>
17 #include <rtl/string.hxx>
24 /** Interface to use po entries in localization
26 PoEntry based on GenPoEntry class which stores attributes
27 of general po entry(see po.cxx). It makes easy to get/set
28 all information needed to localize one english(US) string.
29 It contains some basic checkings and some string
30 transformations between po string and string used by
37 std::unique_ptr
<GenPoEntry
> m_pGenPo
;
38 bool m_bIsInitialized
;
42 friend class PoOfstream
;
43 friend class PoIfstream
;
45 enum TYPE
{ TTEXT
, TQUICKHELPTEXT
, TTITLE
};
46 enum Exception
{ NOSOURCFILE
, NORESTYPE
, NOGROUPID
, NOSTRING
, WRONGHELPTEXT
};
49 PoEntry( std::string_view rSourceFile
, std::string_view rResType
, std::string_view rGroupId
,
50 std::string_view rLocalId
, std::string_view rHelpText
, const OString
& rText
,
54 PoEntry( const PoEntry
& rPo
);
55 PoEntry
& operator=( const PoEntry
& rPo
);
56 PoEntry
& operator=( PoEntry
&& rPo
) noexcept
;
58 OString
const & getSourceFile() const; ///< Get name of file from which entry is extracted
59 OString
getGroupId() const;
60 OString
getLocalId() const;
61 OString
getResourceType() const; ///< Get the type of component from which entry is extracted
62 TYPE
getType() const; ///< Get the type of entry
63 OString
const & getMsgCtxt() const;
64 OString
const & getMsgId() const;
65 OString
const & getMsgStr() const;
68 /// Check whether po-s belong to the same localization component
69 static bool IsInSameComp(const PoEntry
& rPo1
,const PoEntry
& rPo2
);
70 static OString
genKeyId(const OString
& rGenerator
);
74 /** Interface to work with header of po/pot files
76 This class stores information which is in header of
77 a po file. It's main function to generate header to
78 template po files(pot).
84 std::unique_ptr
<GenPoEntry
> m_pGenPo
;
85 bool m_bIsInitialized
;
89 friend class PoOfstream
;
90 friend class PoIfstream
;
92 PoHeader( std::string_view rExtSrc
); ///< Template Constructor
93 PoHeader( std::string_view rExtSrc
, const OString
& rPoHeaderMsgStr
);
95 PoHeader(const PoHeader
&) = delete;
96 PoHeader
& operator=(const PoHeader
&) = delete;
99 /// Interface to write po entry to files as output streams
104 std::ofstream m_aOutPut
;
105 bool m_bIsAfterHeader
;
109 enum OpenMode
{ TRUNC
, APP
};
112 PoOfstream(const OString
& rFileName
, OpenMode aMode
);
114 PoOfstream(const PoOfstream
&) = delete;
115 PoOfstream
& operator=(const PoOfstream
&) = delete;
116 bool isOpen() const { return m_aOutPut
.is_open(); }
118 void open(const OString
& rFileName
, OpenMode aMode
= TRUNC
);
120 void writeHeader(const PoHeader
& rHeader
);
121 void writeEntry(const PoEntry
& rPo
);
124 /// Interface to read po entry from files as input streams
129 std::ifstream m_aInPut
;
134 class Exception final
: public std::exception
{ };
137 PoIfstream( const OString
& rFileName
);
139 PoIfstream(const PoIfstream
&) = delete;
140 PoIfstream
& operator=(const PoIfstream
&) = delete;
141 bool isOpen() const { return m_aInPut
.is_open(); }
142 bool eof() const { return m_bEof
; }
144 void open(const OString
& rFileName
);
145 void open(const OString
& rFileName
, OString
& sPoHeader
);
147 void readEntry(PoEntry
& rPo
);
150 #endif // INCLUDED_L10NTOOLS_INC_PO_HXX
152 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */