Cleanup BCatalogAddOn.

* rename BCatalogAddOn to BCatalogData, since it doesn't represent an
  add-on, but rather the catalog data provided by an add-on
* move BCatalogData out of Catalog.{h,cpp} into its own header and
  implementation file
* drop BCatalogData::MarkForTranslation() methods, they're not needed
* drop BCatalog::GetNoAutoCollectString() methods, they're not being
  used anywhere
* cleanup the B_TRANSLATE_... macros somewhat
* add versions of the B_TRANSLATE_MARK_... macros that are meant to be
  used in void context (when the string isn't being used by the program,
  just meant to be picked up by collectcatkeys).
* adjust several apps to use B_TRANSLATE_MARK_..._VOID where needed
* adjust users of BCatalogAddOn accordingly
This commit is contained in:
Oliver Tappe
2012-04-16 00:04:41 +02:00
parent 5ac65b7f11
commit 541ff51a6e
36 changed files with 833 additions and 810 deletions
+71 -178
View File
@@ -12,7 +12,7 @@
#include <String.h>
class BCatalogAddOn;
class BCatalogData;
class BLocale;
class BMessage;
struct entry_ref;
@@ -31,11 +31,6 @@ public:
const char* comment = NULL);
const char* GetString(uint32 id);
const char* GetNoAutoCollectString(const char* string,
const char* context = NULL,
const char* comment = NULL);
const char* GetNoAutoCollectString(uint32 id);
status_t GetData(const char* name, BMessage* msg);
status_t GetData(uint32 id, BMessage* msg);
@@ -55,7 +50,7 @@ protected:
const BCatalog& operator= (const BCatalog&);
// hide assignment and copy-constructor
BCatalogAddOn* fCatalog;
BCatalogData* fCatalogData;
mutable BLocker fLock;
private:
@@ -122,12 +117,13 @@ private:
#undef B_TRANSLATE_SYSTEM_NAME
#define B_TRANSLATE_SYSTEM_NAME(string) \
BLocaleRoster::Default()->IsFilesystemTranslationPreferred() \
? BLocaleRoster::Default()->GetCatalog()->GetString((string), \
B_TRANSLATE_SYSTEM_NAME_CONTEXT) : (string)
? BLocaleRoster::Default()->GetCatalog()->GetString((string), \
B_TRANSLATE_SYSTEM_NAME_CONTEXT) \
: (string)
// Translation markers which can be used to mark static strings/IDs which
// are used as key for translation requests (at other places in the code):
/* example:
// are used as key for translation requests (at other places in the code).
/* Example:
#define B_TRANSLATE_CONTEXT "MyDecentApp-Menu"
static const char* choices[] = {
@@ -137,7 +133,8 @@ private:
B_TRANSLATE_MARK("down")
};
void MyClass::AddChoices(BMenu* menu) {
void MyClass::AddChoices(BMenu* menu)
{
for (char** ch = choices; *ch != '\0'; ++ch) {
menu->AddItem(
new BMenuItem(
@@ -149,46 +146,57 @@ private:
}
*/
#undef B_TRANSLATE_MARK
#define B_TRANSLATE_MARK(str) \
BCatalogAddOn::MarkForTranslation((str), B_TRANSLATE_CONTEXT, "")
#define B_TRANSLATE_MARK(string) (string)
#undef B_TRANSLATE_MARK_COMMENT
#define B_TRANSLATE_MARK_COMMENT(str, cmt) \
BCatalogAddOn::MarkForTranslation((str), B_TRANSLATE_CONTEXT, (cmt))
#define B_TRANSLATE_MARK_COMMENT(string, comment) (string)
#undef B_TRANSLATE_MARK_ALL
#define B_TRANSLATE_MARK_ALL(str, ctx, cmt) \
BCatalogAddOn::MarkForTranslation((str), (ctx), (cmt))
#define B_TRANSLATE_MARK_ALL(string, context, comment) (string)
#undef B_TRANSLATE_MARK_ID
#define B_TRANSLATE_MARK_ID(id) \
BCatalogAddOn::MarkForTranslation((id))
#define B_TRANSLATE_MARK_ID(id) (id)
#undef B_TRANSLATE_MARK_SYSTEM_NAME
#define B_TRANSLATE_MARK_SYSTEM_NAME(str) \
BCatalogAddOn::MarkForTranslation((str), B_TRANSLATE_SYSTEM_NAME_CONTEXT, "")
#define B_TRANSLATE_MARK_SYSTEM_NAME(string) (string)
// the same for void contexts:
#undef B_TRANSLATE_MARK_VOID
#define B_TRANSLATE_MARK_VOID(string)
#undef B_TRANSLATE_MARK_COMMENT_VOID
#define B_TRANSLATE_MARK_COMMENT_VOID(string, comment)
#undef B_TRANSLATE_MARK_ALL_VOID
#define B_TRANSLATE_MARK_ALL_VOID(string, context, comment)
#undef B_TRANSLATE_MARK_ID_VOID
#define B_TRANSLATE_MARK_ID_VOID(id)
#undef B_TRANSLATE_MARK_SYSTEM_NAME_VOID
#define B_TRANSLATE_MARK_SYSTEM_NAME_VOID(string)
// Translation macros which do not let collectcatkeys try to collect the key
// (useful in combination with the marking macros above):
#undef B_TRANSLATE_NOCOLLECT
#define B_TRANSLATE_NOCOLLECT(str) \
B_TRANSLATE(str)
#define B_TRANSLATE_NOCOLLECT(string) \
B_TRANSLATE(string)
#undef B_TRANSLATE_NOCOLLECT_COMMENT
#define B_TRANSLATE_NOCOLLECT_COMMENT(str, cmt) \
B_TRANSLATE_COMMENT(str, cmt)
#define B_TRANSLATE_NOCOLLECT_COMMENT(string, comment) \
B_TRANSLATE_COMMENT(string, comment)
#undef B_TRANSLATE_NOCOLLECT_ALL
#define B_TRANSLATE_NOCOLLECT_ALL(str, ctx, cmt) \
B_TRANSLATE_ALL(str, ctx, cmt)
#define B_TRANSLATE_NOCOLLECT_ALL(string, context, comment) \
B_TRANSLATE_ALL(string, context, comment)
#undef B_TRANSLATE_NOCOLLECT_ID
#define B_TRANSLATE_NOCOLLECT_ID(id) \
B_TRANSLATE_ID(id)
#undef B_TRANSLATE_NOCOLLECT_SYSTEM_NAME
#define B_TRANSLATE_NOCOLLECT_SYSTEM_NAME(str) \
B_TRANSLATE_SYSTEM_NAME(str)
#define B_TRANSLATE_NOCOLLECT_SYSTEM_NAME(string) \
B_TRANSLATE_SYSTEM_NAME(string)
#endif /* B_AVOID_TRANSLATION_MACROS */
@@ -226,176 +234,61 @@ private:
B_CATKEY((string), B_TRANSLATE_SYSTEM_NAME_CONTEXT)
#undef B_TRANSLATE_MARK
#define B_TRANSLATE_MARK(str) \
B_CATKEY((str), B_TRANSLATE_CONTEXT)
#define B_TRANSLATE_MARK(string) \
B_CATKEY((string), B_TRANSLATE_CONTEXT)
#undef B_TRANSLATE_MARK_COMMENT
#define B_TRANSLATE_MARK_COMMENT(str, cmt) \
B_CATKEY((str), B_TRANSLATE_CONTEXT, (cmt))
#define B_TRANSLATE_MARK_COMMENT(string, comment) \
B_CATKEY((string), B_TRANSLATE_CONTEXT, (comment))
#undef B_TRANSLATE_MARK_ALL
#define B_TRANSLATE_MARK_ALL(str, ctx, cmt) \
B_CATKEY((str), (ctx), (cmt))
#define B_TRANSLATE_MARK_ALL(string, context, comment) \
B_CATKEY((string), (context), (comment))
#undef B_TRANSLATE_MARK_ID
#define B_TRANSLATE_MARK_ID(id) \
B_CATKEY((id))
#undef B_TRANSLATE_MARK_SYSTEM_NAME
#define B_TRANSLATE_MARK_SYSTEM_NAME(str) \
B_CATKEY((str), B_TRANSLATE_SYSTEM_NAME_CONTEXT, "")
#define B_TRANSLATE_MARK_SYSTEM_NAME(string) \
B_CATKEY((string), B_TRANSLATE_SYSTEM_NAME_CONTEXT, "")
#undef B_TRANSLATE_MARK_VOID
#define B_TRANSLATE_MARK_VOID(string) \
B_CATKEY((string), B_TRANSLATE_CONTEXT)
#undef B_TRANSLATE_MARK_COMMENT_VOID
#define B_TRANSLATE_MARK_COMMENT_VOID(string, comment) \
B_CATKEY((string), B_TRANSLATE_CONTEXT, (comment))
#undef B_TRANSLATE_MARK_ALL_VOID
#define B_TRANSLATE_MARK_ALL_VOID(string, context, comment) \
B_CATKEY((string), (context), (comment))
#undef B_TRANSLATE_MARK_ID_VOID
#define B_TRANSLATE_MARK_ID_VOID(id) \
B_CATKEY((id))
#undef B_TRANSLATE_MARK_SYSTEM_NAME_VOID
#define B_TRANSLATE_MARK_SYSTEM_NAME_VOID(string) \
B_CATKEY((string), B_TRANSLATE_SYSTEM_NAME_CONTEXT, "")
#undef B_TRANSLATE_NOCOLLECT
#define B_TRANSLATE_NOCOLLECT(str) \
(void)
#define B_TRANSLATE_NOCOLLECT(string)
#undef B_TRANSLATE_NOCOLLECT_COMMENT
#define B_TRANSLATE_NOCOLLECT_COMMENT(str, cmt) \
(void)
#define B_TRANSLATE_NOCOLLECT_COMMENT(string, comment)
#undef B_TRANSLATE_NOCOLLECT_ALL
#define B_TRANSLATE_NOCOLLECT_ALL(str, ctx, cmt) \
(void)
#define B_TRANSLATE_NOCOLLECT_ALL(string, context, comment)
#undef B_TRANSLATE_NOCOLLECT_ID
#define B_TRANSLATE_NOCOLLECT_ID(id) \
(void)
#define B_TRANSLATE_NOCOLLECT_ID(id)
#undef B_TRANSLATE_NOCOLLECT_SYSTEM_NAME
#define B_TRANSLATE_NOCOLLECT_SYSTEM_NAME(str) \
(void)
#define B_TRANSLATE_NOCOLLECT_SYSTEM_NAME(string)
#endif /* B_COLLECTING_CATKEYS */
/************************************************************************/
// For BCatalog add-on implementations:
// TODO: should go into another header
class BCatalogAddOn {
public:
BCatalogAddOn(const char* signature,
const char* language,
uint32 fingerprint);
virtual ~BCatalogAddOn();
virtual const char* GetString(const char* string,
const char* context = NULL,
const char* comment = NULL) = 0;
virtual const char* GetString(uint32 id) = 0;
status_t InitCheck() const;
BCatalogAddOn* Next();
// the following could be used to localize non-textual data (e.g.
// icons), but these will only be implemented if there's demand for such
// a feature:
virtual bool CanHaveData() const;
virtual status_t GetData(const char* name, BMessage* msg);
virtual status_t GetData(uint32 id, BMessage* msg);
// interface for catalog-editor-app and testing apps:
virtual status_t SetString(const char* string,
const char* translated,
const char* context = NULL,
const char* comment = NULL);
virtual status_t SetString(int32 id, const char* translated);
virtual bool CanWriteData() const;
virtual status_t SetData(const char* name, BMessage* msg);
virtual status_t SetData(uint32 id, BMessage* msg);
virtual status_t ReadFromFile(const char* path = NULL);
virtual status_t ReadFromAttribute(
const entry_ref& appOrAddOnRef);
virtual status_t ReadFromResource(
const entry_ref& appOrAddOnRef);
virtual status_t WriteToFile(const char* path = NULL);
virtual status_t WriteToAttribute(
const entry_ref& appOrAddOnRef);
virtual status_t WriteToResource(
const entry_ref& appOrAddOnRef);
virtual void MakeEmpty();
virtual int32 CountItems() const;
// magic marker functions which are used to mark a string/id
// which will be translated elsewhere in the code (where it can
// not be found since it is references by a variable):
static const char* MarkForTranslation(const char* string,
const char* context, const char* comment);
static int32 MarkForTranslation(int32 id);
void SetNext(BCatalogAddOn* next);
protected:
virtual void UpdateFingerprint();
protected:
friend class BCatalog;
friend status_t get_add_on_catalog(BCatalog*, const char*);
status_t fInitCheck;
BString fSignature;
BString fLanguageName;
uint32 fFingerprint;
BCatalogAddOn* fNext;
};
// every catalog-add-on should export these symbols...
// ...the function that instantiates a catalog for this add-on-type...
extern "C"
BCatalogAddOn* instantiate_catalog(const char* signature, const char* language,
uint32 fingerprint);
// ...the function that creates an empty catalog for this add-on-type...
extern "C"
BCatalogAddOn* create_catalog(const char* signature, const char* language);
// ...and the priority which will be used to order the catalog-add-ons:
extern uint8 gCatalogAddOnPriority;
/*
* BCatalog - inlines for trivial accessors:
*/
inline const char*
BCatalog::GetNoAutoCollectString(const char* string, const char* context,
const char* comment)
{
return GetString(string, context, comment);
}
inline const char*
BCatalog::GetNoAutoCollectString(uint32 id)
{
return GetString(id);
}
/*
* BCatalogAddOn - inlines for trivial accessors:
*/
inline BCatalogAddOn*
BCatalogAddOn::Next()
{
return fNext;
}
inline const char*
BCatalogAddOn::MarkForTranslation(const char* str, const char* /* context */,
const char* /* comment */)
{
return str;
}
inline int32
BCatalogAddOn::MarkForTranslation(int32 id)
{
return id;
}
#endif /* _CATALOG_H_ */
+113
View File
@@ -0,0 +1,113 @@
/*
* Copyright 2003-2012, Haiku, Inc.
* Distributed under the terms of the MIT License.
*/
#ifndef _CATALOG_DATA_H_
#define _CATALOG_DATA_H_
#include <SupportDefs.h>
#include <String.h>
class BCatalog;
class BMessage;
struct entry_ref;
/**
* Base class for the catalog-data provided by every catalog add-on. An instance
* of this class represents (the data of) a single catalog. Several of these
* catalog data objects may be chained together in order to represent
* variations of a specific language. If for instance the catalog data 'en_uk'
* is chained to the data for 'en', a BCatalog using this catalog data chain
* will prefer any entries in the 'en_uk' catalog, but fallback onto 'en' for
* entries missing in the former.
*/
class BCatalogData {
public:
BCatalogData(const char* signature,
const char* language,
uint32 fingerprint);
virtual ~BCatalogData();
virtual const char* GetString(const char* string,
const char* context = NULL,
const char* comment = NULL) = 0;
virtual const char* GetString(uint32 id) = 0;
status_t InitCheck() const;
BCatalogData* Next();
// the following could be used to localize non-textual data (e.g.
// icons), but these will only be implemented if there's demand for such
// a feature:
virtual bool CanHaveData() const;
virtual status_t GetData(const char* name, BMessage* msg);
virtual status_t GetData(uint32 id, BMessage* msg);
// interface for catalog-editor-app and testing apps:
virtual status_t SetString(const char* string,
const char* translated,
const char* context = NULL,
const char* comment = NULL);
virtual status_t SetString(int32 id, const char* translated);
virtual bool CanWriteData() const;
virtual status_t SetData(const char* name, BMessage* msg);
virtual status_t SetData(uint32 id, BMessage* msg);
virtual status_t ReadFromFile(const char* path = NULL);
virtual status_t ReadFromAttribute(
const entry_ref& appOrAddOnRef);
virtual status_t ReadFromResource(
const entry_ref& appOrAddOnRef);
virtual status_t WriteToFile(const char* path = NULL);
virtual status_t WriteToAttribute(
const entry_ref& appOrAddOnRef);
virtual status_t WriteToResource(
const entry_ref& appOrAddOnRef);
virtual void MakeEmpty();
virtual int32 CountItems() const;
void SetNext(BCatalogData* next);
protected:
virtual void UpdateFingerprint();
protected:
friend class BCatalog;
friend status_t get_add_on_catalog(BCatalog*, const char*);
status_t fInitCheck;
BString fSignature;
BString fLanguageName;
uint32 fFingerprint;
BCatalogData* fNext;
};
inline BCatalogData*
BCatalogData::Next()
{
return fNext;
}
// every catalog-add-on should export the following three symbols:
//
// 1. the function that instantiates a catalog for this add-on-type
extern "C"
BCatalogData* instantiate_catalog(const char* signature, const char* language,
uint32 fingerprint);
// 2. the function that creates an empty catalog for this add-on-type
extern "C"
BCatalogData* create_catalog(const char* signature, const char* language);
// 3. the priority which will be used to order the catalog add-ons
extern uint8 gCatalogAddOnPriority;
#endif /* _CATALOG_DATA_H_ */
+2 -2
View File
@@ -46,9 +46,9 @@ class DefaultCatalog : public HashMapCatalog {
status_t SetRawString(const CatKey& key, const char *translated);
void SetSignature(const entry_ref &catalogOwner);
static BCatalogAddOn *Instantiate(const entry_ref& catalogOwner,
static BCatalogData *Instantiate(const entry_ref& catalogOwner,
const char *language, uint32 fingerprint);
static BCatalogAddOn *Create(const char *signature,
static BCatalogData *Create(const char *signature,
const char *language);
static const uint8 kDefaultCatalogAddOnPriority;
+1 -1
View File
@@ -46,7 +46,7 @@ public:
void MakeEmpty();
BCatalogAddOn* CatalogAddOn();
BCatalogData* CatalogData();
private:
EditableCatalog();
+4 -4
View File
@@ -15,7 +15,7 @@
#include <assert.h>
#include <Catalog.h>
#include <CatalogData.h>
#include <HashMap.h>
#include <String.h>
@@ -61,7 +61,7 @@ class CatKey {
};
class HashMapCatalog: public BCatalogAddOn {
class HashMapCatalog: public BCatalogData {
protected:
uint32 ComputeFingerprint() const;
typedef HashMap<CatKey, BString> CatMap;
@@ -72,7 +72,7 @@ class HashMapCatalog: public BCatalogAddOn {
uint32 fingerprint);
// Constructor for normal use
//
// overrides of BCatalogAddOn:
// overrides of BCatalogData:
const char *GetString(const char *string, const char *context = NULL,
const char *comment = NULL);
const char *GetString(uint32 id);
@@ -132,7 +132,7 @@ class HashMapCatalog: public BCatalogAddOn {
inline HashMapCatalog::HashMapCatalog(const char* signature,
const char* language, uint32 fingerprint)
:
BCatalogAddOn(signature, language, fingerprint)
BCatalogData(signature, language, fingerprint)
{
}
+10 -9
View File
@@ -1,5 +1,5 @@
/*
* Copyright 2010, Haiku. All rights reserved.
* Copyright 2010-2012, Haiku. All rights reserved.
* Distributed under the terms of the MIT license.
*/
#ifndef _MUTABLE_LOCALE_ROSTER_H_
@@ -21,7 +21,7 @@
class BLocale;
class BCatalog;
class BCatalogAddOn;
class BCatalogData;
struct entry_ref;
@@ -44,28 +44,29 @@ public:
// the message contains one or more
// 'language'-string-fields which
// contain the language-name(s)
status_t SetFilesystemTranslationPreferred(bool preferred);
status_t SetFilesystemTranslationPreferred(
bool preferred);
status_t LoadSystemCatalog(BCatalog* catalog) const;
BCatalogAddOn* LoadCatalog(const entry_ref& catalogOwner,
BCatalogData* LoadCatalog(const entry_ref& catalogOwner,
const char* language = NULL,
int32 fingerprint = 0) const;
status_t UnloadCatalog(BCatalogAddOn* addOn);
status_t UnloadCatalog(BCatalogData* catalogData);
BCatalogAddOn* CreateCatalog(const char* type,
BCatalogData* CreateCatalog(const char* type,
const char* signature,
const char* language);
};
typedef BCatalogAddOn* (*InstantiateCatalogFunc)(const entry_ref& catalogOwner,
typedef BCatalogData* (*InstantiateCatalogFunc)(const entry_ref& catalogOwner,
const char* language, uint32 fingerprint);
typedef BCatalogAddOn* (*CreateCatalogFunc)(const char* name,
typedef BCatalogData* (*CreateCatalogFunc)(const char* name,
const char* language);
typedef BCatalogAddOn* (*InstantiateEmbeddedCatalogFunc)(
typedef BCatalogData* (*InstantiateEmbeddedCatalogFunc)(
entry_ref* appOrAddOnRef);
typedef status_t (*GetAvailableLanguagesFunc)(BMessage*, const char*,
+1 -1
View File
@@ -33,7 +33,7 @@ class PlainTextCatalog : public HashMapCatalog {
status_t ReadFromFile(const char *path = NULL);
status_t WriteToFile(const char *path = NULL);
static BCatalogAddOn *Instantiate(const char *signature,
static BCatalogData *Instantiate(const char *signature,
const char *language, uint32 fingerprint);
static const char *kCatMimeType;