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 Alpers
- 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
ConstructorsConstructorDescriptionCreate 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) Creates 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) Creates a text with the default language set to the given value.TranslatedText(Collection<Locale> locales) Creates a text with the given locales.TranslatedText(Collection<Locale> locales, Locale initalLocale) Creates a text with the given locales, setting the selected locale to the given initialLocale. -
Method Summary
Modifier and TypeMethodDescriptionbooleanTwo TranslatedTexts are considered equal if the have the same locales and the same texts for each locale.get 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 string.getTextOrDefault(Locale locale, Locale defaultLocale) Gets the text for the given language, or, failing that, for the given defaultLocale, the internal default language or finally an empty string.inthashCode()booleanbooleanisComplete(Locale locale) Alias forisValid(Locale).booleanisComplete(Locale locale, Locale defaultLocale, boolean required) If required is true, true is returned if a non-empty value exists for the given locale.booleanOnly meaningful for the default language for which all required fields must be filled.voidsetSelectedLocale(Locale locale) Set theselectedLocale.voidset the text for the currentselectedLocale.voidSets the text for the given locale.toMap()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, transformValuesMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface de.intranda.metadata.multilanguage.IMetadataValue
getNumberOfUniqueTranslations, getValueOrFallbackMethods 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
Creates a text with the given locales.- Parameters:
locales- collection of locales to initialize the text with
-
TranslatedText
Creates a text with the given locales, setting the selected locale to the given initialLocale.- Parameters:
locales- collection of locales to initialize the text withinitalLocale- locale to select as the active locale
-
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- source translated text to copy values fromlocales- collection of locales to initialize the text withinitialLocale- locale to select as the active locale
-
TranslatedText
Creates a copy of the given Translated text "orig".- Parameters:
orig- source translated text to copy
-
TranslatedText
Creates a text with the default language set to the given value.- Parameters:
text- initial text value for the default language
-
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- source metadata value to copy translations from
-
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- source metadata value to copy translations frominitialLocale- locale to select as the active locale
-
-
Method Details
-
getSelectedLocale
- Specified by:
getSelectedLocalein interfaceIPolyglott- Returns:
- the
selectedLocale
-
setSelectedLocale
Set theselectedLocale.- Specified by:
setSelectedLocalein interfaceIPolyglott- Parameters:
locale- locale to set as the selected 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- locale for which to retrieve the text- 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
Gets 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
Sets the text for the given locale.- Parameters:
text- text value to setlocale- locale for which to set the text
-
getText
get the text for the currentselectedLocale.- Returns:
- Text for selected locale
-
setText
set the text for the currentselectedLocale.- Parameters:
text- text value to set for the selected locale
-
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:
isCompletein interfaceIPolyglott- Parameters:
locale- the locale to check for completeness- Returns:
- true if a non-empty text is set for the given locale; false otherwise
-
isValid
Description copied from interface:IPolyglottOnly meaningful for the default language for which all required fields must be filled.- Specified by:
isValidin interfaceIPolyglott- Parameters:
locale- the locale to check for a non-empty value- Returns:
- true if at least one locale has a non empty text set
-
getValue
- Specified by:
getValuein interfacede.intranda.metadata.multilanguage.IMetadataValue- Overrides:
getValuein classde.intranda.metadata.multilanguage.MultiLanguageMetadataValue- Parameters:
locale- the locale for which to retrieve the text value- 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:
getLocalesin interfaceIPolyglott- Returns:
- the collection of locales for which a text value may be set
-
hasLocale
- Parameters:
locale- locale to check for presence in the supported locale list- 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:
toStringin classde.intranda.metadata.multilanguage.MultiLanguageMetadataValue- Returns:
- a string representation of this object
-
hashCode
public int hashCode()- Overrides:
hashCodein 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:
equalsin classde.intranda.metadata.multilanguage.MultiLanguageMetadataValue- Parameters:
obj- the object to compare to this translated text- Returns:
- true if the given object is equal to this instance, false otherwise
-
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- locale to check for completenessdefaultLocale- fallback locale used to determine if a value existsrequired- whether a non-empty value for the given locale is strictly required- Returns:
- true if completeness not required or text not empty; false otherwise
-
getAsJson
- Throws:
com.fasterxml.jackson.core.JsonProcessingException
-