Implement taking date strings from messages locale.
* mimic LocaleKit and add option to POSIX locale backend for taking the date strings from the messages locale (instead of time locale)
This commit is contained in:
@@ -31,6 +31,8 @@ public:
|
||||
const char* PosixLocaleName()
|
||||
{ return fPosixLocaleName; }
|
||||
|
||||
const Locale& ICULocale() const;
|
||||
|
||||
protected:
|
||||
status_t _ConvertUnicodeStringToLocaleconvEntry(
|
||||
const UnicodeString& string,
|
||||
@@ -52,6 +54,14 @@ private:
|
||||
};
|
||||
|
||||
|
||||
inline
|
||||
const Locale&
|
||||
ICUCategoryData::ICULocale() const
|
||||
{
|
||||
return fLocale;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Libroot
|
||||
} // namespace BPrivate
|
||||
|
||||
|
||||
@@ -18,11 +18,15 @@ namespace BPrivate {
|
||||
namespace Libroot {
|
||||
|
||||
|
||||
class ICUMessagesData;
|
||||
|
||||
|
||||
class ICUTimeData : public ICUCategoryData {
|
||||
typedef ICUCategoryData inherited;
|
||||
public:
|
||||
ICUTimeData(pthread_key_t tlsKey,
|
||||
struct lc_time_t& lcTimeInfo);
|
||||
struct lc_time_t& lcTimeInfo,
|
||||
const ICUMessagesData& messagesData);
|
||||
~ICUTimeData();
|
||||
|
||||
void Initialize(LocaleTimeDataBridge* dataBridge);
|
||||
@@ -33,8 +37,6 @@ public:
|
||||
|
||||
const char* GetLanginfo(int index);
|
||||
|
||||
const Locale& ICULocale() const;
|
||||
|
||||
private:
|
||||
status_t _SetLCTimeEntries(const UnicodeString* strings,
|
||||
char* destination, int entrySize,
|
||||
@@ -59,6 +61,8 @@ private:
|
||||
struct lc_time_t& fLCTimeInfo;
|
||||
|
||||
LocaleTimeDataBridge* fDataBridge;
|
||||
|
||||
const ICUMessagesData& fMessagesData;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ ICULocaleBackend::ICULocaleBackend()
|
||||
fMessagesData(fThreadLocalStorageKey),
|
||||
fMonetaryData(fThreadLocalStorageKey, fLocaleConv),
|
||||
fNumericData(fThreadLocalStorageKey, fLocaleConv),
|
||||
fTimeData(fThreadLocalStorageKey, fLCTimeInfo),
|
||||
fTimeData(fThreadLocalStorageKey, fLCTimeInfo, fMessagesData),
|
||||
fTimeConversion(fTimeData)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -15,16 +15,19 @@
|
||||
|
||||
#include <AutoDeleter.h>
|
||||
|
||||
#include "ICUMessagesData.h"
|
||||
|
||||
namespace BPrivate {
|
||||
namespace Libroot {
|
||||
|
||||
|
||||
ICUTimeData::ICUTimeData(pthread_key_t tlsKey, struct lc_time_t& lcTimeInfo)
|
||||
ICUTimeData::ICUTimeData(pthread_key_t tlsKey, struct lc_time_t& lcTimeInfo,
|
||||
const ICUMessagesData& messagesData)
|
||||
:
|
||||
inherited(tlsKey),
|
||||
fLCTimeInfo(lcTimeInfo),
|
||||
fDataBridge(NULL)
|
||||
fDataBridge(NULL),
|
||||
fMessagesData(messagesData)
|
||||
{
|
||||
for (int i = 0; i < 12; ++i) {
|
||||
fLCTimeInfo.mon[i] = fMon[i];
|
||||
@@ -66,7 +69,19 @@ ICUTimeData::SetTo(const Locale& locale, const char* posixLocaleName)
|
||||
return result;
|
||||
|
||||
UErrorCode icuStatus = U_ZERO_ERROR;
|
||||
DateFormatSymbols formatSymbols(fLocale, icuStatus);
|
||||
|
||||
// check if the date strings should be taken from the messages-locale
|
||||
// or from the time-locale (default)
|
||||
const Locale* symbolsLocale = &fLocale;
|
||||
char stringsValue[16];
|
||||
fLocale.getKeywordValue("strings", stringsValue, sizeof(stringsValue),
|
||||
icuStatus);
|
||||
if (U_SUCCESS(icuStatus) && strcasecmp(stringsValue, "messages") == 0)
|
||||
symbolsLocale = &fMessagesData.ICULocale();
|
||||
else
|
||||
icuStatus = U_ZERO_ERROR;
|
||||
|
||||
DateFormatSymbols formatSymbols(*symbolsLocale, icuStatus);
|
||||
if (!U_SUCCESS(icuStatus))
|
||||
return B_UNSUPPORTED;
|
||||
|
||||
@@ -407,13 +422,5 @@ ICUTimeData::_SetLCTimePattern(DateFormat* format, char* destination,
|
||||
}
|
||||
|
||||
|
||||
const Locale&
|
||||
ICUTimeData::ICULocale() const
|
||||
{
|
||||
return fLocale;
|
||||
|
||||
}
|
||||
|
||||
|
||||
} // namespace Libroot
|
||||
} // namespace BPrivate
|
||||
|
||||
Reference in New Issue
Block a user