Add a new way of using the locale kit with static accessors instead of global variables. This has the following consequences :

* Applications don't have to declare BCatalog fCatalog themselves, it's now done automatically
 * Libs and add-ons can be localized just the same way (except static libraries)
For now this new system is yet disabled as I'm looking for some peer review before going on. To enable it you have to define B_TRANSLATE_USE_NEW_MACROS in each file doing catalog access. This will not stay, I'll update the 
other apps to use it.
The linking in jamfiles must be not only with liblocale.so, but also liblocalestub.a. Not sure how to handle this for user-side applications. Libraries are also required to provide a MIME signature to use any catalog.
The locale preflet is updated to the new system (as a test). Othe rapps will follow if everyone is ok with this approach.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37323 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Adrien Destugues
2010-07-01 11:54:09 +00:00
parent 75e7233162
commit 76a4353b79
12 changed files with 162 additions and 22 deletions
+34
View File
@@ -33,6 +33,8 @@ class BCatalog {
status_t GetLanguage(BString *lang);
status_t GetFingerprint(uint32 *fp);
status_t SetCatalog(const char* signature, uint32 fingerprint);
status_t InitCheck() const;
int32 CountItems() const;
@@ -56,6 +58,21 @@ class BCatalog {
extern BCatalog* be_catalog;
extern BCatalog* be_app_catalog;
// Proxy class for handling a "shared object local" catalog.
// This must be included (statically linked) into each shared object needing
// a catalog on its own (application, add-on, library, ...). The shared object
// must also have a mimetype so that the catalog can be identified.
class BCatalogStub {
private:
static BCatalog sCatalog;
static vint32 sCatalogInitOnce;
public:
static BCatalog* GetCatalog();
};
#ifndef B_AVOID_TRANSLATION_MACROS
// macros for easy catalog-access, define B_AVOID_TRANSLATION_MACROS if
// you don't want these:
@@ -79,8 +96,24 @@ extern BCatalog* be_app_catalog;
// source-file.
#ifdef B_TRANSLATE_USE_NEW_MACROS
// Translation macros which may be used to shorten translation requests:
#undef B_TRANSLATE
#define B_TRANSLATE(str) \
BCatalogStub::GetCatalog()->GetString((str), B_TRANSLATE_CONTEXT)
#undef B_TRANSLATE_COMMENT
#define B_TRANSLATE_COMMENT(str, cmt) \
BCatalogStub::GetCatalog()->GetString((str), B_TRANSLATE_CONTEXT, (cmt))
#undef B_TRANSLATE_ALL
#define B_TRANSLATE_ALL(str, ctx, cmt) \
BCatalogStub::GetCatalog()->GetString((str), (ctx), (cmt))
#undef B_TRANSLATE_ID
#define B_TRANSLATE_ID(id) \
BCatalogStub::GetCatalog()->GetString((id))
#else
#define B_TRANSLATE(str) \
be_catalog->GetString((str), B_TRANSLATE_CONTEXT)
@@ -95,6 +128,7 @@ extern BCatalog* be_app_catalog;
#undef B_TRANSLATE_ID
#define B_TRANSLATE_ID(id) \
be_catalog->GetString((id))
#endif
// 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):
+1
View File
@@ -36,6 +36,7 @@ class BLocaleRoster {
// status_t GetCatalog(BLocale *,const char *mimeType, BCatalog *catalog);
// status_t GetCatalog(const char *mimeType, BCatalog *catalog);
// status_t SetCatalog(BLocale *,const char *mimeType, BCatalog *catalog);
BCatalog* GetCatalog(BCatalog* catalog, vint32* catalogInitStatus);
// status_t GetLocaleFor(const char *langCode, const char *countryCode);