1 // Copyright (C) 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"
17 * \brief C++ API: Provides display names of Locale and its components.
20 #if !UCONFIG_NO_FORMATTING
22 #include "unicode/locid.h"
23 #include "unicode/uscript.h"
24 #include "unicode/uldnames.h"
25 #include "unicode/udisplaycontext.h"
30 * Returns display names of Locales and components of Locales. For
31 * more information on language, script, region, variant, key, and
35 class U_COMMON_API LocaleDisplayNames : public UObject {
41 virtual ~LocaleDisplayNames();
44 * Convenience overload of
45 * {@link #createInstance(const Locale& locale, UDialectHandling dialectHandling)}
46 * that specifies STANDARD dialect handling.
47 * @param locale the display locale
48 * @return a LocaleDisplayNames instance
51 static LocaleDisplayNames* U_EXPORT2 createInstance(const Locale& locale);
54 * Returns an instance of LocaleDisplayNames that returns names
55 * formatted for the provided locale, using the provided
58 * @param locale the display locale
59 * @param dialectHandling how to select names for locales
60 * @return a LocaleDisplayNames instance
63 static LocaleDisplayNames* U_EXPORT2 createInstance(const Locale& locale,
64 UDialectHandling dialectHandling);
67 * Returns an instance of LocaleDisplayNames that returns names formatted
68 * for the provided locale, using the provided UDisplayContext settings.
70 * @param locale the display locale
71 * @param contexts List of one or more context settings (e.g. for dialect
72 * handling, capitalization, etc.
73 * @param length Number of items in the contexts list
74 * @return a LocaleDisplayNames instance
77 static LocaleDisplayNames* U_EXPORT2 createInstance(const Locale& locale,
78 UDisplayContext *contexts, int32_t length);
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);