xref: /haiku/src/tools/locale/Catalog.cpp (revision 1a76488fc88584bf66b9751d7fb9b6527ac20d87)
1 /*
2 ** Distributed under the terms of the MIT License.
3 ** Copyright 2003-2004,2012. All rights reserved.
4 **
5 ** Authors:	Axel Dörfler, axeld@pinc-software.de
6 **			Oliver Tappe, zooey@hirschkaefer.de
7 */
8 
9 #include <Catalog.h>
10 #include <CatalogData.h>
11 
12 
13 // Provides an implementation of BCatalog for the build host, in effect only
14 // supporting setting and getting of catalog entries.
15 
16 
17 BCatalog::BCatalog()
18 	:
19 	fCatalogData(NULL)
20 {
21 }
22 
23 
24 BCatalog::BCatalog(const entry_ref& catalogOwner, const char *language,
25 	uint32 fingerprint)
26 	:
27 	fCatalogData(NULL)
28 {
29 }
30 
31 
32 BCatalog::~BCatalog()
33 {
34 }
35 
36 
37 const char *
38 BCatalog::GetString(const char *string, const char *context, const char *comment)
39 {
40 	if (fCatalogData == 0)
41 		return string;
42 
43 	const char *translated;
44 	for (BCatalogData* cat = fCatalogData; cat != NULL; cat = cat->fNext) {
45 		translated = cat->GetString(string, context, comment);
46 		if (translated)
47 			return translated;
48 	}
49 
50 	return string;
51 }
52 
53 
54 const char *
55 BCatalog::GetString(uint32 id)
56 {
57 	if (fCatalogData == 0)
58 		return "";
59 
60 	const char *translated;
61 	for (BCatalogData* cat = fCatalogData; cat != NULL; cat = cat->fNext) {
62 		translated = cat->GetString(id);
63 		if (translated)
64 			return translated;
65 	}
66 
67 	return "";
68 }
69 
70 
71 status_t
72 BCatalog::GetData(const char *name, BMessage *msg)
73 {
74 	if (fCatalogData == 0)
75 		return B_NO_INIT;
76 
77 	status_t res;
78 	for (BCatalogData* cat = fCatalogData; cat != NULL; cat = cat->fNext) {
79 		res = cat->GetData(name, msg);
80 		if (res != B_NAME_NOT_FOUND && res != EOPNOTSUPP)
81 			return res;
82 				// return B_OK if found, or specific error-code
83 	}
84 
85 	return B_NAME_NOT_FOUND;
86 }
87 
88 
89 status_t
90 BCatalog::GetData(uint32 id, BMessage *msg)
91 {
92 	if (fCatalogData == 0)
93 		return B_NO_INIT;
94 
95 	status_t res;
96 	for (BCatalogData* cat = fCatalogData; cat != NULL; cat = cat->fNext) {
97 		res = cat->GetData(id, msg);
98 		if (res != B_NAME_NOT_FOUND && res != EOPNOTSUPP)
99 			return res;
100 				// return B_OK if found, or specific error-code
101 	}
102 
103 	return B_NAME_NOT_FOUND;
104 }
105