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 <rtl/string.hxx>
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
35 std::unique_ptr
<GenPoEntry
> m_pGenPo
;
36 bool m_bIsInitialized
;
40 friend class PoOfstream
;
41 friend class PoIfstream
;
43 enum TYPE
{ TTEXT
, TQUICKHELPTEXT
, TTITLE
};
44 enum Exception
{ NOSOURCFILE
, NORESTYPE
, NOGROUPID
, NOSTRING
, WRONGHELPTEXT
};
47 PoEntry( const OString
& rSourceFile
, const OString
& rResType
, const OString
& rGroupId
,
48 const OString
& rLocalId
, const OString
& rHelpText
, const OString
& rText
,
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;
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).
82 std::unique_ptr
<GenPoEntry
> m_pGenPo
;
83 bool m_bIsInitialized
;
87 friend class PoOfstream
;
88 friend class PoIfstream
;
90 PoHeader( const OString
& rExtSrc
); ///< Template Constructor
91 PoHeader( const OString
& rExtSrc
, const OString
& rPoHeaderMsgStr
);
93 PoHeader(const PoHeader
&) = delete;
94 PoHeader
& operator=(const PoHeader
&) = delete;
97 /// Interface to write po entry to files as output streams
102 std::ofstream m_aOutPut
;
103 bool m_bIsAfterHeader
;
107 enum OpenMode
{ TRUNC
, APP
};
110 PoOfstream(const OString
& rFileName
, OpenMode aMode
);
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
);
118 void writeHeader(const PoHeader
& rHeader
);
119 void writeEntry(const PoEntry
& rPo
);
122 /// Interface to read po entry from files as input streams
127 std::ifstream m_aInPut
;
132 class Exception
: public std::exception
{ };
135 PoIfstream( const OString
& rFileName
);
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
);
145 void readEntry(PoEntry
& rPo
);
148 #endif // INCLUDED_L10NTOOLS_INC_PO_HXX
150 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */