public final class LocalizedText extends Object
This primitive DataType is specified as a string that is composed of a language component and a country/region component as specified by RFC 3066. The <country/region> component is always preceded by a hyphen. The format of the LocaleId string is shown below:
<language>[-<country/region>], where <language> is the two letter ISO 639 code for a language, <country/region> is the two letter ISO 3166 code for the country/region.
Empty locale is used as an invariant locale and to define a default value when there is no locale information. Clients can use the empty locale to set the invariant/default locale text.
Empty text is used by the Client when removing a translation for a given locale. A special
LocalizedText with empty locale and empty text can be used to remove all translations.
OPC UA Binary encodings use a "not present" marker when the locale or text part would be null or
empty. The SDK uses empty String as the localeId and text part in this case. Given null Strings
to constructor and LocalizedText.Builder methods are interpreted as empty Strings instead.
The rules for constructing LocaleIds defined by RFC 3066 are restricted for OPC UA as follows: d) OPC UA permits only zero or one <country/region> component to follow the <language> component, e) OPC UA also permits the "-CHS" and "-CHT" three-letter <country/region> codes for "Simplified" and "Traditional" Chinese locales. f) OPC UA also allows the use of other <country/region> codes as deemed necessary by the client or the server.
Example: English en English (US) en-US German de German (Germany) de-DE German (Austrian) de-AT
See Country Codes http://www.iso.org/iso/english_country_names_and_code_elements See
Language Codes http://www.loc.gov/standards/iso639-2/php/English_list.php
http://www.ietf.org/rfc/rfc3066.txt,
Locale| Modifier and Type | Class and Description |
|---|---|
static class |
LocalizedText.Builder
Builder for
LocalizedText. |
| Modifier and Type | Field and Description |
|---|---|
static LocalizedText |
EMPTY
A constant with the Invariant localeId (empty string) and empty text.
|
static LocalizedText[] |
EMPTY_ARRAY |
static LocalizedText |
EMPTY_EN |
static NodeId |
ID
Deprecated.
use
Identifiers.LocalizedText instead. |
static Pattern |
LOCALE_PATTERN
The pattern of the locale part.
|
static String |
MUL_LOCALE_ID
The LocaleId for the multiple language locale.
|
static Locale |
NO_LOCALE
Empty
Locale. |
static LocalizedText |
NULL
Deprecated.
use
EMPTY instead. |
static Locale |
NULL_LOCALE
Deprecated.
use
NO_LOCALE instead. |
| Constructor and Description |
|---|
LocalizedText(String text)
Create new Localized Text with locale NO_LOCALE.
|
LocalizedText(String text,
Locale locale)
Create new localized text.
|
LocalizedText(String text,
String localeId)
Create new Localized Text.
|
| Modifier and Type | Method and Description |
|---|---|
LocalizedText |
asSingleLocale(List<Locale> localePreferences)
Returns a
LocalizedText that only contains a single localized value, based on the given
locale preferences. |
LocalizedText |
asSingleLocale(Locale localePreferences)
Returns a
LocalizedText that only contains a single localized value, based on the given
locale preferences. |
static LocalizedText.Builder |
builder()
Creates a new Builder for
LocalizedText. |
static LocalizedText |
english(String text)
Create a english text.
|
boolean |
equals(Object obj) |
static LocalizedText |
from(String text)
Returns a
LocalizedText with a single text for the "invariant locale"
(NO_LOCALE). |
static LocalizedText |
from(String text,
Locale locale)
Returns a
LocalizedText with a single text for the given locale. |
static LocalizedText |
from(String text,
String localeId)
Returns a
LocalizedText with a single text for the given locale. |
static LocalizedText |
fromMultiLocaleJson(String json)
Returns a
LocalizedText parsed from the given multi-locale JSON representation. |
Locale |
getLocale()
Get
getLocaleId() as Locale (best-effort conversion).If this
LocalizedText was values for more than one locale, this will return the invariant
locale, if a value is set for it. |
String |
getLocaleId()
Get the LocaleId part of this
LocalizedText. |
String |
getText()
Returns the Text part of this
LocalizedText. |
String |
getText(List<Locale> locales)
Returns the Text part that matches the first locale in the given list.
|
String |
getText(Locale locale)
Returns the Text part that matches the given locale.
|
Map<String,String> |
getTexts()
Returns all translations.
|
int |
hashCode() |
boolean |
hasText(Locale locale)
Returns true if there is an exact match for the given locale.
|
boolean |
hasText(String localeId)
Returns true if there is an exact match for the given locale.
|
static LocalizedText |
merge(LocalizedText existingTexts,
LocalizedText newTexts)
Merges the given newTexts to the given existingTexts.
|
LocalizedText.Builder |
toBuilder()
Returns a new
LocalizedText.Builder initialized with data from getTexts(). |
static Locale |
toLocale(String localeId)
Convert UA LocateId to
Locale. |
static String |
toLocaleId(Locale locale)
Convert
Locale to UA LocaleId String. |
String |
toString() |
public static final String MUL_LOCALE_ID
public static final Pattern LOCALE_PATTERN
public static final Locale NO_LOCALE
Locale. This is same as Locale.ROOT.@Deprecated public static final Locale NULL_LOCALE
NO_LOCALE instead.NO_LOCALE.public static final LocalizedText[] EMPTY_ARRAY
@Deprecated public static final NodeId ID
Identifiers.LocalizedText instead.public static final LocalizedText EMPTY
@Deprecated public static final LocalizedText NULL
EMPTY instead.EMPTY.public static final LocalizedText EMPTY_EN
public LocalizedText(String text)
text - the textpublic LocalizedText(String text, Locale locale)
text - or nulllocale - locale or nullpublic static LocalizedText.Builder builder()
LocalizedText. This can be used to set multi-locale values.public static LocalizedText english(String text)
text - stringpublic static LocalizedText from(String text)
LocalizedText with a single text for the "invariant locale"
(NO_LOCALE).public static LocalizedText from(String text, Locale locale)
LocalizedText with a single text for the given locale.public static LocalizedText from(String text, String localeId)
LocalizedText with a single text for the given locale.public static LocalizedText fromMultiLocaleJson(String json) throws DecodingException
LocalizedText parsed from the given multi-locale JSON representation.json - JSON StringDecodingException - if decoding the JSON String fails or the parsed String[][] has
incorrect array lengthspublic static LocalizedText merge(LocalizedText existingTexts, LocalizedText newTexts)
LocalizedText
contains mappings from both similar to how Map.putAll(Map) works.
Empty locale and text parts are handled as-if they would have been written OPC UA Specification (v. 1.05) Part 4 section 5.10.4 Write rules. If empty locale has been set to empty text, all entries are removed. If not, removes every entry where text is empty String.
If the existingTexts contains any "empty" values per above rules, these removals are handled before the newTexts are merged and then the rules are applied again.
public static Locale toLocale(String localeId)
Locale. Returns Locale.ROOT if given null. Returns
Locale.ROOT for empty string.public static String toLocaleId(Locale locale)
Locale to UA LocaleId String. Returns an empty String if given null.public LocalizedText asSingleLocale(List<Locale> localePreferences)
LocalizedText that only contains a single localized value, based on the given
locale preferences.
Namely, this works based on https://reference.opcfoundation.org/Core/Part4/v105/docs/5.6.3 ; if
there is a direct match, that is used (the first match from the given array). If there are no
direct matches, the language components are ignored and first match from the array is returned
(but the locale is still the original i.e. if this has 'en-US' and 'en-GB' is requested, the
returned LocalizedText has 'en-US' as the locale). If no matches are found, the default
texts (getText() and locale getLocale()) are
returned.
public LocalizedText asSingleLocale(Locale localePreferences)
LocalizedText that only contains a single localized value, based on the given
locale preferences. See asSingleLocale(List).public Locale getLocale()
getLocaleId() as Locale (best-effort conversion).If this
LocalizedText was values for more than one locale, this will return the invariant
locale, if a value is set for it. Otherwise it returns the first value (locale part) set via
the LocalizedText.Builder.setTexts(LocalizedText).public String getLocaleId()
LocalizedText. If this LocalizedText has values
for more than one locale, this will return the invariant locale, if a value is set for it.
Otherwise it returns the first value (locale part) set via the
LocalizedText.Builder.setTexts(LocalizedText).public String getText()
LocalizedText. If this LocalizedText has values
for more than one locale, returns text matching getLocaleId().public String getText(List<Locale> locales)
getText().public String getText(Locale locale)
getText().public Map<String,String> getTexts()
public boolean hasText(Locale locale)
public boolean hasText(String localeId)
public LocalizedText.Builder toBuilder()
LocalizedText.Builder initialized with data from getTexts().Copyright © 2026. All rights reserved.