xref: /haiku/src/tools/locale/Catalog.cpp (revision e0ef64750f3169cd634bb2f7a001e22488b05231)
1 /*
2 ** Distributed under the terms of the OpenBeOS License.
3 ** Copyright 2003-2004. All rights reserved.
4 **
5 ** Authors:	Axel Dörfler, axeld@pinc-software.de
6 **			Oliver Tappe, zooey@hirschkaefer.de
7 */
8 
9 #include <syslog.h>
10 
11 #include <Application.h>
12 #include <Catalog.h>
13 #include <Locale.h>
14 #include <LocaleRoster.h>
15 #include <Node.h>
16 #include <Roster.h>
17 
18 
19 BCatalog* be_catalog = NULL;
20 	// catalog used by translation macros
21 BCatalog* be_app_catalog = NULL;
22 	// app-catalog (useful for accessing app's catalog from inside an add-on,
23 	// since in an add-on, be_catalog will hold the add-on's catalog.
24 
25 
26 //#pragma mark - BCatalog
27 BCatalog::BCatalog()
28 	:
29 	fCatalog(NULL)
30 {
31 }
32 
33 
34 BCatalog::BCatalog(const char *signature, const char *language,
35 	uint32 fingerprint)
36 {
37 	//fCatalog = be_locale_roster->LoadCatalog(signature, language, fingerprint);
38 }
39 
40 
41 BCatalog::~BCatalog()
42 {
43 	if (be_catalog == this)
44 		be_app_catalog = be_catalog = NULL;
45 	//be_locale_roster->UnloadCatalog(fCatalog);
46 }
47 
48 
49 const char *
50 BCatalog::GetString(const char *string, const char *context, const char *comment)
51 {
52 	const char *translated;
53 	for (BCatalogAddOn* cat = fCatalog; cat != NULL; cat = cat->fNext) {
54 		translated = cat->GetString(string, context, comment);
55 		if (translated)
56 			return translated;
57 	}
58 	return string;
59 }
60 
61 
62 const char *
63 BCatalog::GetString(uint32 id)
64 {
65 	const char *translated;
66 	for (BCatalogAddOn* cat = fCatalog; cat != NULL; cat = cat->fNext) {
67 		translated = cat->GetString(id);
68 		if (translated)
69 			return translated;
70 	}
71 	return "";
72 }
73 
74 
75 status_t
76 BCatalog::GetData(const char *name, BMessage *msg)
77 {
78 	if (!fCatalog)
79 		return B_NO_INIT;
80 	status_t res;
81 	for (BCatalogAddOn* cat = fCatalog; cat != NULL; cat = cat->fNext) {
82 		res = cat->GetData(name, msg);
83 		if (res != B_NAME_NOT_FOUND && res != EOPNOTSUPP)
84 			return res;
85 				// return B_OK if found, or specific error-code
86 	}
87 	return B_NAME_NOT_FOUND;
88 }
89 
90 
91 status_t
92 BCatalog::GetData(uint32 id, BMessage *msg)
93 {
94 	if (!fCatalog)
95 		return B_NO_INIT;
96 	status_t res;
97 	for (BCatalogAddOn* cat = fCatalog; cat != NULL; cat = cat->fNext) {
98 		res = cat->GetData(id, msg);
99 		if (res != B_NAME_NOT_FOUND && res != EOPNOTSUPP)
100 			return res;
101 				// return B_OK if found, or specific error-code
102 	}
103 	return B_NAME_NOT_FOUND;
104 }
105 
106 
107 //#pragma mark - BCatalogAddOn
108 BCatalogAddOn::BCatalogAddOn(const char *signature, const char *language,
109 	uint32 fingerprint)
110 	:
111 	fInitCheck(B_NO_INIT),
112 	fSignature(signature),
113 	fLanguageName(language),
114 	fFingerprint(fingerprint),
115 	fNext(NULL)
116 {
117 	fLanguageName.ToLower();
118 		// canonicalize language-name to lowercase
119 }
120 
121 
122 BCatalogAddOn::~BCatalogAddOn()
123 {
124 }
125 
126 
127 void
128 BCatalogAddOn::UpdateFingerprint()
129 {
130 	fFingerprint = 0;
131 		// base implementation always yields the same fingerprint,
132 		// which means that no version-mismatch detection is possible.
133 }
134 
135 
136 status_t
137 BCatalogAddOn::InitCheck() const
138 {
139 	return fInitCheck;
140 }
141 
142 
143 bool
144 BCatalogAddOn::CanHaveData() const
145 {
146 	return false;
147 }
148 
149 
150 status_t
151 BCatalogAddOn::GetData(const char *name, BMessage *msg)
152 {
153 	return EOPNOTSUPP;
154 }
155 
156 
157 status_t
158 BCatalogAddOn::GetData(uint32 id, BMessage *msg)
159 {
160 	return EOPNOTSUPP;
161 }
162 
163 
164 status_t
165 BCatalogAddOn::SetString(const char *string, const char *translated,
166 	const char *context, const char *comment)
167 {
168 	return EOPNOTSUPP;
169 }
170 
171 
172 status_t
173 BCatalogAddOn::SetString(int32 id, const char *translated)
174 {
175 	return EOPNOTSUPP;
176 }
177 
178 
179 bool
180 BCatalogAddOn::CanWriteData() const
181 {
182 	return false;
183 }
184 
185 
186 status_t
187 BCatalogAddOn::SetData(const char *name, BMessage *msg)
188 {
189 	return EOPNOTSUPP;
190 }
191 
192 
193 status_t
194 BCatalogAddOn::SetData(uint32 id, BMessage *msg)
195 {
196 	return EOPNOTSUPP;
197 }
198 
199 
200 status_t
201 BCatalogAddOn::ReadFromFile(const char *path)
202 {
203 	return EOPNOTSUPP;
204 }
205 
206 
207 status_t
208 BCatalogAddOn::ReadFromAttribute(entry_ref *appOrAddOnRef)
209 {
210 	return EOPNOTSUPP;
211 }
212 
213 
214 status_t
215 BCatalogAddOn::ReadFromResource(entry_ref *appOrAddOnRef)
216 {
217 	return EOPNOTSUPP;
218 }
219 
220 
221 status_t
222 BCatalogAddOn::WriteToFile(const char *path)
223 {
224 	return EOPNOTSUPP;
225 }
226 
227 
228 status_t
229 BCatalogAddOn::WriteToAttribute(entry_ref *appOrAddOnRef)
230 {
231 	return EOPNOTSUPP;
232 }
233 
234 
235 status_t
236 BCatalogAddOn::WriteToResource(entry_ref *appOrAddOnRef)
237 {
238 	return EOPNOTSUPP;
239 }
240 
241 
242 void BCatalogAddOn::MakeEmpty()
243 {
244 }
245 
246 
247 int32
248 BCatalogAddOn::CountItems() const
249 {
250 	return 0;
251 }
252