LocalizationUtils
Package: velox.gui.utils.localization
Type: Class
Inheritance: java.lang.Object → velox.gui.utils.localization.LocalizationUtils
Description​
Some util method for trivial localization tasks
Fields​
FULL_DATE_SKELETON​
public static final String FULL_DATE_SKELETON
Represents date in full format, e.g. "Sun, Feb 4, 2024, 20:39:15 GMT+2" (for English locale)
Constructors​
LocalizationUtils​
public LocalizationUtils()
Methods​
getCollator​
public static com.ibm.icu.text.Collator getCollator()
Returns: Collator with current Bookmap locale that used for locale sensitive string comparison
sortAlphabetically​
public static List<String> sortAlphabetically(List<String> strings)
Sort alphabetically list of string
Parameters:
strings- list to sort (will not be changed)
Returns: sorted list
getMessageFormat​
public static com.ibm.icu.text.MessageFormat getMessageFormat(String pattern)
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​
public static com.ibm.icu.util.Currency getCurrency(String theIsoCode)
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​
public static com.ibm.icu.text.DateFormat getDateFormatForSceleton(String skeleton)
Parameters:
skeleton- - a skeleton string that represents a custom date-time pattern, please seeDateFormat
Returns: DateFormat with current Bookmap locale for given skeleton
getNumberFormat​
public static com.ibm.icu.text.NumberFormat getNumberFormat(NumberFormatStyle numberFormat)
NumberFormat with current Bookmap localization. If you don't need to parse numbers but need a customized number format than better use LocalizedNumberFormatter from getNumberFormatter() method, it has more user-friendly setup process
Parameters:
numberFormat-
Returns: most likely will return DecimalFormat
See Also:
NumberFormatStyle
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​
public static String format(long number)
format​
public static String format(double number)
format​
public static String format(double number, int precision)
format​
public static String format(double number, com.ibm.icu.util.Currency currency)
parseNumber​
public static Number parseNumber(String text)
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​
public static double parseDouble(String text)
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​
public static int parseInteger(String text)
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​
public static double parseLong(String text)
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​
public static Map<String, Object> mapOf(Object... input)
A replacement for Map.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​
public static Map<String, Object> mapOf(Map<String, Object> map)
Simmilar to mapOf(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 as localizeListCellRenderer(ListCellRenderer, Function) but for the list of items implementing TranslatableComponent instead of specifying localizedStringSupplier function.
Type Parameters:
E-
Parameters:
renderer- renderer to wrap
Returns: wrapped renderer