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:
  • Constructor Details

    • TranslatedText

      public TranslatedText()
      Create a text with the locales from IPolyglott.getLocalesStatic()
    • TranslatedText

      public TranslatedText(Collection<Locale> locales)
      Create a text with the given locales
      Parameters:
      locales -
    • TranslatedText

      public TranslatedText(Collection<Locale> locales, Locale initalLocale)
      Create a text with the given locales, setting the selected locale to the given initialLocale
      Parameters:
      locales -
      initalLocale -
    • TranslatedText

      public TranslatedText(TranslatedText orig, Collection<Locale> locales, Locale initialLocale)
      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

      public TranslatedText(TranslatedText orig)
      Create a copy of the given Translated text "orig"
      Parameters:
      orig -
    • TranslatedText

      public TranslatedText(String text)
      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 a SimpleMetadataValue, its value is written to the default locale. The selected locale is set to IPolyglott.getCurrentLocale()
      Parameters:
      orig -
    • TranslatedText

      public TranslatedText(de.intranda.metadata.multilanguage.IMetadataValue orig, Locale initialLocale)
      Create a text using the values of the given IMetadataValue orig. If orig is a SimpleMetadataValue, its value is written to the default locale. The selected locale is set to the given initialLocale
      Parameters:
      orig -
      initialLocale -
  • Method Details

    • getSelectedLocale

      public Locale getSelectedLocale()
      Specified by:
      getSelectedLocale in interface IPolyglott
      Returns:
      the selectedLocale
    • setSelectedLocale

      public void setSelectedLocale(Locale locale)
      Set the selectedLocale
      Specified by:
      setSelectedLocale in interface IPolyglott
      Parameters:
      locale -
    • getText

      public String getText(Locale locale)
      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

      public String getTextOrDefault()
      Get the text for IPolyglott.getCurrentLocale(), or, failing that, for IPolyglott.getDefaultLocale(), the internal default language or finally an empty string
      Returns:
      String
    • getTextOrDefault

      public String getTextOrDefault(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 string
      Parameters:
      locale - The locale to return the text for
      defaultLocale - The fallback locale to use if no text exists for the given locale
      Returns:
      String
    • setText

      public void setText(String text, Locale locale)
      Set the text for the given locale
      Parameters:
      text -
      locale -
    • getText

      public String getText()
      get the text for the current selectedLocale
      Returns:
      Text for selected locale
    • setText

      public void setText(String text)
      set the text for the current selectedLocale
      Parameters:
      text -
    • toMap

      public Map<Locale,String> 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

      public boolean isComplete(Locale locale)
      Alias for isValid(Locale)
      Specified by:
      isComplete in interface IPolyglott
      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) and IPolyglott.isValid(Locale) are identical. For implementations with only one field, both methods are also always identical
    • isValid

      public boolean isValid(Locale locale)
      Description copied from interface: IPolyglott
      Only meaningfull for the default language for which all required fields must be filled
      Specified by:
      isValid in interface IPolyglott
      Returns:
      true if at least one locale has a non empty text set
    • getValue

      public Optional<String> getValue(Locale locale)
      Specified by:
      getValue in interface de.intranda.metadata.multilanguage.IMetadataValue
      Overrides:
      getValue in class de.intranda.metadata.multilanguage.MultiLanguageMetadataValue
      Returns:
      an optional containing the text for the given locale if one exists, or an empty optional otherwise
    • getLocales

      public Collection<Locale> getLocales()
      Specified by:
      getLocales in interface IPolyglott
      Returns:
      Collection
    • hasLocale

      public boolean hasLocale(Locale locale)
      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

      public String toString()
      Alias for getText()
      Overrides:
      toString in class de.intranda.metadata.multilanguage.MultiLanguageMetadataValue
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class de.intranda.metadata.multilanguage.MultiLanguageMetadataValue
    • equals

      public boolean equals(Object obj)
      two TranslatedTexts are considered equal if the have the same locales and the same texts for each locale
      Overrides:
      equals in class de.intranda.metadata.multilanguage.MultiLanguageMetadataValue
    • isComplete

      public 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. 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

      public String getAsJson() throws com.fasterxml.jackson.core.JsonProcessingException
      Throws:
      com.fasterxml.jackson.core.JsonProcessingException