Class NameTranslations

java.lang.Object
com.priint.pubserver.lang.NameTranslations

public final class NameTranslations extends Object
A helper class for bundling language-to-name maps. It assures a Language.DEFAULT translation is always provided on its initialization. It has init methods simplifying its initialization:
   private static final NameTranslations nameTranslations = NameTranslations.of(
             Language.DE, "Setze Nächste Dokument-Stage",
             Language.EN, "Set Next Document Stage"
   );
 
Finally, it encapsulates a consistent way of getting a translation in a desired language, expressed by a Language object or by a simple 2-char String representation of it. It makes sure that even if the language one provides is not supported for any reason, at the very least the default translation will be returned.
  • Constructor Details

    • NameTranslations

      public NameTranslations(Map<Language,String> translations)
      Parameters:
      translations - a language-to-name map containing all desired translations. Needs to contain an entry for the Language.DEFAULT. No nulls are allowed.
  • Method Details

    • of

      public static NameTranslations of(Language lang, String translation)
      Returns a NameTranslations containing a single language-to-translation entry. No nulls are allowed.
      Parameters:
      lang - the Language.DEFAULT value object
      translation - a string translation for that language
      Returns:
      a NameTranslations containing a single language-to-translation entry
    • of

      public static NameTranslations of(Language lang1, String translation1, Language lang2, String translation2)
      Returns a NameTranslations containing two language-to-translation entries. One of them needs to be for the Language.DEFAULT language. No nulls are allowed.
      Parameters:
      lang1 - the first entry language
      translation1 - the first entry string translation
      lang2 - the second entry language
      translation2 - the second entry string translation
      Returns:
      a NameTranslations containing the listed language-to-translation entries
    • of

      public static NameTranslations of(Language lang1, String translation1, Language lang2, String translation2, Language lang3, String translation3)
      Returns a NameTranslations containing three language-to-translation entries. One of them needs to be for the Language.DEFAULT language. No nulls are allowed.
      Parameters:
      lang1 - the first entry language
      translation1 - the first entry string translation
      lang2 - the second entry language
      translation2 - the second entry string translation
      lang3 - the third entry language
      translation3 - the third entry string translation
      Returns:
      a NameTranslations containing the listed language-to-translation entries
    • of

      public static NameTranslations of(Language lang1, String translation1, Language lang2, String translation2, Language lang3, String translation3, Language lang4, String translation4)
      Returns a NameTranslations containing four language-to-translation entries. One of them needs to be for the Language.DEFAULT language. No nulls are allowed.
      Parameters:
      lang1 - the first entry language
      translation1 - the first entry string translation
      lang2 - the second entry language
      translation2 - the second entry string translation
      lang3 - the third entry language
      translation3 - the third entry string translation
      lang4 - the fourth entry language
      translation4 - the fourth entry string translation
      Returns:
      a NameTranslations containing the listed language-to-translation entries
    • getTranslationForLanguage

      public String getTranslationForLanguage(Language language)
      Gets a translation for a given language or the Language.DEFAULT translation if the requested one is not available.
      Parameters:
      language - a translation language to look for
      Returns:
      a translation for a selected language or a default translation if the requested one is not available.
    • getTranslationForLanguage

      public String getTranslationForLanguage(String language)
      Gets a translation for a given language or the Language.DEFAULT translation if the requested one is not available.
      Parameters:
      language - a translation language to look for, expecting a two lower case letter Language compatible code.
      Returns:
      a translation for a selected language or a default translation if the requested one is not available.
    • asMap

      public Map<Language,String> asMap()
      Returns the whole immutable map of language-translation pairs this object holds.
      Returns:
      all translations in a form of an immutable map
    • toString

      public String toString()
      Overrides:
      toString in class Object