* Added a B_TRANSLATE_WITH_CONTEXT() macro.

* Added a number of TODOs.
* Cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39280 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2010-11-02 21:36:35 +00:00
parent 0ac16c5b3e
commit 312f43920a

View File

@ -5,10 +5,12 @@
#ifndef _CATALOG_H_ #ifndef _CATALOG_H_
#define _CATALOG_H_ #define _CATALOG_H_
#include <LocaleRoster.h> #include <LocaleRoster.h>
#include <SupportDefs.h> #include <SupportDefs.h>
#include <String.h> #include <String.h>
class BCatalogAddOn; class BCatalogAddOn;
class BLocale; class BLocale;
class BMessage; class BMessage;
@ -16,29 +18,32 @@ struct entry_ref;
class BCatalog { class BCatalog {
public: public:
BCatalog(); BCatalog();
BCatalog(const char *signature, const char *language = NULL, BCatalog(const char* signature,
const char* language = NULL,
uint32 fingerprint = 0); uint32 fingerprint = 0);
virtual ~BCatalog(); virtual ~BCatalog();
const char *GetString(const char *string, const char *context = NULL, const char* GetString(const char* string,
const char* context = NULL,
const char* comment = NULL); const char* comment = NULL);
const char* GetString(uint32 id); const char* GetString(uint32 id);
const char* GetNoAutoCollectString(const char* string, const char* GetNoAutoCollectString(const char* string,
const char *context = NULL, const char *comment = NULL); const char* context = NULL,
const char* comment = NULL);
const char* GetNoAutoCollectString(uint32 id); const char* GetNoAutoCollectString(uint32 id);
status_t GetData(const char* name, BMessage* msg); status_t GetData(const char* name, BMessage* msg);
status_t GetData(uint32 id, BMessage* msg); status_t GetData(uint32 id, BMessage* msg);
status_t GetSignature(BString *sig); status_t GetSignature(BString* signature);
status_t GetLanguage(BString *lang); status_t GetLanguage(BString* language);
status_t GetFingerprint(uint32 *fp); status_t GetFingerprint(uint32* fingerprint);
status_t SetCatalog(const char* signature, uint32 fingerprint); status_t SetCatalog(const char* signature,
uint32 fingerprint);
status_t InitCheck() const; status_t InitCheck() const;
int32 CountItems() const; int32 CountItems() const;
@ -65,6 +70,8 @@ class BCatalog {
// you don't want these (in which case you need to collect the catalog keys // you don't want these (in which case you need to collect the catalog keys
// manually, as collectcatkeys won't do it for you): // manually, as collectcatkeys won't do it for you):
// TODO: maybe rename this to B_TRANSLATE_DEFAULT_CONTEXT, so that
// B_TRANSLATE_WITH_CONTEXT() can just be called B_TRANSLATE_CONTEXT()
#undef B_TRANSLATE_CONTEXT #undef B_TRANSLATE_CONTEXT
// In a single application, several strings (e.g. 'Ok') will be used // In a single application, several strings (e.g. 'Ok') will be used
// more than once, in different contexts. // more than once, in different contexts.
@ -85,16 +92,21 @@ class BCatalog {
// Translation macros which may be used to shorten translation requests: // Translation macros which may be used to shorten translation requests:
#undef B_TRANSLATE #undef B_TRANSLATE
#define B_TRANSLATE(str) \ #define B_TRANSLATE(string) \
be_locale_roster->GetCatalog()->GetString((str), B_TRANSLATE_CONTEXT) be_locale_roster->GetCatalog()->GetString((string), B_TRANSLATE_CONTEXT)
#undef B_TRANSLATE_WITH_CONTEXT
#define B_TRANSLATE_WITH_CONTEXT(string, context) \
be_locale_roster->GetCatalog()->GetString((string), (context))
#undef B_TRANSLATE_COMMENT #undef B_TRANSLATE_COMMENT
#define B_TRANSLATE_COMMENT(str, cmt) \ #define B_TRANSLATE_COMMENT(string, comment) \
be_locale_roster->GetCatalog()->GetString((str), B_TRANSLATE_CONTEXT, (cmt)) be_locale_roster->GetCatalog()->GetString((string), B_TRANSLATE_CONTEXT, \
(comment))
#undef B_TRANSLATE_ALL #undef B_TRANSLATE_ALL
#define B_TRANSLATE_ALL(str, ctx, cmt) \ #define B_TRANSLATE_ALL(string, context, comment) \
be_locale_roster->GetCatalog()->GetString((str), (ctx), (cmt)) be_locale_roster->GetCatalog()->GetString((string), (context), (comment))
#undef B_TRANSLATE_ID #undef B_TRANSLATE_ID
#define B_TRANSLATE_ID(id) \ #define B_TRANSLATE_ID(id) \
@ -160,22 +172,29 @@ class BCatalog {
#endif /* B_AVOID_TRANSLATION_MACROS */ #endif /* B_AVOID_TRANSLATION_MACROS */
#else /* B_COLLECTING_CATKEYS */ #else /* B_COLLECTING_CATKEYS */
// TODO: why define them here? Since we obviously control the preprocessor, we
// could simply always include a certain file that defines them; this doesn't
// really belong into a public header.
// Translation macros used when executing collectcatkeys // Translation macros used when executing collectcatkeys
#undef B_TRANSLATE_CONTEXT #undef B_TRANSLATE_CONTEXT
#undef B_TRANSLATE #undef B_TRANSLATE
#define B_TRANSLATE(str) \ #define B_TRANSLATE(string) \
B_CATKEY((str), B_TRANSLATE_CONTEXT) B_CATKEY((string), B_TRANSLATE_CONTEXT)
#undef B_TRANSLATE_WITH_CONTEXT
#define B_TRANSLATE_WITH_CONTEXT(string, context) \
B_CATKEY((string), (context))
#undef B_TRANSLATE_COMMENT #undef B_TRANSLATE_COMMENT
#define B_TRANSLATE_COMMENT(str, cmt) \ #define B_TRANSLATE_COMMENT(string, comment) \
B_CATKEY((str), B_TRANSLATE_CONTEXT, (cmt)) B_CATKEY((string), B_TRANSLATE_CONTEXT, (comment))
#undef B_TRANSLATE_ALL #undef B_TRANSLATE_ALL
#define B_TRANSLATE_ALL(str, ctx, cmt) \ #define B_TRANSLATE_ALL(string, context, comment) \
B_CATKEY((str), (ctx), (cmt)) B_CATKEY((string), (context), (comment))
#undef B_TRANSLATE_ID #undef B_TRANSLATE_ID
#define B_TRANSLATE_ID(id) \ #define B_TRANSLATE_ID(id) \
@ -218,10 +237,12 @@ class BCatalog {
/************************************************************************/ /************************************************************************/
// For BCatalog add-on implementations: // For BCatalog add-on implementations:
// TODO: should go into another header
class BCatalogAddOn { class BCatalogAddOn {
public: public:
BCatalogAddOn(const char *signature, const char *language, BCatalogAddOn(const char* signature,
const char* language,
uint32 fingerprint); uint32 fingerprint);
virtual ~BCatalogAddOn(); virtual ~BCatalogAddOn();
@ -264,8 +285,8 @@ class BCatalogAddOn {
// magic marker functions which are used to mark a string/id // magic marker functions which are used to mark a string/id
// which will be translated elsewhere in the code (where it can // which will be translated elsewhere in the code (where it can
// not be found since it is references by a variable): // not be found since it is references by a variable):
static const char *MarkForTranslation(const char *str, const char *ctx, static const char* MarkForTranslation(const char* string,
const char *cmt); const char* context, const char* comment);
static int32 MarkForTranslation(int32 id); static int32 MarkForTranslation(int32 id);
void SetNext(BCatalogAddOn* next); void SetNext(BCatalogAddOn* next);
@ -273,14 +294,15 @@ class BCatalogAddOn {
protected: protected:
virtual void UpdateFingerprint(); virtual void UpdateFingerprint();
protected:
friend class BCatalog;
friend status_t get_add_on_catalog(BCatalog*, const char*);
status_t fInitCheck; status_t fInitCheck;
BString fSignature; BString fSignature;
BString fLanguageName; BString fLanguageName;
uint32 fFingerprint; uint32 fFingerprint;
BCatalogAddOn* fNext; BCatalogAddOn* fNext;
friend class BCatalog;
friend status_t get_add_on_catalog(BCatalog*, const char *);
}; };
// every catalog-add-on should export these symbols... // every catalog-add-on should export these symbols...
@ -399,17 +421,16 @@ BCatalogAddOn::MarkForTranslation(int32 id)
} }
// TODO: does not belong here, either
namespace BPrivate { namespace BPrivate {
/*
* EditableCatalog
*/
class EditableCatalog : public BCatalog {
class EditableCatalog : public BCatalog {
public: public:
EditableCatalog(const char *type, const char *signature, EditableCatalog(const char* type,
const char* signature,
const char* language); const char* language);
~EditableCatalog(); virtual ~EditableCatalog();
status_t SetString(const char* string, status_t SetString(const char* string,
const char* translated, const char* translated,
@ -432,12 +453,14 @@ class EditableCatalog : public BCatalog {
private: private:
EditableCatalog(); EditableCatalog();
EditableCatalog(const EditableCatalog&); EditableCatalog(const EditableCatalog& other);
const EditableCatalog& operator= (const EditableCatalog&); const EditableCatalog& operator=(const EditableCatalog& other);
// hide assignment, default- and copy-constructor // hide assignment, default-, and
// copy-constructor
}; };
} // namespace BPrivate } // namespace BPrivate
#endif /* _CATALOG_H_ */ #endif /* _CATALOG_H_ */