Class LocaleHelper


  • public class LocaleHelper
    extends java.lang.Object
    An helper to extract localization data from a Jar.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.Locale _locale  
      private java.util.Map<java.lang.String,​java.util.Map<java.lang.String,​java.lang.String>> _localizations  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private LocaleHelper()  
      private LocaleHelper​(Jar jar, java.util.Locale locale, java.lang.String basePath)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private java.util.Locale computeNextLocale​(java.util.Locale nextLocale)  
      static LocaleHelper createIfPresent​(Jar jar, java.util.Locale locale, java.lang.String basePath)
      Create a LocaleHelper if localization data are found at the specified path, otherwise return null.
      static LocaleHelper empty()  
      private java.util.Map<java.lang.String,​java.util.Map<java.lang.String,​java.lang.String>> extractLocalizations​(Jar jar, java.lang.String path)  
      java.lang.String get​(java.lang.String variableOrValue)
      If the argument is a variable, its corresponding value will be returned for the default locale of this helper instance.
      java.lang.String get​(java.lang.String variableOrValue, java.util.Locale locale)
      If the argument is a variable, its corresponding value will be returned for the specified locale.
      private static boolean hasLocalization​(Jar jar, java.lang.String path)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • _locale

        private final java.util.Locale _locale
      • _localizations

        private final java.util.Map<java.lang.String,​java.util.Map<java.lang.String,​java.lang.String>> _localizations
    • Constructor Detail

      • LocaleHelper

        private LocaleHelper​(Jar jar,
                             java.util.Locale locale,
                             java.lang.String basePath)
      • LocaleHelper

        private LocaleHelper()
    • Method Detail

      • createIfPresent

        public static LocaleHelper createIfPresent​(Jar jar,
                                                   java.util.Locale locale,
                                                   java.lang.String basePath)
        Create a LocaleHelper if localization data are found at the specified path, otherwise return null.
        Parameters:
        jar - the jar containing the localization file, must not be null
        locale - the default locale for this helper, must not be null
        basePath - a base path in the Jar to the localization property files without its extension and its locale suffix, must not be null
        Returns:
        a LocaleHelper which contains localization data or null if there is no localization data at the specified path.
      • empty

        public static LocaleHelper empty()
        Returns:
        a LocaleHelper without localization data, never null
      • get

        public java.lang.String get​(java.lang.String variableOrValue)
        If the argument is a variable, its corresponding value will be returned for the default locale of this helper instance. Otherwise, the argument is returned.

        Values will be search from the most specific to the less specific locale including unlocalized (empty locale) value.

        Parameters:
        variableOrValue - a variable (starting with '%') or a value, can be null
        Returns:
        the localized value, can be null
      • get

        public java.lang.String get​(java.lang.String variableOrValue,
                                    java.util.Locale locale)
        If the argument is a variable, its corresponding value will be returned for the specified locale. Otherwise, the argument is returned.

        Values will be search from the most specific to the less specific locale including unlocalized (empty locale) value.

        Parameters:
        variableOrValue - a variable (starting with '%') or a value, can be null
        locale - the locale, must not be null
        Returns:
        the localized value, can be null
      • computeNextLocale

        private java.util.Locale computeNextLocale​(java.util.Locale nextLocale)
      • hasLocalization

        private static boolean hasLocalization​(Jar jar,
                                               java.lang.String path)
      • extractLocalizations

        private java.util.Map<java.lang.String,​java.util.Map<java.lang.String,​java.lang.String>> extractLocalizations​(Jar jar,
                                                                                                                                  java.lang.String path)