Package com.priint.pubserver.lang
Class NameTranslations
java.lang.Object
com.priint.pubserver.lang.NameTranslations
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionasMap()Returns the whole immutable map of language-translation pairs this object holds.getTranslationForLanguage(Language language) Gets a translation for a given language or theLanguage.DEFAULTtranslation if the requested one is not available.getTranslationForLanguage(String language) Gets a translation for a given language or theLanguage.DEFAULTtranslation if the requested one is not available.static NameTranslationsReturns a NameTranslations containing a single language-to-translation entry.static NameTranslationsReturns a NameTranslations containing two language-to-translation entries.static NameTranslationsof(Language lang1, String translation1, Language lang2, String translation2, Language lang3, String translation3) Returns a NameTranslations containing three language-to-translation entries.static NameTranslationsof(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.toString()
-
Constructor Details
-
NameTranslations
- Parameters:
translations- a language-to-name map containing all desired translations. Needs to contain an entry for theLanguage.DEFAULT. Nonulls are allowed.
-
-
Method Details
-
of
Returns a NameTranslations containing a single language-to-translation entry. Nonulls are allowed.- Parameters:
lang- theLanguage.DEFAULTvalue objecttranslation- 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 theLanguage.DEFAULTlanguage. Nonulls are allowed.- Parameters:
lang1- the first entry languagetranslation1- the first entry string translationlang2- the second entry languagetranslation2- 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 theLanguage.DEFAULTlanguage. Nonulls are allowed.- Parameters:
lang1- the first entry languagetranslation1- the first entry string translationlang2- the second entry languagetranslation2- the second entry string translationlang3- the third entry languagetranslation3- 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 theLanguage.DEFAULTlanguage. Nonulls are allowed.- Parameters:
lang1- the first entry languagetranslation1- the first entry string translationlang2- the second entry languagetranslation2- the second entry string translationlang3- the third entry languagetranslation3- the third entry string translationlang4- the fourth entry languagetranslation4- the fourth entry string translation- Returns:
- a NameTranslations containing the listed language-to-translation entries
-
getTranslationForLanguage
Gets a translation for a given language or theLanguage.DEFAULTtranslation 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
Gets a translation for a given language or theLanguage.DEFAULTtranslation if the requested one is not available.- Parameters:
language- a translation language to look for, expecting a two lower case letterLanguagecompatible code.- Returns:
- a translation for a selected language or a default translation if the requested one is not available.
-
asMap
Returns the whole immutable map of language-translation pairs this object holds.- Returns:
- all translations in a form of an immutable map
-
toString
-