2010-05-06 19:42:48 +04:00
|
|
|
/*
|
2012-04-14 19:38:58 +04:00
|
|
|
* Copyright 2003-2012, Haiku, Inc.
|
2009-09-19 16:19:46 +04:00
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*/
|
2009-05-01 23:23:59 +04:00
|
|
|
#ifndef _CATALOG_H_
|
|
|
|
#define _CATALOG_H_
|
|
|
|
|
2010-11-03 00:36:35 +03:00
|
|
|
|
2010-07-20 15:38:34 +04:00
|
|
|
#include <LocaleRoster.h>
|
2012-04-14 19:38:58 +04:00
|
|
|
#include <Locker.h>
|
2009-05-01 23:23:59 +04:00
|
|
|
#include <SupportDefs.h>
|
|
|
|
#include <String.h>
|
|
|
|
|
2010-11-03 00:36:35 +03:00
|
|
|
|
2012-04-15 21:04:02 +04:00
|
|
|
class BCatalogData;
|
2009-05-01 23:23:59 +04:00
|
|
|
class BLocale;
|
|
|
|
class BMessage;
|
|
|
|
struct entry_ref;
|
|
|
|
|
|
|
|
|
2009-05-02 01:56:16 +04:00
|
|
|
class BCatalog {
|
2010-11-03 00:36:35 +03:00
|
|
|
public:
|
|
|
|
BCatalog();
|
2011-10-31 12:57:09 +04:00
|
|
|
BCatalog(const entry_ref& catalogOwner,
|
2010-11-03 00:36:35 +03:00
|
|
|
const char* language = NULL,
|
|
|
|
uint32 fingerprint = 0);
|
|
|
|
virtual ~BCatalog();
|
2009-05-01 23:23:59 +04:00
|
|
|
|
2010-11-03 00:36:35 +03:00
|
|
|
const char* GetString(const char* string,
|
|
|
|
const char* context = NULL,
|
|
|
|
const char* comment = NULL);
|
|
|
|
const char* GetString(uint32 id);
|
2009-05-01 23:23:59 +04:00
|
|
|
|
2010-11-03 00:36:35 +03:00
|
|
|
status_t GetData(const char* name, BMessage* msg);
|
|
|
|
status_t GetData(uint32 id, BMessage* msg);
|
2009-05-01 23:23:59 +04:00
|
|
|
|
2010-11-03 00:36:35 +03:00
|
|
|
status_t GetSignature(BString* signature);
|
|
|
|
status_t GetLanguage(BString* language);
|
|
|
|
status_t GetFingerprint(uint32* fingerprint);
|
2009-05-01 23:23:59 +04:00
|
|
|
|
2012-04-14 19:38:58 +04:00
|
|
|
status_t SetTo(const entry_ref& catalogOwner,
|
|
|
|
const char* language = NULL,
|
|
|
|
uint32 fingerprint = 0);
|
2010-07-01 15:54:09 +04:00
|
|
|
|
2010-11-03 00:36:35 +03:00
|
|
|
status_t InitCheck() const;
|
|
|
|
int32 CountItems() const;
|
2009-05-01 23:23:59 +04:00
|
|
|
|
2010-11-03 00:36:35 +03:00
|
|
|
protected:
|
|
|
|
BCatalog(const BCatalog&);
|
|
|
|
const BCatalog& operator= (const BCatalog&);
|
|
|
|
// hide assignment and copy-constructor
|
2009-05-01 23:23:59 +04:00
|
|
|
|
2012-04-15 21:04:02 +04:00
|
|
|
BCatalogData* fCatalogData;
|
2012-04-14 19:38:58 +04:00
|
|
|
mutable BLocker fLock;
|
2009-05-01 23:23:59 +04:00
|
|
|
|
2010-11-03 00:36:35 +03:00
|
|
|
private:
|
2012-04-14 19:24:20 +04:00
|
|
|
friend class BLocale;
|
|
|
|
friend status_t get_add_on_catalog(BCatalog*, const char*);
|
2009-05-01 23:23:59 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-04-16 23:31:22 +04:00
|
|
|
#undef B_TRANSLATION_SYSTEM_NAME_CONTEXT
|
|
|
|
#define B_TRANSLATION_SYSTEM_NAME_CONTEXT "System name"
|
2011-03-13 20:29:10 +03:00
|
|
|
|
|
|
|
|
2009-05-01 23:23:59 +04:00
|
|
|
#ifndef B_AVOID_TRANSLATION_MACROS
|
|
|
|
// macros for easy catalog-access, define B_AVOID_TRANSLATION_MACROS if
|
2010-07-26 02:47:39 +04:00
|
|
|
// you don't want these (in which case you need to collect the catalog keys
|
|
|
|
// manually, as collectcatkeys won't do it for you):
|
2009-05-01 23:23:59 +04:00
|
|
|
|
2012-04-16 23:31:22 +04:00
|
|
|
#undef B_TRANSLATION_CONTEXT
|
2009-05-02 01:56:16 +04:00
|
|
|
// In a single application, several strings (e.g. 'Ok') will be used
|
|
|
|
// more than once, in different contexts.
|
2009-05-01 23:23:59 +04:00
|
|
|
// As the application programmer can not know if all translations of
|
|
|
|
// this string will be the same for all languages, each occurrence of
|
|
|
|
// the string must be translated on its own.
|
|
|
|
// Specifying the context explicitly with each string allows the person
|
|
|
|
// translating a catalog to separate these different occurrences of the
|
2009-05-02 01:56:16 +04:00
|
|
|
// same string and tell which strings appears in what context of the
|
2009-05-01 23:23:59 +04:00
|
|
|
// application.
|
|
|
|
// In order to give the translator a useful hint, the application
|
2012-04-16 23:31:22 +04:00
|
|
|
// programmer needs to define B_TRANSLATION_CONTEXT with the context he'd
|
2010-05-08 02:59:42 +04:00
|
|
|
// like to be associated with the strings used in this specifc source file.
|
2009-05-01 23:23:59 +04:00
|
|
|
// example:
|
2012-04-16 23:31:22 +04:00
|
|
|
// #define B_TRANSLATION_CONTEXT "Folder-Window"
|
2009-05-02 01:56:16 +04:00
|
|
|
// Tip: Use a descriptive name of the class implemented in that
|
|
|
|
// source-file.
|
2009-05-01 23:23:59 +04:00
|
|
|
|
2012-08-16 23:10:53 +04:00
|
|
|
#ifdef B_COLLECTING_CATKEYS
|
|
|
|
|
|
|
|
// pull in all the macros used when collecting catalog keys.
|
|
|
|
#include <tools/CollectingCatalog.h>
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2009-05-01 23:23:59 +04:00
|
|
|
// Translation macros which may be used to shorten translation requests:
|
2010-05-10 18:44:54 +04:00
|
|
|
#undef B_TRANSLATE
|
2010-11-03 00:36:35 +03:00
|
|
|
#define B_TRANSLATE(string) \
|
2010-11-22 16:06:36 +03:00
|
|
|
BLocaleRoster::Default()->GetCatalog()->GetString((string), \
|
2012-04-16 23:31:22 +04:00
|
|
|
B_TRANSLATION_CONTEXT)
|
2010-11-03 00:36:35 +03:00
|
|
|
|
2012-04-16 23:31:22 +04:00
|
|
|
#undef B_TRANSLATE_CONTEXT
|
|
|
|
#define B_TRANSLATE_CONTEXT(string, context) \
|
2010-11-22 16:06:36 +03:00
|
|
|
BLocaleRoster::Default()->GetCatalog()->GetString((string), (context))
|
2010-07-01 15:54:09 +04:00
|
|
|
|
|
|
|
#undef B_TRANSLATE_COMMENT
|
2010-11-03 00:36:35 +03:00
|
|
|
#define B_TRANSLATE_COMMENT(string, comment) \
|
2010-11-22 16:06:36 +03:00
|
|
|
BLocaleRoster::Default()->GetCatalog()->GetString((string), \
|
2012-04-16 23:31:22 +04:00
|
|
|
B_TRANSLATION_CONTEXT, (comment))
|
2010-07-01 15:54:09 +04:00
|
|
|
|
|
|
|
#undef B_TRANSLATE_ALL
|
2010-11-03 00:36:35 +03:00
|
|
|
#define B_TRANSLATE_ALL(string, context, comment) \
|
2010-11-22 16:06:36 +03:00
|
|
|
BLocaleRoster::Default()->GetCatalog()->GetString((string), (context), \
|
|
|
|
(comment))
|
2010-07-01 15:54:09 +04:00
|
|
|
|
|
|
|
#undef B_TRANSLATE_ID
|
|
|
|
#define B_TRANSLATE_ID(id) \
|
2010-11-22 16:06:36 +03:00
|
|
|
BLocaleRoster::Default()->GetCatalog()->GetString((id))
|
2009-05-01 23:23:59 +04:00
|
|
|
|
2011-03-26 01:13:48 +03:00
|
|
|
#undef B_TRANSLATE_SYSTEM_NAME
|
|
|
|
#define B_TRANSLATE_SYSTEM_NAME(string) \
|
2011-03-15 19:00:58 +03:00
|
|
|
BLocaleRoster::Default()->IsFilesystemTranslationPreferred() \
|
2012-04-15 21:04:02 +04:00
|
|
|
? BLocaleRoster::Default()->GetCatalog()->GetString((string), \
|
2012-04-16 23:31:22 +04:00
|
|
|
B_TRANSLATION_SYSTEM_NAME_CONTEXT) \
|
2012-04-15 21:04:02 +04:00
|
|
|
: (string)
|
2011-03-15 19:00:58 +03:00
|
|
|
|
2009-05-01 23:23:59 +04:00
|
|
|
// Translation markers which can be used to mark static strings/IDs which
|
2012-04-15 21:04:02 +04:00
|
|
|
// are used as key for translation requests (at other places in the code).
|
|
|
|
/* Example:
|
2012-04-16 23:31:22 +04:00
|
|
|
#define B_TRANSLATION_CONTEXT "MyDecentApp-Menu"
|
2009-05-01 23:23:59 +04:00
|
|
|
|
2012-04-14 19:24:20 +04:00
|
|
|
static const char* choices[] = {
|
2010-05-10 18:44:54 +04:00
|
|
|
B_TRANSLATE_MARK("left"),
|
|
|
|
B_TRANSLATE_MARK("right"),
|
|
|
|
B_TRANSLATE_MARK("up"),
|
|
|
|
B_TRANSLATE_MARK("down")
|
2009-05-01 23:23:59 +04:00
|
|
|
};
|
|
|
|
|
2012-04-15 21:04:02 +04:00
|
|
|
void MyClass::AddChoices(BMenu* menu)
|
|
|
|
{
|
2012-04-14 19:24:20 +04:00
|
|
|
for (char** ch = choices; *ch != '\0'; ++ch) {
|
2009-05-01 23:23:59 +04:00
|
|
|
menu->AddItem(
|
|
|
|
new BMenuItem(
|
2010-05-10 18:44:54 +04:00
|
|
|
B_TRANSLATE(*ch),
|
2009-05-01 23:23:59 +04:00
|
|
|
new BMessage(...)
|
|
|
|
)
|
2012-04-14 19:24:20 +04:00
|
|
|
);
|
2009-05-01 23:23:59 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
2010-05-10 18:44:54 +04:00
|
|
|
#undef B_TRANSLATE_MARK
|
2012-04-15 21:04:02 +04:00
|
|
|
#define B_TRANSLATE_MARK(string) (string)
|
2009-05-01 23:23:59 +04:00
|
|
|
|
2017-08-05 05:59:22 +03:00
|
|
|
#undef B_TRANSLATE_MARK_CONTEXT
|
|
|
|
#define B_TRANSLATE_MARK_CONTEXT(string, context) (string)
|
|
|
|
|
2010-05-10 18:44:54 +04:00
|
|
|
#undef B_TRANSLATE_MARK_COMMENT
|
2012-04-15 21:04:02 +04:00
|
|
|
#define B_TRANSLATE_MARK_COMMENT(string, comment) (string)
|
2009-05-01 23:23:59 +04:00
|
|
|
|
2010-05-10 18:44:54 +04:00
|
|
|
#undef B_TRANSLATE_MARK_ALL
|
2012-04-15 21:04:02 +04:00
|
|
|
#define B_TRANSLATE_MARK_ALL(string, context, comment) (string)
|
2009-05-02 01:56:16 +04:00
|
|
|
|
2010-05-10 18:44:54 +04:00
|
|
|
#undef B_TRANSLATE_MARK_ID
|
2012-04-15 21:04:02 +04:00
|
|
|
#define B_TRANSLATE_MARK_ID(id) (id)
|
2009-05-02 01:56:16 +04:00
|
|
|
|
2011-03-26 01:13:48 +03:00
|
|
|
#undef B_TRANSLATE_MARK_SYSTEM_NAME
|
2012-04-15 21:04:02 +04:00
|
|
|
#define B_TRANSLATE_MARK_SYSTEM_NAME(string) (string)
|
|
|
|
|
|
|
|
// the same for void contexts:
|
|
|
|
#undef B_TRANSLATE_MARK_VOID
|
|
|
|
#define B_TRANSLATE_MARK_VOID(string)
|
|
|
|
|
2017-08-05 05:59:22 +03:00
|
|
|
#undef B_TRANSLATE_MARK_CONTEXT_VOID
|
|
|
|
#define B_TRANSLATE_MARK_CONTEXT_VOID(string, context)
|
|
|
|
|
2012-04-15 21:04:02 +04:00
|
|
|
#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)
|
2011-03-13 20:29:10 +03:00
|
|
|
|
2012-08-16 23:10:53 +04:00
|
|
|
// Translation macros which cause collectcatkeys to ignore this key
|
2010-07-26 02:47:39 +04:00
|
|
|
// (useful in combination with the marking macros above):
|
|
|
|
#undef B_TRANSLATE_NOCOLLECT
|
2012-04-15 21:04:02 +04:00
|
|
|
#define B_TRANSLATE_NOCOLLECT(string) \
|
|
|
|
B_TRANSLATE(string)
|
2010-07-26 02:47:39 +04:00
|
|
|
|
|
|
|
#undef B_TRANSLATE_NOCOLLECT_COMMENT
|
2012-04-15 21:04:02 +04:00
|
|
|
#define B_TRANSLATE_NOCOLLECT_COMMENT(string, comment) \
|
|
|
|
B_TRANSLATE_COMMENT(string, comment)
|
2010-07-26 02:47:39 +04:00
|
|
|
|
|
|
|
#undef B_TRANSLATE_NOCOLLECT_ALL
|
2012-04-15 21:04:02 +04:00
|
|
|
#define B_TRANSLATE_NOCOLLECT_ALL(string, context, comment) \
|
|
|
|
B_TRANSLATE_ALL(string, context, comment)
|
2010-07-26 02:47:39 +04:00
|
|
|
|
|
|
|
#undef B_TRANSLATE_NOCOLLECT_ID
|
|
|
|
#define B_TRANSLATE_NOCOLLECT_ID(id) \
|
|
|
|
B_TRANSLATE_ID(id)
|
|
|
|
|
2011-03-26 01:13:48 +03:00
|
|
|
#undef B_TRANSLATE_NOCOLLECT_SYSTEM_NAME
|
2012-04-15 21:04:02 +04:00
|
|
|
#define B_TRANSLATE_NOCOLLECT_SYSTEM_NAME(string) \
|
|
|
|
B_TRANSLATE_SYSTEM_NAME(string)
|
2011-03-15 19:00:58 +03:00
|
|
|
|
2012-08-16 23:10:53 +04:00
|
|
|
#endif /* B_COLLECTING_CATKEYS */
|
|
|
|
|
2009-05-01 23:23:59 +04:00
|
|
|
#endif /* B_AVOID_TRANSLATION_MACROS */
|
|
|
|
|
|
|
|
|
2009-09-20 21:57:06 +04:00
|
|
|
#endif /* _CATALOG_H_ */
|