bump product version to 6.4.0.3
[LibreOffice.git] / l10ntools / inc / po.hxx
blobbbbf289cbec683b38481b8501c482fef1ebfcf26
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
8 */
10 #ifndef INCLUDED_L10NTOOLS_INC_PO_HXX
11 #define INCLUDED_L10NTOOLS_INC_PO_HXX
13 #include <fstream>
14 #include <memory>
15 #include <rtl/string.hxx>
17 class PoOfstream;
18 class PoIfstream;
19 class GenPoEntry;
22 /** Interface to use po entries in localization
24 PoEntry based on GenPoEntry class which stores attributes
25 of general po entry(see po.cxx). It makes easy to get/set
26 all information needed to localize one english(US) string.
27 It contains some basic checkings and some string
28 transformations between po string and string used by
29 localization tools.
31 class PoEntry
33 private:
35 std::unique_ptr<GenPoEntry> m_pGenPo;
36 bool m_bIsInitialized;
38 public:
40 friend class PoOfstream;
41 friend class PoIfstream;
43 enum TYPE { TTEXT, TQUICKHELPTEXT, TTITLE };
44 enum Exception { NOSOURCFILE, NORESTYPE, NOGROUPID, NOSTRING, WRONGHELPTEXT };
46 PoEntry();
47 PoEntry( const OString& rSourceFile, const OString& rResType, const OString& rGroupId,
48 const OString& rLocalId, const OString& rHelpText, const OString& rText,
49 const TYPE eType );
50 ~PoEntry();
52 PoEntry( const PoEntry& rPo );
53 PoEntry& operator=( const PoEntry& rPo );
54 PoEntry& operator=( PoEntry&& rPo ) noexcept;
56 OString const & getSourceFile() const; ///< Get name of file from which entry is extracted
57 OString getGroupId() const;
58 OString getLocalId() const;
59 OString getResourceType() const; ///< Get the type of component from which entry is extracted
60 TYPE getType() const; ///< Get the type of entry
61 OString const & getMsgCtxt() const;
62 OString const & getMsgId() const;
63 OString const & getMsgStr() const;
64 bool isFuzzy() const;
66 /// Check whether po-s belong to the same localization component
67 static bool IsInSameComp(const PoEntry& rPo1,const PoEntry& rPo2);
68 static OString genKeyId(const OString& rGenerator);
72 /** Interface to work with header of po/pot files
74 This class stores information which is in header of
75 a po file. It's main function to generate header to
76 template po files(pot).
78 class PoHeader
80 private:
82 std::unique_ptr<GenPoEntry> m_pGenPo;
83 bool m_bIsInitialized;
85 public:
87 friend class PoOfstream;
88 friend class PoIfstream;
90 PoHeader( const OString& rExtSrc ); ///< Template Constructor
91 PoHeader( const OString& rExtSrc, const OString& rPoHeaderMsgStr );
92 ~PoHeader();
93 PoHeader(const PoHeader&) = delete;
94 PoHeader& operator=(const PoHeader&) = delete;
97 /// Interface to write po entry to files as output streams
98 class PoOfstream
100 private:
102 std::ofstream m_aOutPut;
103 bool m_bIsAfterHeader;
105 public:
107 enum OpenMode { TRUNC, APP };
109 PoOfstream();
110 PoOfstream(const OString& rFileName, OpenMode aMode );
111 ~PoOfstream();
112 PoOfstream(const PoOfstream&) = delete;
113 PoOfstream& operator=(const PoOfstream&) = delete;
114 bool isOpen() const { return m_aOutPut.is_open(); }
116 void open(const OString& rFileName, OpenMode aMode = TRUNC );
117 void close();
118 void writeHeader(const PoHeader& rHeader);
119 void writeEntry(const PoEntry& rPo);
122 /// Interface to read po entry from files as input streams
123 class PoIfstream
125 private:
127 std::ifstream m_aInPut;
128 bool m_bEof;
130 public:
132 class Exception : public std::exception { };
134 PoIfstream();
135 PoIfstream( const OString& rFileName );
136 ~PoIfstream();
137 PoIfstream(const PoIfstream&) = delete;
138 PoIfstream& operator=(const PoIfstream&) = delete;
139 bool isOpen() const { return m_aInPut.is_open(); }
140 bool eof() const { return m_bEof; }
142 void open(const OString& rFileName);
143 void open(const OString& rFileName, OString& sPoHeader);
144 void close();
145 void readEntry(PoEntry& rPo);
148 #endif // INCLUDED_L10NTOOLS_INC_PO_HXX
150 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */