Package velox.gui.utils.localization
Class LocalizationUtils
java.lang.Object
velox.gui.utils.localization.LocalizationUtils
Some util method for trivial localization tasks
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Stringformat(double number) static Stringformat(double number, int precision) static Stringformat(double number, com.ibm.icu.util.Currency currency) static Stringformat(long number) static com.ibm.icu.text.Collatorstatic com.ibm.icu.util.Currencystatic com.ibm.icu.util.CurrencygetCurrency(String theIsoCode) Returns a currency object given an ISO 4217 3-letter code.static com.ibm.icu.text.DateFormatgetDateFormatForSceleton(String skeleton) static com.ibm.icu.text.NumberFormatReturn NumberFormat that was used by default before Bookmap localizationstatic com.ibm.icu.number.LocalizedNumberFormatterstatic com.ibm.icu.text.MessageFormatgetMessageFormat(String pattern) static com.ibm.icu.text.NumberFormatstatic com.ibm.icu.text.NumberFormatgetNumberFormat(NumberFormatStyle numberFormat) NumberFormat with current Bookmap localization.static com.ibm.icu.number.LocalizedNumberFormatterstatic <E extends TranslatableComponent>
ListCellRenderer<E> localizeListCellRenderer(ListCellRenderer<? super E> renderer) Wraps supplied renderer.static <E> ListCellRenderer<E> localizeListCellRenderer(ListCellRenderer<? super E> renderer, Function<E, String> localizedStringSupplier) Wraps supplied renderer.A replacement forMap.of()which allows null as values, null keys are still prohibited.Simmilar tomapOf(Object...), but creates an immutable map of the specified map.static doubleparseDouble(String text) Locale specific parse of text that represent double numberstatic intparseInteger(String text) Locale specific parse of text that represent integer numberstatic doubleLocale specific parse of text that represent long numberstatic NumberparseNumber(String text) Locale specific parse of text that represent numbersortAlphabetically(List<String> strings) Sort alphabetically list of string
-
Field Details
-
FULL_DATE_SKELETON
Represents date in full format, e.g. "Sun, Feb 4, 2024, 20:39:15 GMT+2" (for English locale)- See Also:
-
-
Constructor Details
-
LocalizationUtils
public LocalizationUtils()
-
-
Method Details
-
getCollator
public static com.ibm.icu.text.Collator getCollator()- Returns:
- Collator with current Bookmap locale that used for locale sensitive string comparison
-
sortAlphabetically
Sort alphabetically list of string- Parameters:
strings- list to sort (will not be changed)- Returns:
- sorted list
-
getMessageFormat
- Parameters:
pattern-- Returns:
- MessageFormat with current Bookmap locale
-
getCurrency
public static com.ibm.icu.util.Currency getCurrency()- Returns:
- default currency object for current Bookmap locale
-
getCurrency
Returns a currency object given an ISO 4217 3-letter code.- Parameters:
theIsoCode-- Returns:
-
getDefaultNumberFormat
public static com.ibm.icu.text.NumberFormat getDefaultNumberFormat()Return NumberFormat that was used by default before Bookmap localization -
getNumberFormat
public static com.ibm.icu.text.NumberFormat getNumberFormat()- Returns:
- NumberFormat for current Bookmap locale
-
getDateFormatForSceleton
- Parameters:
skeleton- - a skeleton string that represents a custom date-time pattern, please seeDateFormat- Returns:
- DateFormat with current Bookmap locale for given skeleton
-
getNumberFormat
NumberFormat with current Bookmap localization. If you don't need to parse numbers but need a customized number format than better useLocalizedNumberFormatterfromgetNumberFormatter()method, it has more user-friendly setup process- Parameters:
numberFormat-- Returns:
- most likely will return
DecimalFormat - See Also:
-
getNumberFormatter
public static com.ibm.icu.number.LocalizedNumberFormatter getNumberFormatter()- Returns:
- NumberFormatter for current Bookmap locale
-
getDefaultNumberFormatter
public static com.ibm.icu.number.LocalizedNumberFormatter getDefaultNumberFormatter()- Returns:
- NumberFormatter by default locale
-
format
-
format
-
format
-
format
-
parseNumber
Locale specific parse of text that represent number- Parameters:
text- to parse- Returns:
- parsed number
- Throws:
NumberFormatException- if the specified string cannot be parsed fully.
-
parseDouble
Locale specific parse of text that represent double number- Parameters:
text- to parse- Returns:
- parsed double
- Throws:
NumberFormatException- if the specified string cannot be parsed fully.
-
parseInteger
Locale specific parse of text that represent integer number- Parameters:
text- to parse- Returns:
- parsed int
- Throws:
NumberFormatException- if the beginning of the specified string cannot be parsed.
-
parseLong
Locale specific parse of text that represent long number- Parameters:
text- to parse- Returns:
- parsed long
- Throws:
NumberFormatException- if the beginning of the specified string cannot be parsed.
-
mapOf
A replacement forMap.of()which allows null as values, null keys are still prohibited.
Use this method if you unsure if passed values 100% not null.- Parameters:
input- key values pairs, pass order is similiar toMap.of(Object, Object), i.e.:mapOf(key1, value1, key2, value2, ...)- Returns:
- immutable map with respective key and values
-
mapOf
Simmilar tomapOf(Object...), but creates an immutable map of the specified map. Allows null as values, null keys are still prohibited.- Parameters:
map- the map for which an immutable map is to be returned.- Returns:
- immutable map with respective key and values
-
localizeListCellRenderer
public static <E> ListCellRenderer<E> localizeListCellRenderer(ListCellRenderer<? super E> renderer, Function<E, String> localizedStringSupplier) Wraps supplied renderer. The wrapper replaces the object to be rendered with its localized interpretation before sending it to the wrapped renderer.- Type Parameters:
E-- Parameters:
renderer- renderer to wraplocalizedStringSupplier- function that transform object to its localized string representation- Returns:
- wrapped renderer
-
localizeListCellRenderer
public static <E extends TranslatableComponent> ListCellRenderer<E> localizeListCellRenderer(ListCellRenderer<? super E> renderer) Wraps supplied renderer. The wrapper replaces the object to be rendered with its localized interpretation before sending it to the wrapped renderer.
The same aslocalizeListCellRenderer(ListCellRenderer, Function)but for the list of items implementingTranslatableComponentinstead of specifying localizedStringSupplier function.- Type Parameters:
E-- Parameters:
renderer- renderer to wrap- Returns:
- wrapped renderer
-