java.lang.Object
org.tentackle.common.I18NText
- All Implemented Interfaces:
Serializable,CharSequence,Comparable<I18NText>
Multilingual text.
This is an immutable and serializable object which is supported as a regular datatype via
This is an immutable and serializable object which is supported as a regular datatype via
org.tentackle.sql.datatypes.I18NTextType.
Model example:
... I18NText description description internationalized description [COLS=30] ...
Don't forget to add the [COLS=...] option if yoy want to use auto-binding for the field width in FX views.
Please keep in mind, that I18NText implements
CharSequence and Comparable only for the current locale (see LocaleProvider.getInstance().getLocale()),
but Object.equals(Object) and Object.hashCode() cover all translations.
As a consequence, sorted sets of I18NText elements require appropriate attention.
- See Also:
-
Constructor Summary
ConstructorsModifierConstructorDescriptionI18NText()Creates a vacantI18NText.Creates anI18NTextfrom a string in the current locale.protectedI18NText(LinkedHashMap<Locale, String> textMap, Locale defaultLocale) Protected constructor for internal use only.Creates anI18NTextfrom a string for the given locale.I18NText(ParameterString parameterString) Creates anI18NTextfrom a parameter string. -
Method Summary
Modifier and TypeMethodDescriptionprotected Localeapply(Locale locale, String text, LinkedHashMap<Locale, String> withTextMap, Locale withDefaultLocale) Applies a translation to an existing map and default locale.charcharAt(int index) chars()intbooleanget()Gets the translation for the current locale.Gets the translation for the given locale.Gets the current default locale.Gets the mapping between locales and translations.inthashCode()booleanisEmpty()booleanisVacant()Returns whether there are valid translations at all.intlength()protected LocalenarrowLocale(Locale locale) Narrows the effective locale returned by theLocaleProviderfurther to language.
The LocaleProvider may allow wider locales for ResourceBundles, but for I18NText this would complicate things way too much.
In most applications, the LocaleProvider narrows to language anyway.subSequence(int start, int end) Creates a parameter string of the current translations.toString()static I18NTextCreates anI18NTextfrom a string in the current locale.Derives an I18NText object with a translation for the current locale.Derives an I18NText object with a translation for the given locale.
-
Constructor Details
-
I18NText
public I18NText()Creates a vacantI18NText. -
I18NText
Creates anI18NTextfrom a string in the current locale.- Parameters:
text- the string
-
I18NText
Creates anI18NTextfrom a string for the given locale.- Parameters:
locale- the localetext- the string
-
I18NText
Creates anI18NTextfrom a parameter string.- Parameters:
parameterString- the parameter string- See Also:
-
I18NText
Protected constructor for internal use only.- Parameters:
textMap- the translationsdefaultLocale- the default locale
-
-
Method Details
-
valueOf
Creates anI18NTextfrom a string in the current locale.- Parameters:
text- the string- Returns:
- the i18n object
-
with
Derives an I18NText object with a translation for the given locale.- Parameters:
locale- the localetext- the string- Returns:
- the old translation, null if new
-
with
Derives an I18NText object with a translation for the current locale.- Parameters:
text- the string- Returns:
- the old translation, null if new
-
get
Gets the translation for the given locale.- Parameters:
locale- the locale- Returns:
- the string, null if no translations at all
-
get
Gets the translation for the current locale.- Returns:
- the string, null if no translations at all
-
getDefaultLocale
Gets the current default locale.- Returns:
- the default locale, null if no translations at all or the translation for the fallback locale is set
-
getTranslations
Gets the mapping between locales and translations.- Returns:
- the unmodifiable map of translations
-
toParameterString
Creates a parameter string of the current translations.- Returns:
- the parameter string
-
isVacant
public boolean isVacant()Returns whether there are valid translations at all.- Returns:
- true if the map of translations is empty
-
length
public int length()- Specified by:
lengthin interfaceCharSequence
-
isEmpty
public boolean isEmpty()- Specified by:
isEmptyin interfaceCharSequence
-
charAt
public char charAt(int index) - Specified by:
charAtin interfaceCharSequence
-
subSequence
- Specified by:
subSequencein interfaceCharSequence
-
chars
- Specified by:
charsin interfaceCharSequence
-
codePoints
- Specified by:
codePointsin interfaceCharSequence
-
compareTo
- Specified by:
compareToin interfaceComparable<I18NText>
-
toString
- Specified by:
toStringin interfaceCharSequence- Overrides:
toStringin classObject
-
equals
-
hashCode
public int hashCode() -
apply
protected Locale apply(Locale locale, String text, LinkedHashMap<Locale, String> withTextMap, Locale withDefaultLocale) Applies a translation to an existing map and default locale.- Parameters:
locale- the locale to applytext- the translation to applywithTextMap- the current translationswithDefaultLocale- the current default locale- Returns:
- the new default locale
-
narrowLocale
Narrows the effective locale returned by theLocaleProviderfurther to language.
The LocaleProvider may allow wider locales for ResourceBundles, but for I18NText this would complicate things way too much.
In most applications, the LocaleProvider narrows to language anyway.- Parameters:
locale- the effective locale- Returns:
- the language-only locale
-