ICU-67 Added ResourceBundle::getLocale() and supporting stuff (Locale::getName, rewritten ResourceBundle::constructForLocale...)
X-SVN-Rev: 173
This commit is contained in:
parent
1d2370edc5
commit
17dbf189a9
@ -29,6 +29,7 @@
|
||||
* getLanguagesForCountry()
|
||||
* 03/16/99 bertrand rehaul.
|
||||
* 07/21/99 stephen Added U_CFUNC setDefault
|
||||
* 11/09/99 weiv Added const char * getName() const;
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
@ -415,6 +416,12 @@ Locale::getName(UnicodeString& name) const
|
||||
return name;
|
||||
}
|
||||
|
||||
const char *
|
||||
Locale::getName() const
|
||||
{
|
||||
return fullName;
|
||||
}
|
||||
|
||||
// deprecated
|
||||
UnicodeString&
|
||||
Locale::getISO3Language(UnicodeString& lang) const
|
||||
|
@ -24,6 +24,7 @@
|
||||
* 04/24/97 aliu Numerous changes per code review.
|
||||
* 08/18/98 stephen Added tokenizeString(),changed getDisplayName()
|
||||
* 09/08/98 stephen Moved definition of kEmptyString for Mac Port
|
||||
* 11/09/99 weiv Added const char * getName() const;
|
||||
*****************************************************************************************
|
||||
*/
|
||||
|
||||
@ -33,6 +34,13 @@
|
||||
|
||||
#include "unistr.h"
|
||||
|
||||
typedef struct ULocale ULocale;
|
||||
typedef struct UHashtable UHashtable;
|
||||
|
||||
#define ULOC_LANG_CAPACITY 3
|
||||
#define ULOC_COUNTRY_CAPACITY 3
|
||||
#define ULOC_FULLNAME_CAPACITY 50
|
||||
|
||||
/**
|
||||
*
|
||||
* A <code>Locale</code> object represents a specific geographical, political,
|
||||
@ -170,13 +178,6 @@
|
||||
* </pre>
|
||||
* </blockquote>
|
||||
*/
|
||||
typedef struct ULocale ULocale;
|
||||
typedef struct UHashtable UHashtable;
|
||||
|
||||
#define ULOC_LANG_CAPACITY 3
|
||||
#define ULOC_COUNTRY_CAPACITY 3
|
||||
#define ULOC_FULLNAME_CAPACITY 50
|
||||
|
||||
class U_COMMON_API Locale
|
||||
{
|
||||
public:
|
||||
@ -325,6 +326,15 @@ public:
|
||||
UnicodeString& getName( UnicodeString& name) const;
|
||||
|
||||
/**
|
||||
* Returns the programmatic name of the entire locale, with the language,
|
||||
* country and variant separated by underbars. If a field is missing, at
|
||||
* most one underbar will occur. Example: "en", "de_DE", "en_US_WIN",
|
||||
* "de_POSIX", "fr_MAC"
|
||||
* @return A pointer to "name".
|
||||
*/
|
||||
const char * getName() const;
|
||||
|
||||
/**
|
||||
* Fills in "name" with the locale's three-letter language code, as specified
|
||||
* in ISO draft standard ISO-639-2..
|
||||
* @param name Receives the three-letter language code.
|
||||
|
@ -47,6 +47,7 @@
|
||||
* Cleaned up.
|
||||
* 06/14/99 stephen Removed methods taking a filename suffix.
|
||||
* 06/22/99 stephen Added missing T_FileStream_close in parse()
|
||||
* 11/09/99 weiv Added getLocale(), rewritten constructForLocale()
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
@ -291,7 +292,7 @@ ResourceBundle::ResourceBundle( const UnicodeString& path,
|
||||
const UnicodeString& localeName,
|
||||
UErrorCode& status)
|
||||
: fPath(path, kDefaultSuffix),
|
||||
fRealLocaleID(localeName),
|
||||
fRealLocale(localeName),
|
||||
fIsDataOwned(TRUE),
|
||||
fVersionID(0),
|
||||
fgCache(fgUserCache),
|
||||
@ -377,34 +378,32 @@ ResourceBundle::constructForLocale(const PathInfo& path,
|
||||
fIsDataOwned = FALSE;
|
||||
fVersionID = 0;
|
||||
|
||||
// fRealLocale can be inited in three ways, see 1), 2), 3)
|
||||
UnicodeString returnedLocale;
|
||||
locale.getName(returnedLocale);
|
||||
if (returnedLocale.size()!=0) {
|
||||
// 1) Desired Locale has a name
|
||||
fRealLocale = Locale(returnedLocale);
|
||||
} else {
|
||||
// 2) Desired Locale name is empty, so we use default locale for the system
|
||||
fRealLocale = Locale(kDefaultLocaleName);
|
||||
}
|
||||
error = U_ZERO_ERROR;
|
||||
|
||||
locale.getName(fRealLocaleID);
|
||||
|
||||
// if the locale we were passed is Locale("", "", ""), that, by
|
||||
// convention, refers to the root locale (default.txt), even when
|
||||
// the system default locale is something else (otherwise there's no
|
||||
// way to get to it). We can accomplish this by changing the locale
|
||||
// name to "default" here. I'm not sure this is the best way to do
|
||||
// this, but it's simple and it works.
|
||||
if(fRealLocaleID.size() == 0)
|
||||
fRealLocaleID = kDefaultLocaleName;
|
||||
|
||||
for(i = 1; i < kDataCount; ++i) {
|
||||
fData[i] = 0;
|
||||
fDataStatus[i] = U_INTERNAL_PROGRAM_ERROR;
|
||||
fLoaded[i] = FALSE;
|
||||
}
|
||||
|
||||
UnicodeString returnedLocale;
|
||||
error = U_ZERO_ERROR;
|
||||
fData[0] = getHashtableForLocale(fRealLocaleID, returnedLocale, error);
|
||||
fData[0] = getHashtableForLocale(fRealLocale.getName(), returnedLocale, error);
|
||||
fLoaded[0] = TRUE;
|
||||
fDataStatus[0] = U_ZERO_ERROR;
|
||||
if(U_SUCCESS(error))
|
||||
fRealLocaleID = returnedLocale;
|
||||
// 3) We're unable to get the desired Locale, so we're using what is provided (fallback occured)
|
||||
fRealLocale = Locale(returnedLocale);
|
||||
|
||||
fLocaleIterator = new LocaleFallbackIterator(fRealLocaleID,
|
||||
fLocaleIterator = new LocaleFallbackIterator(fRealLocale.getName(),
|
||||
kDefaultLocaleName, FALSE);
|
||||
}
|
||||
|
||||
@ -1121,6 +1120,11 @@ ResourceBundle::addToCache(const UnicodeString& localeName,
|
||||
}
|
||||
}
|
||||
|
||||
const Locale &ResourceBundle::getLocale(void) const
|
||||
{
|
||||
return fRealLocale;
|
||||
}
|
||||
|
||||
ResourceBundle::PathInfo::PathInfo()
|
||||
: fWPrefix(NULL), fWSuffix(NULL)
|
||||
{}
|
||||
|
@ -43,6 +43,7 @@
|
||||
* Reworked to use new binary format.
|
||||
* Cleaned up.
|
||||
* 06/14/99 stephen Removed methods taking a filename suffix.
|
||||
* 11/09/99 weiv Added getLocale(), fRealLocale, removed fRealLocaleID
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
@ -423,6 +424,13 @@ public:
|
||||
*/
|
||||
const char* getVersionNumber(void) const;
|
||||
|
||||
/**
|
||||
* Return the Locale associated with this ResourceBundle.
|
||||
*
|
||||
* @return a Locale object
|
||||
*/
|
||||
const Locale &getLocale(void) const ;
|
||||
|
||||
private:
|
||||
class U_COMMON_API PathInfo {
|
||||
public:
|
||||
@ -621,7 +629,7 @@ private:
|
||||
bool_t fLoaded[kDataCount];
|
||||
UErrorCode fDataStatus[kDataCount]; // Returns the appropriate error code for each data table.
|
||||
bool_t fIsDataOwned;
|
||||
UnicodeString fRealLocaleID;
|
||||
Locale fRealLocale;
|
||||
LocaleFallbackIterator* fLocaleIterator;
|
||||
char* fVersionID;
|
||||
};
|
||||
|
@ -18,6 +18,7 @@
|
||||
* 04/01/97 aliu Creation.
|
||||
* 06/14/99 stephen Removed functions taking a filename suffix.
|
||||
* 07/20/99 stephen Changed for UResourceBundle typedef'd to void*
|
||||
* 11/09/99 weiv Added ures_getLocale()
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
@ -66,7 +67,7 @@ U_CAPI const UChar* ures_get( const UResourceBundle* resourceBundle,
|
||||
const char* resourceTag,
|
||||
UErrorCode* status)
|
||||
{
|
||||
if (U_FAILURE(*status)) return NULL;
|
||||
if (status==NULL || U_FAILURE(*status)) return NULL;
|
||||
if (!resourceBundle || !resourceTag)
|
||||
{
|
||||
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
||||
@ -84,7 +85,7 @@ U_CAPI const UChar* ures_getArrayItem(const UResourceBundle* resourceBundle,
|
||||
int32_t resourceIndex,
|
||||
UErrorCode* status)
|
||||
{
|
||||
if (U_FAILURE(*status)) return NULL;
|
||||
if (status==NULL || U_FAILURE(*status)) return NULL;
|
||||
if (!resourceBundle || !resourceTag || (resourceIndex < 0))
|
||||
{
|
||||
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
||||
@ -105,7 +106,7 @@ U_CAPI const UChar* ures_get2dArrayItem(const UResourceBundle* resourceBundle,
|
||||
int32_t columnIndex,
|
||||
UErrorCode* status)
|
||||
{
|
||||
if (U_FAILURE(*status)) return NULL;
|
||||
if (status==NULL || U_FAILURE(*status)) return NULL;
|
||||
if (!resourceBundle || !resourceTag || (rowIndex < 0) || (columnIndex < 0))
|
||||
{
|
||||
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
||||
@ -120,12 +121,23 @@ U_CAPI const UChar* ures_get2dArrayItem(const UResourceBundle* resourceBundle,
|
||||
else return NULL;
|
||||
}
|
||||
|
||||
U_CAPI const char* ures_getLocale(const UResourceBundle* resourceBundle, UErrorCode* status)
|
||||
{
|
||||
if (status==NULL || U_FAILURE(*status)) return NULL;
|
||||
if (!resourceBundle)
|
||||
{
|
||||
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
||||
return NULL;
|
||||
}
|
||||
return ((ResourceBundle*)resourceBundle)->getLocale().getName();
|
||||
}
|
||||
|
||||
U_CAPI const UChar* ures_getTaggedArrayItem(const UResourceBundle* resourceBundle,
|
||||
const char* resourceTag,
|
||||
const char* itemTag,
|
||||
UErrorCode* status)
|
||||
{
|
||||
if (U_FAILURE(*status)) return NULL;
|
||||
if (status==NULL || U_FAILURE(*status)) return NULL;
|
||||
if (!resourceBundle || !resourceTag || !itemTag)
|
||||
{
|
||||
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
||||
|
@ -21,6 +21,7 @@
|
||||
* 04/15/99 Madhu Updated Javadoc
|
||||
* 06/14/99 stephen Removed functions taking a filename suffix.
|
||||
* 07/20/99 stephen Language-independent ypedef to void*
|
||||
* 11/09/99 weiv Added ures_getLocale()
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
@ -324,5 +325,13 @@ U_CAPI void U_EXPORT2 ures_close(UResourceBundle* resourceBundle);
|
||||
* string.
|
||||
*/
|
||||
U_CAPI const char* U_EXPORT2 ures_getVersionNumber(const UResourceBundle* resourceBundle);
|
||||
|
||||
/**
|
||||
* Return the name of the Locale associated with this ResourceBundle.
|
||||
* @param resourceBundle: resource bundle in question
|
||||
* @param status: just for catching illegal arguments
|
||||
* @return A Locale name
|
||||
*/
|
||||
U_CAPI const char* ures_getLocale(const UResourceBundle* resourceBundle, UErrorCode* status);
|
||||
#endif /*_URES*/
|
||||
/*eof*/
|
||||
|
Loading…
Reference in New Issue
Block a user