blob: a93d47954a149ab52c5c24058069af2c4fe4f7e6 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001#ifndef XLIFF_FILE_H
2#define XLIFF_FILE_H
3
4#include "Values.h"
5
6#include "Configuration.h"
7
8#include <set>
9
10using namespace std;
11
12extern const XMLNamespaceMap XLIFF_NAMESPACES;
13
14extern const char*const XLIFF_XMLNS;
15
16struct Stats
17{
18 string config;
19 size_t files;
20 size_t toBeTranslated;
21 size_t noComments;
22 size_t totalStrings;
23};
24
25struct TransUnit {
26 string id;
27 StringResource source;
28 StringResource target;
29 StringResource altSource;
30 StringResource altTarget;
31 string rejectComment;
32};
33
34class XLIFFFile
35{
36public:
37 static XLIFFFile* Parse(const string& filename);
38 static XLIFFFile* Create(const Configuration& sourceConfig, const Configuration& targetConfig,
39 const string& currentVersion);
40 ~XLIFFFile();
41
42 inline const Configuration& SourceConfig() const { return m_sourceConfig; }
43 inline const Configuration& TargetConfig() const { return m_targetConfig; }
44
45 inline const string& CurrentVersion() const { return m_currentVersion; }
46 inline const string& OldVersion() const { return m_oldVersion; }
47
48 set<string> Files() const;
49
50 void AddStringResource(const StringResource& res);
51 inline set<StringResource> const& GetStringResources() const { return m_strings; }
52 bool FindStringResource(const string& filename, int version, bool source);
53
54 void Filter(bool (*func)(const string&,const TransUnit&,void*), void* cookie);
55 void Map(void (*func)(const string&,TransUnit*,void*), void* cookie);
56
57 TransUnit* EditTransUnit(const string& file, const string& id);
58
59 // exports this file as a n XMLNode, you own this object
60 XMLNode* ToXMLNode() const;
61
62 // writes the ValuesFile out to a string in the canonical format (i.e. writes the contents of
63 // ToXMLNode()).
64 string ToString() const;
65
66 Stats GetStats(const string& config) const;
67
68private:
69 struct File {
70 int Compare(const File& that) const;
71
72 inline bool operator<(const File& that) const { return Compare(that) < 0; }
73 inline bool operator<=(const File& that) const { return Compare(that) <= 0; }
74 inline bool operator==(const File& that) const { return Compare(that) == 0; }
75 inline bool operator!=(const File& that) const { return Compare(that) != 0; }
76 inline bool operator>=(const File& that) const { return Compare(that) >= 0; }
77 inline bool operator>(const File& that) const { return Compare(that) > 0; }
78
79 string filename;
80 vector<TransUnit> transUnits;
81 };
82
83 XLIFFFile();
84 StringResource* find_string_res(TransUnit& g, const StringResource& str);
85
86 Configuration m_sourceConfig;
87 Configuration m_targetConfig;
88
89 string m_currentVersion;
90 string m_oldVersion;
91
92 set<StringResource> m_strings;
93 vector<File> m_files;
94};
95
96int convert_html_to_xliff(const XMLNode* original, const string& name, XMLNode* addTo, int* phID);
97
98#endif // XLIFF_FILE_H