2 ******************************************************************************
3 * Copyright (C) 2010-2012, International Business Machines Corporation and
4 * others. All Rights Reserved.
5 ******************************************************************************
11 #include "unicode/utypes.h"
15 * \brief C++ API: Provides display names of Locale and its components.
18 #if !UCONFIG_NO_FORMATTING
20 #include "unicode/locid.h"
21 #include "unicode/uscript.h"
22 #include "unicode/uldnames.h"
23 #include "unicode/udisplaycontext.h"
28 * Returns display names of Locales and components of Locales. For
29 * more information on language, script, region, variant, key, and
33 class U_I18N_API LocaleDisplayNames
: public UObject
{
39 virtual ~LocaleDisplayNames();
42 * Convenience overload of
43 * {@link #createInstance(const Locale& locale, UDialectHandling dialectHandling)}
44 * that specifies STANDARD dialect handling.
45 * @param locale the display locale
46 * @return a LocaleDisplayNames instance
49 static LocaleDisplayNames
* U_EXPORT2
createInstance(const Locale
& locale
);
52 * Returns an instance of LocaleDisplayNames that returns names
53 * formatted for the provided locale, using the provided
56 * @param locale the display locale
57 * @param dialectHandling how to select names for locales
58 * @return a LocaleDisplayNames instance
61 static LocaleDisplayNames
* U_EXPORT2
createInstance(const Locale
& locale
,
62 UDialectHandling dialectHandling
);
64 #ifndef U_HIDE_DRAFT_API
66 * Returns an instance of LocaleDisplayNames that returns names formatted
67 * for the provided locale, using the provided UDisplayContext settings.
69 * @param locale the display locale
70 * @param contexts List of one or more context settings (e.g. for dialect
71 * handling, capitalization, etc.
72 * @param length Number of items in the contexts list
73 * @return a LocaleDisplayNames instance
76 static LocaleDisplayNames
* U_EXPORT2
createInstance(const Locale
& locale
,
77 UDisplayContext
*contexts
, int32_t length
);
78 #endif /* U_HIDE_DRAFT_API */
82 * Returns the locale used to determine the display names. This is
83 * not necessarily the same locale passed to {@link #createInstance}.
84 * @return the display locale
87 virtual const Locale
& getLocale() const = 0;
90 * Returns the dialect handling used in the display names.
91 * @return the dialect handling enum
94 virtual UDialectHandling
getDialectHandling() const = 0;
97 * Returns the UDisplayContext value for the specified UDisplayContextType.
98 * @param type the UDisplayContextType whose value to return
99 * @return the UDisplayContext for the specified type.
102 virtual UDisplayContext
getContext(UDisplayContextType type
) const = 0;
104 // names for entire locales
106 * Returns the display name of the provided locale.
107 * @param locale the locale whose display name to return
108 * @param result receives the locale's display name
109 * @return the display name of the provided locale
112 virtual UnicodeString
& localeDisplayName(const Locale
& locale
,
113 UnicodeString
& result
) const = 0;
116 * Returns the display name of the provided locale id.
117 * @param localeId the id of the locale whose display name to return
118 * @param result receives the locale's display name
119 * @return the display name of the provided locale
122 virtual UnicodeString
& localeDisplayName(const char* localeId
,
123 UnicodeString
& result
) const = 0;
125 // names for components of a locale id
127 * Returns the display name of the provided language code.
128 * @param lang the language code
129 * @param result receives the language code's display name
130 * @return the display name of the provided language code
133 virtual UnicodeString
& languageDisplayName(const char* lang
,
134 UnicodeString
& result
) const = 0;
137 * Returns the display name of the provided script code.
138 * @param script the script code
139 * @param result receives the script code's display name
140 * @return the display name of the provided script code
143 virtual UnicodeString
& scriptDisplayName(const char* script
,
144 UnicodeString
& result
) const = 0;
147 * Returns the display name of the provided script code.
148 * @param scriptCode the script code number
149 * @param result receives the script code's display name
150 * @return the display name of the provided script code
153 virtual UnicodeString
& scriptDisplayName(UScriptCode scriptCode
,
154 UnicodeString
& result
) const = 0;
157 * Returns the display name of the provided region code.
158 * @param region the region code
159 * @param result receives the region code's display name
160 * @return the display name of the provided region code
163 virtual UnicodeString
& regionDisplayName(const char* region
,
164 UnicodeString
& result
) const = 0;
167 * Returns the display name of the provided variant.
168 * @param variant the variant string
169 * @param result receives the variant's display name
170 * @return the display name of the provided variant
173 virtual UnicodeString
& variantDisplayName(const char* variant
,
174 UnicodeString
& result
) const = 0;
177 * Returns the display name of the provided locale key.
178 * @param key the locale key name
179 * @param result receives the locale key's display name
180 * @return the display name of the provided locale key
183 virtual UnicodeString
& keyDisplayName(const char* key
,
184 UnicodeString
& result
) const = 0;
187 * Returns the display name of the provided value (used with the provided key).
188 * @param key the locale key name
189 * @param value the locale key's value
190 * @param result receives the value's display name
191 * @return the display name of the provided value
194 virtual UnicodeString
& keyValueDisplayName(const char* key
, const char* value
,
195 UnicodeString
& result
) const = 0;
198 inline LocaleDisplayNames
* LocaleDisplayNames::createInstance(const Locale
& locale
) {
199 return LocaleDisplayNames::createInstance(locale
, ULDN_STANDARD_NAMES
);