|PUBLIC MEMBERS:||CLASSES | STRUCTS | UNIONS | ENUMS | TYPEDEFS | METHODS | STATIC METHODS | DATA | STATIC DATA|
|PRIVATE MEMBERS:||CLASSES | STRUCTS | UNIONS | ENUMS | TYPEDEFS | METHODS | STATIC METHODS | DATA | STATIC DATA|
:: rtl ::
- Base Classes
- Known Derived Classes
OLocaleobject represents a specific geographical, political, or cultural region. An operation that requires a
OLocaleto perform its task is called locale-sensitive and uses the
OLocaleto tailor information for the user. For example, displaying a number is a locale-sensitive operation--the number should be formatted according to the customs/conventions of the user's native country, region, or culture.
You create a
OLocaleobject using one of the two constructors in this class:
OLocale(String language, String country) OLocale(String language, String country, String variant)
The second argument to both constructors is a valid ISO Country Code. These codes are the upper-case two-letter codes as defined by ISO-3166. You can find a full list of these codes at a number of sites, such as:
The second constructor requires a third argument--the Variant. The Variant codes are vendor and browser-specific. For example, use WIN for Windows, MAC for Macintosh, and POSIX for POSIX. Where there are two variants, separate them with an underscore, and put the most important one first. For example, a Traditional Spanish collation might be referenced, with "ES", "ES", "Traditional_WIN".
OLocaleobject is just an identifier for a region, no validity check is performed when you construct a
OLocale. If you want to see whether particular resources are available for the
OLocaleyou construct, you must query those resources. For example, ask the
NumberFormatfor the locales it supports using its
Note: When you ask for a resource for a particular locale, you get back the best available match, not necessarily precisely what you asked for. For more information, look at
OLocaleclass provides a number of convenient constants that you can use to create
OLocaleobjects for commonly used locales. For example, the following creates a
OLocaleobject for the United States:
Once you've created a
OLocaleyou can query it for information about itself. Use
getCountryto get the ISO Country Code and
getLanguageto get the ISO Language Code. You can use
getDisplayCountryto get the name of the country suitable for displaying to the user. Similarly, you can use
getDisplayLanguageto get the name of the language suitable for displaying to the user. Interestingly, the
getDisplayXXXmethods are themselves locale-sensitive and have two versions: one that uses the default locale and one that uses the locale specified as an argument.
The JDK provides a number of classes that perform locale-sensitive operations. For example, the
NumberFormatclass formats numbers, currency, or percentages in a locale-sensitive manner. Classes such as
NumberFormathave a number of convenience methods for creating a default object of that type. For example, the
NumberFormatclass provides these three convenience methods for creating a default
NumberFormat.getInstance() NumberFormat.getCurrencyInstance() NumberFormat.getPercentInstance()
NumberFormat.getInstance(myLocale) NumberFormat.getCurrencyInstance(myLocale) NumberFormat.getPercentInstance(myLocale)
OLocaleis the mechanism for identifying the kind of object (
NumberFormat) that you would like to get. The locale is just a mechanism for identifying objects, not a container for the objects themselves.
Each class that performs locale-sensitive operations allows you to get all the available objects of that type. You can sift through these objects by language, country, or variant, and use the display names to present a menu to the user. For example, you can create a menu of all the collation objects suitable for a given language. Such classes must implement these three class methods:
public static OLocale getAvailableLocales() public static String getDisplayName(OLocale objectLocale, OLocale displayLocale) public static final String getDisplayName(OLocale objectLocale) // getDisplayName will throw MissingResourceException if the locale // is not one of the available locales.
OLocale( rtl_Locale * locale );
OLocale( const OLocale & obj );
operator=( const OLocale & obj );
getLanguage( ) const;
Getter for programmatic name of field, an lowercased two-letter ISO-639 code. OUString
getCountry( ) const;
Getter for programmatic name of field, an uppercased two-letter ISO-3166 code. OUString
getVariant( ) const;
Getter for programmatic name of field. sal_Int32
hashCode( ) const;
Returns the hash code of the locale This. sal_Bool
operator==( const OLocale & obj ) const;
getData( ) const;
registerLocale( const OUString & language, const OUString & country, const OUString & variant );
Construct a locale from language, country, variant. static OLocale
registerLocale( const OUString & language, const OUString & country );
Construct a locale from language, country. static OLocale
setDefault( const OUString & language, const OUString & country, const OUString & variant );
rtl_Locale * pData; Must be the first member in this class. OUString access this member with *(rtl_Locale **)&locale.
Copyright © 2012, The Apache Software Foundation, Licensed under the Apache License, Version 2.0. Apache, the Apache feather logo, Apache OpenOffice and OpenOffice.org are trademarks of The Apache Software Foundation. Other names may be trademarks of their respective owners.