* reintegrated gsoc-locale-kit branch into trunk - there's more
work to do, but it's about time to give this code more exposure. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33176 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -15,7 +15,7 @@ class BCatalog {
|
||||
public:
|
||||
BCatalog();
|
||||
BCatalog(const char *signature, const char *language = NULL,
|
||||
int32 fingerprint = 0);
|
||||
uint32 fingerprint = 0);
|
||||
virtual ~BCatalog();
|
||||
|
||||
const char *GetString(const char *string, const char *context = NULL,
|
||||
@@ -27,7 +27,7 @@ class BCatalog {
|
||||
|
||||
status_t GetSignature(BString *sig);
|
||||
status_t GetLanguage(BString *lang);
|
||||
status_t GetFingerprint(int32 *fp);
|
||||
status_t GetFingerprint(uint32 *fp);
|
||||
|
||||
status_t InitCheck() const;
|
||||
int32 CountItems() const;
|
||||
@@ -143,7 +143,7 @@ class BCatalogAddOn {
|
||||
friend class BLocaleRoster;
|
||||
public:
|
||||
BCatalogAddOn(const char *signature, const char *language,
|
||||
int32 fingerprint);
|
||||
uint32 fingerprint);
|
||||
virtual ~BCatalogAddOn();
|
||||
|
||||
virtual const char *GetString(const char *string,
|
||||
@@ -195,7 +195,7 @@ class BCatalogAddOn {
|
||||
status_t fInitCheck;
|
||||
BString fSignature;
|
||||
BString fLanguageName;
|
||||
int32 fFingerprint;
|
||||
uint32 fFingerprint;
|
||||
BCatalogAddOn *fNext;
|
||||
|
||||
friend class BCatalog;
|
||||
@@ -206,7 +206,7 @@ class BCatalogAddOn {
|
||||
// ...the function that instantiates a catalog for this add-on-type...
|
||||
extern "C"
|
||||
BCatalogAddOn *instantiate_catalog(const char *signature,
|
||||
const char *language, int32 fingerprint);
|
||||
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,
|
||||
@@ -243,7 +243,7 @@ BCatalog::GetLanguage(BString *lang)
|
||||
|
||||
|
||||
inline status_t
|
||||
BCatalog::GetFingerprint(int32 *fp)
|
||||
BCatalog::GetFingerprint(uint32 *fp)
|
||||
{
|
||||
if (!fp)
|
||||
return B_BAD_VALUE;
|
||||
|
||||
+45
-30
@@ -6,6 +6,13 @@
|
||||
#include <LocaleStrings.h>
|
||||
#include <String.h>
|
||||
|
||||
#include <unicode/locid.h>
|
||||
|
||||
namespace icu_4_2 {
|
||||
class DateFormat;
|
||||
}
|
||||
|
||||
|
||||
enum {
|
||||
B_METRIC = 0,
|
||||
B_US
|
||||
@@ -14,39 +21,46 @@ enum {
|
||||
|
||||
class BCountry {
|
||||
public:
|
||||
BCountry();
|
||||
BCountry(const char* languageCode, const char* countryCode);
|
||||
BCountry(const char* languageAndCountryCode = "en_US");
|
||||
virtual ~BCountry();
|
||||
|
||||
virtual const char *Name() const;
|
||||
virtual bool Name(BString&) const;
|
||||
const char* Code() const;
|
||||
|
||||
// see definitions below
|
||||
const char *GetString(uint32 id) const;
|
||||
|
||||
// date & time
|
||||
|
||||
virtual void FormatDate(char *string,size_t maxSize,time_t time,bool longFormat);
|
||||
virtual void FormatDate(BString *string,time_t time,bool longFormat);
|
||||
virtual void FormatTime(char *string,size_t maxSize,time_t time,bool longFormat);
|
||||
virtual void FormatTime(BString *string,time_t time,bool longFormat);
|
||||
virtual void FormatDate(char* string, size_t maxSize, time_t time,
|
||||
bool longFormat);
|
||||
virtual void FormatDate(BString* string, time_t time, bool longFormat);
|
||||
virtual void FormatTime(char* string, size_t maxSize, time_t time,
|
||||
bool longFormat);
|
||||
virtual void FormatTime(BString* string, time_t time,
|
||||
bool longFormat);
|
||||
|
||||
const char *DateFormat(bool longFormat) const;
|
||||
const char *TimeFormat(bool longFormat) const;
|
||||
const char *DateSeparator() const;
|
||||
const char *TimeSeparator() const;
|
||||
bool DateFormat(BString&, bool longFormat) const;
|
||||
void SetDateFormat(const char* formatString,
|
||||
bool longFormat = true);
|
||||
bool TimeFormat(BString&, bool longFormat) const;
|
||||
const char* DateSeparator() const;
|
||||
const char* TimeSeparator() const;
|
||||
|
||||
// numbers
|
||||
|
||||
virtual void FormatNumber(char *string,size_t maxSize,double value);
|
||||
virtual void FormatNumber(BString *string,double value);
|
||||
virtual void FormatNumber(char *string,size_t maxSize,int32 value);
|
||||
virtual void FormatNumber(BString *string,int32 value);
|
||||
virtual void FormatNumber(char* string, size_t maxSize, double value);
|
||||
virtual UErrorCode FormatNumber(BString* string, double value);
|
||||
virtual void FormatNumber(char* string, size_t maxSize, int32 value);
|
||||
virtual void FormatNumber(BString* string, int32 value);
|
||||
|
||||
const char *DecimalPoint() const;
|
||||
const char *ThousandsSeparator() const;
|
||||
const char *Grouping() const;
|
||||
bool DecimalPoint(BString&) const;
|
||||
bool ThousandsSeparator(BString&) const;
|
||||
bool Grouping(BString&) const;
|
||||
|
||||
const char *PositiveSign() const;
|
||||
const char *NegativeSign() const;
|
||||
bool PositiveSign(BString&) const;
|
||||
bool NegativeSign(BString&) const;
|
||||
|
||||
// measurements
|
||||
|
||||
@@ -54,21 +68,22 @@ class BCountry {
|
||||
|
||||
// monetary
|
||||
|
||||
virtual ssize_t FormatMonetary(char *string,size_t maxSize,char *format, ...);
|
||||
virtual ssize_t FormatMonetary(BString *string,char *format, ...);
|
||||
virtual ssize_t FormatMonetary(char* string, size_t maxSize,
|
||||
double value);
|
||||
virtual ssize_t FormatMonetary(BString* string, double value);
|
||||
|
||||
const char *CurrencySymbol() const;
|
||||
const char *InternationalCurrencySymbol() const;
|
||||
const char *MonDecimalPoint() const;
|
||||
const char *MonThousandsSeparator() const;
|
||||
const char *MonGrouping() const;
|
||||
bool CurrencySymbol(BString&) const;
|
||||
bool InternationalCurrencySymbol(BString&) const;
|
||||
bool MonDecimalPoint(BString&) const;
|
||||
bool MonThousandsSeparator(BString&) const;
|
||||
bool MonGrouping(BString&) const;
|
||||
virtual int32 MonFracDigits() const;
|
||||
|
||||
protected:
|
||||
BCountry(const char **strings);
|
||||
|
||||
private:
|
||||
const char **fStrings;
|
||||
icu_4_2::DateFormat* fICULongDateFormatter;
|
||||
icu_4_2::DateFormat* fICUShortDateFormatter;
|
||||
const char** fStrings;
|
||||
Locale fICULocale;
|
||||
};
|
||||
|
||||
#endif /* _COUNTRY_H_ */
|
||||
|
||||
@@ -1,199 +0,0 @@
|
||||
#ifndef _DEFAULT_CATALOG_H_
|
||||
#define _DEFAULT_CATALOG_H_
|
||||
|
||||
#if __GNUC__ > 2
|
||||
# include <ext/hash_map>
|
||||
#else
|
||||
# include <hash_map>
|
||||
#endif
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include <Catalog.h>
|
||||
#include <DataIO.h>
|
||||
#include <String.h>
|
||||
|
||||
class BFile;
|
||||
|
||||
namespace BPrivate {
|
||||
struct CatKey;
|
||||
}
|
||||
|
||||
#if __GNUC__ > 2
|
||||
namespace __gnu_cxx {
|
||||
#endif // __GNUC__ > 2
|
||||
|
||||
template<>
|
||||
struct hash<BPrivate::CatKey> {
|
||||
size_t operator() (const BPrivate::CatKey &key) const;
|
||||
};
|
||||
|
||||
#if __GNUC__ > 2
|
||||
} // namespace __gnu_cxx
|
||||
#endif // __GNUC__ > 2
|
||||
|
||||
namespace BPrivate {
|
||||
|
||||
/*
|
||||
* The key-type for the hash_map which maps native strings or IDs to
|
||||
* the corresponding translated string.
|
||||
* The key-type should be efficient to use if it is just created by an ID
|
||||
* but it should also support being created from up to three strings,
|
||||
* which as a whole specify the key to the translated string.
|
||||
*/
|
||||
struct CatKey {
|
||||
BString fKey;
|
||||
// the key-string consists of three values separated by a special
|
||||
// token:
|
||||
// - the native string
|
||||
// - the context of the string's usage
|
||||
// - a comment that can be used to separate strings that
|
||||
// are identical otherwise (useful for the translator)
|
||||
size_t fHashVal;
|
||||
// the hash-value of fKey
|
||||
uint32 fFlags;
|
||||
// with respect to the catalog-editor, each translation can be
|
||||
// in different states (empty, unchecked, checked, etc.).
|
||||
// This state (and potential other flags) lives in the fFlags member.
|
||||
CatKey(const char *str, const char *ctx, const char *cmt);
|
||||
CatKey(uint32 id);
|
||||
CatKey();
|
||||
bool operator== (const CatKey& right) const;
|
||||
status_t GetStringParts(BString* str, BString* ctx, BString* cmt) const;
|
||||
static size_t HashFun(const char* s);
|
||||
};
|
||||
|
||||
/*
|
||||
* The implementation of the Locale Kit's standard catalog-type.
|
||||
* Currently it only maps CatKey to a BString (the translated string),
|
||||
* but the value-type might change to add support for shortcuts and/or
|
||||
* graphical data (button-images and the like).
|
||||
*/
|
||||
class DefaultCatalog : public BCatalogAddOn {
|
||||
|
||||
public:
|
||||
DefaultCatalog(const char *signature, const char *language,
|
||||
int32 fingerprint);
|
||||
// constructor for normal use
|
||||
DefaultCatalog(entry_ref *appOrAddOnRef);
|
||||
// constructor for embedded catalog
|
||||
DefaultCatalog(const char *path, const char *signature,
|
||||
const char *language);
|
||||
// constructor for editor-app
|
||||
|
||||
~DefaultCatalog();
|
||||
|
||||
// overrides of BCatalogAddOn:
|
||||
const char *GetString(const char *string, const char *context = NULL,
|
||||
const char *comment = NULL);
|
||||
const char *GetString(uint32 id);
|
||||
const char *GetString(const CatKey& key);
|
||||
//
|
||||
status_t SetString(const char *string, const char *translated,
|
||||
const char *context = NULL, const char *comment = NULL);
|
||||
status_t SetString(int32 id, const char *translated);
|
||||
status_t SetString(const CatKey& key, const char *translated);
|
||||
void UpdateFingerprint();
|
||||
|
||||
// implementation for editor-interface:
|
||||
status_t ReadFromFile(const char *path = NULL);
|
||||
status_t ReadFromAttribute(entry_ref *appOrAddOnRef);
|
||||
status_t ReadFromResource(entry_ref *appOrAddOnRef);
|
||||
status_t WriteToFile(const char *path = NULL);
|
||||
status_t WriteToAttribute(entry_ref *appOrAddOnRef);
|
||||
status_t WriteToResource(entry_ref *appOrAddOnRef);
|
||||
//
|
||||
void MakeEmpty();
|
||||
int32 CountItems() const;
|
||||
|
||||
static BCatalogAddOn *Instantiate(const char *signature,
|
||||
const char *language,
|
||||
int32 fingerprint);
|
||||
static BCatalogAddOn *InstantiateEmbedded(entry_ref *appOrAddOnRef);
|
||||
static BCatalogAddOn *Create(const char *signature,
|
||||
const char *language);
|
||||
static const uint8 kDefaultCatalogAddOnPriority;
|
||||
static const char *kCatMimeType;
|
||||
|
||||
private:
|
||||
status_t Flatten(BDataIO *dataIO);
|
||||
status_t Unflatten(BDataIO *dataIO);
|
||||
int32 ComputeFingerprint() const;
|
||||
void UpdateAttributes(BFile& catalogFile);
|
||||
|
||||
#if __GNUC__ > 2
|
||||
typedef __gnu_cxx::hash_map<CatKey, BString,
|
||||
__gnu_cxx::hash<CatKey>, std::equal_to<CatKey> > CatMap;
|
||||
#else
|
||||
typedef hash_map<CatKey, BString, hash<CatKey>,
|
||||
std::equal_to<CatKey> > CatMap;
|
||||
#endif
|
||||
CatMap fCatMap;
|
||||
mutable BString fPath;
|
||||
|
||||
public:
|
||||
/*
|
||||
* CatWalker
|
||||
*/
|
||||
class CatWalker {
|
||||
public:
|
||||
CatWalker() {}
|
||||
CatWalker(CatMap &catMap);
|
||||
bool AtEnd() const;
|
||||
const CatKey& GetKey() const;
|
||||
const char *GetValue() const;
|
||||
void Next();
|
||||
private:
|
||||
CatMap::iterator fPos;
|
||||
CatMap::iterator fEnd;
|
||||
};
|
||||
status_t GetWalker(CatWalker *walker);
|
||||
};
|
||||
|
||||
inline
|
||||
DefaultCatalog::CatWalker::CatWalker(CatMap &catMap)
|
||||
: fPos(catMap.begin()),
|
||||
fEnd(catMap.end())
|
||||
{
|
||||
}
|
||||
|
||||
inline bool
|
||||
DefaultCatalog::CatWalker::AtEnd() const
|
||||
{
|
||||
return fPos == fEnd;
|
||||
}
|
||||
|
||||
inline const CatKey &
|
||||
DefaultCatalog::CatWalker::GetKey() const
|
||||
{
|
||||
assert(fPos != fEnd);
|
||||
return fPos->first;
|
||||
}
|
||||
|
||||
inline const char *
|
||||
DefaultCatalog::CatWalker::GetValue() const
|
||||
{
|
||||
assert(fPos != fEnd);
|
||||
return fPos->second.String();
|
||||
}
|
||||
|
||||
inline void
|
||||
DefaultCatalog::CatWalker::Next()
|
||||
{
|
||||
++fPos;
|
||||
}
|
||||
|
||||
inline status_t
|
||||
DefaultCatalog::GetWalker(CatWalker *walker)
|
||||
{
|
||||
if (!walker)
|
||||
return B_BAD_VALUE;
|
||||
*walker = CatWalker(fCatMap);
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
} // namespace BPrivate
|
||||
|
||||
using namespace BPrivate;
|
||||
|
||||
#endif /* _DEFAULT_CATALOG_H_ */
|
||||
@@ -1,3 +1,9 @@
|
||||
/*
|
||||
** Copyright 2003, Axel Dörfler, [email protected]. All rights reserved.
|
||||
** Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _LANGUAGE_H_
|
||||
#define _LANGUAGE_H_
|
||||
|
||||
|
||||
@@ -25,7 +25,8 @@ class BLocale {
|
||||
|
||||
void FormatString(char *target, size_t maxSize, char *fmt, ...);
|
||||
void FormatString(BString *, char *fmt, ...);
|
||||
void FormatDateTime(char *target, size_t maxSize, const char *fmt, time_t);
|
||||
void FormatDateTime(char *target, size_t maxSize, const char *fmt,
|
||||
time_t);
|
||||
void FormatDateTime(BString *, const char *fmt, time_t);
|
||||
|
||||
// Country short-hands
|
||||
@@ -37,8 +38,10 @@ class BLocale {
|
||||
|
||||
// Collator short-hands
|
||||
|
||||
int StringCompare(const char *, const char *, int32 len = -1, int8 strength = B_COLLATE_DEFAULT) const;
|
||||
int StringCompare(const BString *, const BString *, int32 len = -1, int8 strength = B_COLLATE_DEFAULT) const;
|
||||
int StringCompare(const char *, const char *, int32 len = -1,
|
||||
int8 strength = B_COLLATE_DEFAULT) const;
|
||||
int StringCompare(const BString *, const BString *,
|
||||
int32 len = -1, int8 strength = B_COLLATE_DEFAULT) const;
|
||||
|
||||
void GetSortKey(const char *string, BString *key);
|
||||
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
#ifndef _LOCALE_ROSTER_H_
|
||||
#define _LOCALE_ROSTER_H_
|
||||
|
||||
|
||||
#include <String.h>
|
||||
|
||||
|
||||
class BLanguage;
|
||||
class BLocale;
|
||||
class BCollator;
|
||||
@@ -10,6 +12,8 @@ class BCountry;
|
||||
class BCatalog;
|
||||
class BCatalogAddOn;
|
||||
|
||||
struct entry_ref;
|
||||
|
||||
namespace BPrivate {
|
||||
class EditableCatalog;
|
||||
};
|
||||
@@ -18,6 +22,7 @@ enum {
|
||||
B_LOCALE_CHANGED = '_LCC',
|
||||
};
|
||||
|
||||
|
||||
class BLocaleRoster {
|
||||
|
||||
public:
|
||||
@@ -28,11 +33,12 @@ class BLocaleRoster {
|
||||
// status_t GetCatalog(const char *mimeType, BCatalog *catalog);
|
||||
// status_t SetCatalog(BLocale *,const char *mimeType, BCatalog *catalog);
|
||||
|
||||
// status_t GetLocaleFor(const char *langCode,const char *countryCode);
|
||||
// status_t GetLocaleFor(const char *langCode, const char *countryCode);
|
||||
|
||||
status_t GetDefaultCollator(BCollator **) const;
|
||||
status_t GetDefaultLanguage(BLanguage **) const;
|
||||
status_t GetDefaultCountry(BCountry **) const;
|
||||
void SetDefaultCountry(BCountry *) const;
|
||||
|
||||
status_t GetPreferredLanguages(BMessage *) const;
|
||||
status_t SetPreferredLanguages(BMessage *);
|
||||
@@ -43,36 +49,29 @@ class BLocaleRoster {
|
||||
// the message contains one or more 'language'-string-fields
|
||||
// which contain the language-name(s)
|
||||
|
||||
status_t GetInstalledCatalogs(BMessage *,
|
||||
const char* sigPattern = NULL,
|
||||
const char* langPattern = NULL,
|
||||
int32 fingerprint = 0) const;
|
||||
status_t GetInstalledCatalogs(BMessage *, const char* sigPattern = NULL,
|
||||
const char* langPattern = NULL, int32 fingerprint = 0) const;
|
||||
// the message contains...
|
||||
|
||||
// status_t GetDefaultLanguage(BLanguage *);
|
||||
// status_t SetDefaultLanguage(BLanguage *);
|
||||
|
||||
static const char *kCatLangAttr;
|
||||
static const char *kCatSigAttr;
|
||||
static const char *kCatFingerprintAttr;
|
||||
//
|
||||
|
||||
static const char *kCatManagerMimeType;
|
||||
static const char *kCatEditorMimeType;
|
||||
//
|
||||
|
||||
static const char *kEmbeddedCatAttr;
|
||||
static int32 kEmbeddedCatResId;
|
||||
|
||||
private:
|
||||
|
||||
BCatalogAddOn* LoadCatalog(const char *signature,
|
||||
const char *language = NULL,
|
||||
int32 fingerprint = 0);
|
||||
const char *language = NULL, int32 fingerprint = 0);
|
||||
BCatalogAddOn* LoadEmbeddedCatalog(entry_ref *appOrAddOnRef);
|
||||
status_t UnloadCatalog(BCatalogAddOn *addOn);
|
||||
//
|
||||
|
||||
BCatalogAddOn* CreateCatalog(const char *type,
|
||||
const char *signature,
|
||||
const char *language);
|
||||
const char *signature, const char *language);
|
||||
|
||||
friend class BCatalog;
|
||||
friend class BPrivate::EditableCatalog;
|
||||
|
||||
@@ -6,13 +6,9 @@ enum country_strings {
|
||||
B_COUNTRY_STRINGS_BASE = 0,
|
||||
|
||||
B_DATE_TIME_FORMAT = B_COUNTRY_STRINGS_BASE,
|
||||
B_DATE_FORMAT,
|
||||
B_TIME_FORMAT,
|
||||
B_TIME_AM_PM_FORMAT,
|
||||
|
||||
B_SHORT_DATE_TIME_FORMAT,
|
||||
B_SHORT_DATE_FORMAT,
|
||||
B_SHORT_TIME_FORMAT,
|
||||
B_SHORT_TIME_AM_PM_FORMAT,
|
||||
|
||||
B_AM_STRING,
|
||||
@@ -20,17 +16,6 @@ enum country_strings {
|
||||
|
||||
B_DATE_SEPARATOR,
|
||||
B_TIME_SEPARATOR,
|
||||
B_GROUPING,
|
||||
B_DECIMAL_POINT,
|
||||
B_THOUSANDS_SEPARATOR,
|
||||
B_POSITIVE_SIGN,
|
||||
B_NEGATIVE_SIGN,
|
||||
|
||||
B_CURRENCY_SYMBOL,
|
||||
B_INT_CURRENCY_SYMBOL,
|
||||
B_MON_GROUPING,
|
||||
B_MON_DECIMAL_POINT,
|
||||
B_MON_THOUSANDS_SEPARATOR,
|
||||
|
||||
B_NUM_COUNTRY_STRINGS,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user