tdf#133368: update extensions website URLs and use https
[LibreOffice.git] / l10ntools / inc / po.hxx
blobdb513cab1f8e5bf1d310470afed6ade96f0e0739
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 <string_view>
17 #include <rtl/string.hxx>
19 class PoOfstream;
20 class PoIfstream;
21 class GenPoEntry;
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
31 localization tools.
33 class PoEntry
35 private:
37 std::unique_ptr<GenPoEntry> m_pGenPo;
38 bool m_bIsInitialized;
40 public:
42 friend class PoOfstream;
43 friend class PoIfstream;
45 enum TYPE { TTEXT, TQUICKHELPTEXT, TTITLE };
46 enum Exception { NOSOURCFILE, NORESTYPE, NOGROUPID, NOSTRING, WRONGHELPTEXT };
48 PoEntry();
49 PoEntry( const OString& rSourceFile, std::string_view rResType, std::string_view rGroupId,
50 std::string_view rLocalId, const OString& rHelpText, const OString& rText,
51 const TYPE eType );
52 ~PoEntry();
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;
66 bool isFuzzy() 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).
80 class PoHeader
82 private:
84 std::unique_ptr<GenPoEntry> m_pGenPo;
85 bool m_bIsInitialized;
87 public:
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 );
94 ~PoHeader();
95 PoHeader(const PoHeader&) = delete;
96 PoHeader& operator=(const PoHeader&) = delete;
99 /// Interface to write po entry to files as output streams
100 class PoOfstream
102 private:
104 std::ofstream m_aOutPut;
105 bool m_bIsAfterHeader;
107 public:
109 enum OpenMode { TRUNC, APP };
111 PoOfstream();
112 PoOfstream(const OString& rFileName, OpenMode aMode );
113 ~PoOfstream();
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 );
119 void close();
120 void writeHeader(const PoHeader& rHeader);
121 void writeEntry(const PoEntry& rPo);
124 /// Interface to read po entry from files as input streams
125 class PoIfstream
127 private:
129 std::ifstream m_aInPut;
130 bool m_bEof;
132 public:
134 class Exception final : public std::exception { };
136 PoIfstream();
137 PoIfstream( const OString& rFileName );
138 ~PoIfstream();
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);
146 void close();
147 void readEntry(PoEntry& rPo);
150 #endif // INCLUDED_L10NTOOLS_INC_PO_HXX
152 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */