Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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 : */
9 :
10 : #ifndef _PO_INCLUDED
11 : #define _PO_INCLUDED
12 :
13 : #include <fstream>
14 : #include <rtl/string.hxx>
15 : #include <boost/noncopyable.hpp>
16 :
17 : class PoOfstream;
18 : class PoIfstream;
19 : class GenPoEntry;
20 :
21 :
22 : /** Interface to use po entries in localization
23 :
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.
30 : */
31 : class PoEntry
32 : {
33 : private:
34 :
35 : GenPoEntry* m_pGenPo;
36 : bool m_bIsInitialized;
37 :
38 : public:
39 :
40 : friend class PoOfstream;
41 : friend class PoIfstream;
42 :
43 : enum TYPE { TTEXT, TQUICKHELPTEXT, TTITLE };
44 : enum Exception { NOSOURCFILE, NORESTYPE, NOGROUPID, NOSTRING, WRONGHELPTEXT };
45 :
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 = TTEXT );
50 : ~PoEntry();
51 :
52 : PoEntry( const PoEntry& rPo );
53 : PoEntry& operator=( const PoEntry& rPo );
54 :
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;
62 : bool isFuzzy() const;
63 :
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);
67 :
68 : };
69 :
70 : /** Interface to work with header of po/pot files
71 :
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).
75 : */
76 : class PoHeader: private boost::noncopyable
77 : {
78 : private:
79 :
80 : GenPoEntry* m_pGenPo;
81 : bool m_bIsInitialized;
82 :
83 : public:
84 :
85 : friend class PoOfstream;
86 : friend class PoIfstream;
87 :
88 : PoHeader( const OString& rExtSrc ); ///< Template Constructor
89 : ~PoHeader();
90 : };
91 :
92 : /// Interface to write po entry to files as output streams
93 : class PoOfstream: private boost::noncopyable
94 : {
95 : private:
96 :
97 : std::ofstream m_aOutPut;
98 : bool m_bIsAfterHeader;
99 :
100 : public:
101 :
102 : enum OpenMode { TRUNC, APP };
103 :
104 : PoOfstream();
105 : PoOfstream(const OString& rFileName, OpenMode aMode = TRUNC );
106 : ~PoOfstream();
107 0 : bool isOpen() const { return m_aOutPut.is_open(); }
108 :
109 : void open(const OString& rFileName, OpenMode aMode = TRUNC );
110 : void close();
111 : void writeHeader(const PoHeader& rHeader);
112 : void writeEntry(const PoEntry& rPo);
113 : };
114 :
115 : /// Interface to read po entry from files as input streams
116 : class PoIfstream: private boost::noncopyable
117 : {
118 : private:
119 :
120 : std::ifstream m_aInPut;
121 : bool m_bEof;
122 :
123 : public:
124 :
125 : enum Exception { INVALIDENTRY };
126 :
127 : PoIfstream();
128 : PoIfstream( const OString& rFileName );
129 : ~PoIfstream();
130 0 : bool isOpen() const { return m_aInPut.is_open(); }
131 0 : bool eof() const { return m_bEof; }
132 :
133 : void open(const OString& rFileName);
134 : void close();
135 : void readEntry(PoEntry& rPo);
136 : };
137 :
138 : #endif // _PO_INCLUDED
139 :
140 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|