Class TranslatedText
java.lang.Object
de.intranda.metadata.multilanguage.MultiLanguageMetadataValue
io.goobi.viewer.model.translations.TranslatedText
- All Implemented Interfaces:
de.intranda.metadata.multilanguage.IMetadataValue
,IPolyglott
,Serializable
public class TranslatedText
extends de.intranda.metadata.multilanguage.MultiLanguageMetadataValue
implements IPolyglott, Serializable
Translations for some text for a set of locales. Text can be set and retrieved for each locale individually. There may be a "default language" text
which represent text that has not actual locale, whether it is text that has no translations or is an internal representation of the text. This
default language only exists if the text is initiated giving only a single text without locale or if it is explicitly added
- Author:
- florian
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class de.intranda.metadata.multilanguage.MultiLanguageMetadataValue
de.intranda.metadata.multilanguage.MultiLanguageMetadataValue.ValuePair
-
Field Summary
Fields inherited from class de.intranda.metadata.multilanguage.MultiLanguageMetadataValue
DEFAULT_LANGUAGE
-
Constructor Summary
ConstructorDescriptionCreate a text with the locales fromIPolyglott.getLocalesStatic()
TranslatedText
(de.intranda.metadata.multilanguage.IMetadataValue orig) Create a text using the values of the given IMetadataValue orig.TranslatedText
(de.intranda.metadata.multilanguage.IMetadataValue orig, Locale initialLocale) Create a text using the values of the given IMetadataValue orig.TranslatedText
(TranslatedText orig) Create a copy of the given Translated text "orig"TranslatedText
(TranslatedText orig, Collection<Locale> locales, Locale initialLocale) Create a text with the given locales, setting the selected locale to the given initialLocale.TranslatedText
(String text) Create a text with the default language set to the given valueTranslatedText
(Collection<Locale> locales) Create a text with the given localesTranslatedText
(Collection<Locale> locales, Locale initalLocale) Create a text with the given locales, setting the selected locale to the given initialLocale -
Method Summary
Modifier and TypeMethodDescriptionboolean
two TranslatedTexts are considered equal if the have the same locales and the same texts for each localeget the values ofIPolyglott.getLocalesStatic()
getText()
get the text for the currentselectedLocale
Get the text for the given locale.Get the text forIPolyglott.getCurrentLocale()
, or, failing that, forIPolyglott.getDefaultLocale()
, the internal default language or finally an empty stringgetTextOrDefault
(Locale locale, Locale defaultLocale) Get the text for the given language, or, failing that, for the given defaultLocale, the internal default language or finally an empty stringint
hashCode()
boolean
boolean
isComplete
(Locale locale) Alias forisValid(Locale)
boolean
isComplete
(Locale locale, Locale defaultLocale, boolean required) If required is true, true is returned if a non-empty value exists for the given locale.boolean
Only meaningfull for the default language for which all required fields must be filledvoid
setSelectedLocale
(Locale locale) Set theselectedLocale
void
set the text for the currentselectedLocale
void
Set the text for the given localetoMap()
Get the values as a map of locales and associated texts.toString()
Alias forgetText()
Methods inherited from class de.intranda.metadata.multilanguage.MultiLanguageMetadataValue
addPrefix, addSuffix, copy, getLanguages, getValue, getValue, getValues, hasTranslations, isEmpty, isEmpty, isEmpty, mapEach, removeTranslation, setValue, setValue, setValue
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface de.intranda.metadata.multilanguage.IMetadataValue
getNumberOfUniqueTranslations, getValueOrFallback
Methods inherited from interface io.goobi.viewer.model.translations.IPolyglott
isDefaultLocaleSelected, isEmpty, isSelected, setSelectedLocale
-
Constructor Details
-
TranslatedText
public TranslatedText()Create a text with the locales fromIPolyglott.getLocalesStatic()
-
TranslatedText
Create a text with the given locales- Parameters:
locales
-
-
TranslatedText
Create a text with the given locales, setting the selected locale to the given initialLocale- Parameters:
locales
-initalLocale
-
-
TranslatedText
Create a text with the given locales, setting the selected locale to the given initialLocale. Initialize the values with the onces from the given TranslatedText "orig". If a Locale contained in locales is not included in orig, its value remains blank. If a locale is contained in orig, but not in locales, the value is set anyway- Parameters:
orig
-locales
-initialLocale
-
-
TranslatedText
Create a copy of the given Translated text "orig"- Parameters:
orig
-
-
TranslatedText
Create a text with the default language set to the given value- Parameters:
text
-
-
TranslatedText
public TranslatedText(de.intranda.metadata.multilanguage.IMetadataValue orig) Create a text using the values of the given IMetadataValue orig. If orig is aSimpleMetadataValue
, its value is written to the default locale. The selected locale is set toIPolyglott.getCurrentLocale()
- Parameters:
orig
-
-
TranslatedText
Create a text using the values of the given IMetadataValue orig. If orig is aSimpleMetadataValue
, its value is written to the default locale. The selected locale is set to the given initialLocale- Parameters:
orig
-initialLocale
-
-
-
Method Details
-
getSelectedLocale
- Specified by:
getSelectedLocale
in interfaceIPolyglott
- Returns:
- the
selectedLocale
-
setSelectedLocale
Set theselectedLocale
- Specified by:
setSelectedLocale
in interfaceIPolyglott
- Parameters:
locale
-
-
getText
Get the text for the given locale. If that does not exist, get the value for the default language and if that doesn't exist, an empty string- Parameters:
locale
-- Returns:
- Text for the given locale
-
getTextOrDefault
Get the text forIPolyglott.getCurrentLocale()
, or, failing that, forIPolyglott.getDefaultLocale()
, the internal default language or finally an empty string- Returns:
String
-
getTextOrDefault
Get the text for the given language, or, failing that, for the given defaultLocale, the internal default language or finally an empty string- Parameters:
locale
- The locale to return the text fordefaultLocale
- The fallback locale to use if no text exists for the given locale- Returns:
String
-
setText
Set the text for the given locale- Parameters:
text
-locale
-
-
getText
get the text for the currentselectedLocale
- Returns:
- Text for selected locale
-
setText
set the text for the currentselectedLocale
- Parameters:
text
-
-
toMap
Get the values as a map of locales and associated texts. The default language text is never included since it does not have a locale- Returns:
- Map<Locale, String>
-
isComplete
Alias forisValid(Locale)
- Specified by:
isComplete
in interfaceIPolyglott
- Returns:
- true if
IPolyglott.isValid(Locale)
returns true for the given locale and all fields contain a value which have a value in the default locale. For the default locale,IPolyglott.isComplete(Locale)
andIPolyglott.isValid(Locale)
are identical. For implementations with only one field, both methods are also always identical
-
isValid
Description copied from interface:IPolyglott
Only meaningfull for the default language for which all required fields must be filled- Specified by:
isValid
in interfaceIPolyglott
- Returns:
- true if at least one locale has a non empty text set
-
getValue
- Specified by:
getValue
in interfacede.intranda.metadata.multilanguage.IMetadataValue
- Overrides:
getValue
in classde.intranda.metadata.multilanguage.MultiLanguageMetadataValue
- Returns:
- an optional containing the text for the given locale if one exists, or an empty optional otherwise
-
getLocales
get the values ofIPolyglott.getLocalesStatic()
- Specified by:
getLocales
in interfaceIPolyglott
- Returns:
- Collection
-
hasLocale
- Parameters:
locale
-- Returns:
- true if the given locale is in the list of locales for which a text may be set, whether or not a text exists for that locale
-
toString
Alias forgetText()
- Overrides:
toString
in classde.intranda.metadata.multilanguage.MultiLanguageMetadataValue
-
hashCode
public int hashCode()- Overrides:
hashCode
in classde.intranda.metadata.multilanguage.MultiLanguageMetadataValue
-
equals
two TranslatedTexts are considered equal if the have the same locales and the same texts for each locale- Overrides:
equals
in classde.intranda.metadata.multilanguage.MultiLanguageMetadataValue
-
isComplete
If required is true, true is returned if a non-empty value exists for the given locale. Otherwise return true unless defaultLocale has a non-empty value while locale has not.- Parameters:
locale
-defaultLocale
-required
-- Returns:
- true if completeness not required or text not empty; false otherwise
-
getAsJson
- Throws:
com.fasterxml.jackson.core.JsonProcessingException
-