1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 ******************************************************************************
5 * Copyright (C) 2010-2016, International Business Machines Corporation and
6 * others. All Rights Reserved.
7 ******************************************************************************
13 #include "unicode/utypes.h"
15 #if U_SHOW_CPLUSPLUS_API
19 * \brief C++ API: Provides display names of Locale and its components.
22 #if !UCONFIG_NO_FORMATTING
24 #include "unicode/locid.h"
25 #include "unicode/strenum.h"
26 #include "unicode/uscript.h"
27 #include "unicode/uldnames.h"
28 #include "unicode/udisplaycontext.h"
33 * Returns display names of Locales and components of Locales. For
34 * more information on language, script, region, variant, key, and
38 class U_COMMON_API LocaleDisplayNames
: public UObject
{
44 virtual ~LocaleDisplayNames();
47 * Convenience overload of
48 * {@link #createInstance(const Locale& locale, UDialectHandling dialectHandling)}
49 * that specifies STANDARD dialect handling.
50 * @param locale the display locale
51 * @return a LocaleDisplayNames instance
54 inline static LocaleDisplayNames
* U_EXPORT2
createInstance(const Locale
& locale
);
57 * Returns an instance of LocaleDisplayNames that returns names
58 * formatted for the provided locale, using the provided
61 * @param locale the display locale
62 * @param dialectHandling how to select names for locales
63 * @return a LocaleDisplayNames instance
66 static LocaleDisplayNames
* U_EXPORT2
createInstance(const Locale
& locale
,
67 UDialectHandling dialectHandling
);
70 * Returns an instance of LocaleDisplayNames that returns names formatted
71 * for the provided locale, using the provided UDisplayContext settings.
73 * @param locale the display locale
74 * @param contexts List of one or more context settings (e.g. for dialect
75 * handling, capitalization, etc.
76 * @param length Number of items in the contexts list
77 * @return a LocaleDisplayNames instance
80 static LocaleDisplayNames
* U_EXPORT2
createInstance(const Locale
& locale
,
81 UDisplayContext
*contexts
, int32_t length
);
85 * Returns the locale used to determine the display names. This is
86 * not necessarily the same locale passed to {@link #createInstance}.
87 * @return the display locale
90 virtual const Locale
& getLocale() const = 0;
93 * Returns the dialect handling used in the display names.
94 * @return the dialect handling enum
97 virtual UDialectHandling
getDialectHandling() const = 0;
100 * Returns the UDisplayContext value for the specified UDisplayContextType.
101 * @param type the UDisplayContextType whose value to return
102 * @return the UDisplayContext for the specified type.
105 virtual UDisplayContext
getContext(UDisplayContextType type
) const = 0;
107 // names for entire locales
109 * Returns the display name of the provided locale.
110 * @param locale the locale whose display name to return
111 * @param result receives the locale's display name
112 * @return the display name of the provided locale
115 virtual UnicodeString
& localeDisplayName(const Locale
& locale
,
116 UnicodeString
& result
) const = 0;
119 * Returns the display name of the provided locale id.
120 * @param localeId the id of the locale whose display name to return
121 * @param result receives the locale's display name
122 * @return the display name of the provided locale
125 virtual UnicodeString
& localeDisplayName(const char* localeId
,
126 UnicodeString
& result
) const = 0;
128 // names for components of a locale id
130 * Returns the display name of the provided language code.
131 * @param lang the language code
132 * @param result receives the language code's display name
133 * @return the display name of the provided language code
136 virtual UnicodeString
& languageDisplayName(const char* lang
,
137 UnicodeString
& result
) const = 0;
140 * Returns the display name of the provided script code.
141 * @param script the script code
142 * @param result receives the script code's display name
143 * @return the display name of the provided script code
146 virtual UnicodeString
& scriptDisplayName(const char* script
,
147 UnicodeString
& result
) const = 0;
150 * Returns the display name of the provided script code.
151 * @param scriptCode the script code number
152 * @param result receives the script code's display name
153 * @return the display name of the provided script code
156 virtual UnicodeString
& scriptDisplayName(UScriptCode scriptCode
,
157 UnicodeString
& result
) const = 0;
160 * Returns the display name of the provided region code.
161 * @param region the region code
162 * @param result receives the region code's display name
163 * @return the display name of the provided region code
166 virtual UnicodeString
& regionDisplayName(const char* region
,
167 UnicodeString
& result
) const = 0;
170 * Returns the display name of the provided variant.
171 * @param variant the variant string
172 * @param result receives the variant's display name
173 * @return the display name of the provided variant
176 virtual UnicodeString
& variantDisplayName(const char* variant
,
177 UnicodeString
& result
) const = 0;
180 * Returns the display name of the provided locale key.
181 * @param key the locale key name
182 * @param result receives the locale key's display name
183 * @return the display name of the provided locale key
186 virtual UnicodeString
& keyDisplayName(const char* key
,
187 UnicodeString
& result
) const = 0;
190 * Returns the display name of the provided value (used with the provided key).
191 * @param key the locale key name
192 * @param value the locale key's value
193 * @param result receives the value's display name
194 * @return the display name of the provided value
197 virtual UnicodeString
& keyValueDisplayName(const char* key
, const char* value
,
198 UnicodeString
& result
) const = 0;
201 inline LocaleDisplayNames
* LocaleDisplayNames::createInstance(const Locale
& locale
) {
202 return LocaleDisplayNames::createInstance(locale
, ULDN_STANDARD_NAMES
);
209 #endif /* U_SHOW_CPLUSPLUS_API */