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
14 #include <rtl/string.hxx>
15 #include <boost/noncopyable.hpp>
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
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
,
49 const TYPE eType
= TTEXT
);
52 PoEntry( const PoEntry
& rPo
);
53 PoEntry
& operator=( const PoEntry
& rPo
);
55 OString
getSourceFile() const; ///< Get name of file from which entry is extracted
56 OString
getGroupId() const;
57 OString
getLocalId() const;
58 OString
getResourceType() const; ///< Get the type of component from which entry is extracted
59 TYPE
getType() const; ///< Get the type of entry
60 OString
getMsgId() const;
61 OString
getMsgStr() const;
64 /// Check whether po-s belong to the same localization component
65 static bool IsInSameComp(const PoEntry
& rPo1
,const PoEntry
& rPo2
);
66 static OString
genKeyId(const OString
& rGenerator
);
70 /** Interface to work with header of po/pot files
72 This class stores information which is in header of
73 a po file. It's main function to generate header to
74 template po files(pot).
76 class PoHeader
: private boost::noncopyable
81 bool m_bIsInitialized
;
85 friend class PoOfstream
;
86 friend class PoIfstream
;
88 PoHeader( const OString
& rExtSrc
); ///< Template Constructor
92 /// Interface to write po entry to files as output streams
93 class PoOfstream
: private boost::noncopyable
97 std::ofstream m_aOutPut
;
98 bool m_bIsAfterHeader
;
102 enum OpenMode
{ TRUNC
, APP
};
105 PoOfstream(const OString
& rFileName
, OpenMode aMode
= TRUNC
);
107 bool isOpen() const { return m_aOutPut
.is_open(); }
109 void open(const OString
& rFileName
, OpenMode aMode
= TRUNC
);
111 void writeHeader(const PoHeader
& rHeader
);
112 void writeEntry(const PoEntry
& rPo
);
115 /// Interface to read po entry from files as input streams
116 class PoIfstream
: private boost::noncopyable
120 std::ifstream m_aInPut
;
125 enum Exception
{ INVALIDENTRY
};
128 PoIfstream( const OString
& rFileName
);
130 bool isOpen() const { return m_aInPut
.is_open(); }
131 bool eof() const { return m_bEof
; }
133 void open(const OString
& rFileName
);
135 void readEntry(PoEntry
& rPo
);
138 #endif // INCLUDED_L10NTOOLS_INC_PO_HXX
140 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */