Class LanguageImpl

Object
com.liferay.portal.language.LanguageImpl
All Implemented Interfaces:
com.liferay.portal.kernel.language.Language, Serializable

public class LanguageImpl extends Object implements com.liferay.portal.kernel.language.Language, Serializable
Provides various translation related functionalities for language keys specified in portlet configurations and portal resource bundles.

You can disable translations by setting the translations.disabled property to true in portal.properties.

Depending on the context passed into these methods, the lookup might be limited to the portal's resource bundle (e.g. when only a locale is passed), or extended to include an individual portlet's resource bundle (e.g. when a request object is passed). A portlet's resource bundle overrides the portal's resources when both are present.

Author:
Brian Wing Shun Chan, Andrius Vitkauskas, Eduardo Lundgren
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
     
    format(Locale locale, String pattern, Object argument)
    Returns the translated pattern using the locale or, if the locale is not available, the server's default locale.
    format(Locale locale, String pattern, Object[] arguments)
    Returns the translated pattern using the locale or, if the locale is not available, the server's default locale.
    format(Locale locale, String pattern, Object[] arguments, boolean translateArguments)
    Returns the translated pattern using the locale or, if the locale is not available, the server's default locale.
    format(Locale locale, String pattern, Object argument, boolean translateArguments)
    Returns the translated pattern using the locale or, if the locale is not available, the server's default locale.
    format(Locale locale, String pattern, List<Object> arguments)
    Returns the translated pattern using the locale or, if the locale is not available, the server's default locale.
    format(ResourceBundle resourceBundle, String pattern, Object argument)
    Returns the translated pattern in the resource bundle or, if the resource bundle is not available, the untranslated key.
    format(ResourceBundle resourceBundle, String pattern, Object[] arguments)
    Returns the translated pattern in the resource bundle or, if the resource bundle is not available, the untranslated key.
    format(ResourceBundle resourceBundle, String pattern, Object[] arguments, boolean translateArguments)
    Returns the translated pattern in the resource bundle or, if the resource bundle is not available, the untranslated key.
    format(ResourceBundle resourceBundle, String pattern, Object argument, boolean translateArguments)
    Returns the translated pattern in the resource bundle or, if the resource bundle is not available, the untranslated key.
    format(javax.servlet.http.HttpServletRequest httpServletRequest, String pattern, com.liferay.portal.kernel.language.LanguageWrapper argument)
    Returns the translated pattern using the current request's locale or, if the current request locale is not available, the server's default locale.
    format(javax.servlet.http.HttpServletRequest httpServletRequest, String pattern, com.liferay.portal.kernel.language.LanguageWrapper[] arguments)
    Returns the translated pattern using the current request's locale or, if the current request locale is not available, the server's default locale.
    format(javax.servlet.http.HttpServletRequest httpServletRequest, String pattern, com.liferay.portal.kernel.language.LanguageWrapper[] arguments, boolean translateArguments)
    Returns the translated pattern using the current request's locale or, if the current request locale is not available, the server's default locale.
    format(javax.servlet.http.HttpServletRequest httpServletRequest, String pattern, com.liferay.portal.kernel.language.LanguageWrapper argument, boolean translateArguments)
    Returns the translated pattern using the current request's locale or, if the current request locale is not available, the server's default locale.
    format(javax.servlet.http.HttpServletRequest httpServletRequest, String pattern, Object argument)
    Returns the translated pattern using the current request's locale or, if the current request locale is not available, the server's default locale.
    format(javax.servlet.http.HttpServletRequest httpServletRequest, String pattern, Object[] arguments)
    Returns the translated pattern using the current request's locale or, if the current request locale is not available, the server's default locale.
    format(javax.servlet.http.HttpServletRequest httpServletRequest, String pattern, Object[] arguments, boolean translateArguments)
    Returns the translated pattern using the current request's locale or, if the current request locale is not available, the server's default locale.
    format(javax.servlet.http.HttpServletRequest httpServletRequest, String pattern, Object argument, boolean translateArguments)
    Returns the translated pattern using the current request's locale or, if the current request locale is not available, the server's default locale.
    formatStorageSize(double size, Locale locale)
    Returns the translated and formatted storage size
    get(Locale locale, String key)
    Returns the key's translation from the portal's resource bundle.
    get(Locale locale, String key, String defaultValue)
    Returns the key's translation from the portal's resource bundle.
    get(ResourceBundle resourceBundle, String key)
    Returns the key's translation from the resource bundle.
    get(ResourceBundle resourceBundle, String key, String defaultValue)
    Returns the key's translation from the resource bundle.
    get(javax.servlet.http.HttpServletRequest httpServletRequest, String key)
     
    get(javax.servlet.http.HttpServletRequest httpServletRequest, String key, String defaultValue)
    Returns the key's translation from the portlet configuration, or from the portal's resource bundle if the portlet configuration is unavailable.
    get(javax.servlet.http.HttpServletRequest httpServletRequest, ResourceBundle resourceBundle, String key)
    Returns the key's translation from the portlet configuration, or from the portal's resource bundle if the portlet configuration is unavailable.
    get(javax.servlet.http.HttpServletRequest httpServletRequest, ResourceBundle resourceBundle, String key, String defaultValue)
     
    Returns the locales configured for the portal.
    getAvailableLocales(long groupId)
     
     
     
     
    getBCP47LanguageId(javax.servlet.http.HttpServletRequest httpServletRequest)
     
     
    Returns the language ID from the locale.
    getLanguageId(PortletRequest portletRequest)
    Returns the language ID that the PortletRequest is served with.
    getLanguageId(javax.servlet.http.HttpServletRequest httpServletRequest)
    Returns the language ID that the request is served with.
    long
    Returns the last time (in milliseconds) there was a change in the language's list, company, or group.
    getLocale(long groupId, String languageCode)
     
    getLocale(String languageCode)
    Returns the locale associated with the language code.
    com.liferay.portal.kernel.resource.bundle.ResourceBundleLoader
     
     
    getTimeDescription(Locale locale, long milliseconds)
    Returns an exact localized description of the time interval (in milliseconds) in the largest unit possible.
    getTimeDescription(Locale locale, long milliseconds, boolean approximate)
    Returns an approximate or exact localized description of the time interval (in milliseconds) in the largest unit possible.
    getTimeDescription(Locale locale, Long milliseconds)
    Returns an exact localized description of the time interval (in milliseconds) in the largest unit possible.
    getTimeDescription(javax.servlet.http.HttpServletRequest httpServletRequest, long milliseconds)
    Returns an exact localized description of the time interval (in milliseconds) in the largest unit possible.
    getTimeDescription(javax.servlet.http.HttpServletRequest httpServletRequest, long milliseconds, boolean approximate)
    Returns an approximate or exact localized description of the time interval (in milliseconds) in the largest unit possible.
    getTimeDescription(javax.servlet.http.HttpServletRequest httpServletRequest, Long milliseconds)
    Returns an exact localized description of the time interval (in milliseconds) in the largest unit possible.
    void
     
    boolean
    Returns true if the language code is configured to be available.
    boolean
    isAvailableLocale(long groupId, String languageId)
    Returns true if the language ID is configured to be available in the group.
    boolean
    isAvailableLocale(long groupId, Locale locale)
    Returns true if the locale is configured to be available in the group.
    boolean
    Returns true if the language ID is configured to be available.
    boolean
    Returns true if the locale is configured to be available.
    boolean
    Returns true if the locale is configured to be a beta language.
    boolean
     
    boolean
    isInheritLocales(long groupId)
     
    boolean
    isSameLanguage(Locale locale1, Locale locale2)
     
    process(Supplier<ResourceBundle> resourceBundleSupplier, Locale locale, String content)
     
    void
     
    void
    resetAvailableLocales(long companyId)
     
    void
    updateCookie(javax.servlet.http.HttpServletRequest httpServletRequest, javax.servlet.http.HttpServletResponse httpServletResponse, Locale locale)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • LanguageImpl

      public LanguageImpl()
  • Method Details

    • afterPropertiesSet

      public void afterPropertiesSet()
    • format

      public String format(javax.servlet.http.HttpServletRequest httpServletRequest, String pattern, com.liferay.portal.kernel.language.LanguageWrapper argument)
      Returns the translated pattern using the current request's locale or, if the current request locale is not available, the server's default locale.

      The lookup is done on the portlet configuration first, and if it's not found, it is done on the portal's resource bundle. If a translation for a given key does not exist, this method returns the requested key as the translation.

      The substitute placeholder (e.g. {0}) is replaced with the argument, following the standard Java ResourceBundle notion of index based substitution.

      Specified by:
      format in interface com.liferay.portal.kernel.language.Language
      Parameters:
      httpServletRequest - the request used to determine the current locale
      pattern - the key to look up in the current locale's resource file. The key follows the standard Java resource specification.
      argument - the single argument to be substituted into the pattern and translated, if possible
      Returns:
      the translated pattern, with the argument substituted in for the pattern's placeholder
    • format

      public String format(javax.servlet.http.HttpServletRequest httpServletRequest, String pattern, com.liferay.portal.kernel.language.LanguageWrapper argument, boolean translateArguments)
      Returns the translated pattern using the current request's locale or, if the current request locale is not available, the server's default locale.

      The lookup is done on the portlet configuration first, and if it's not found, it is done on the portal's resource bundle. If a translation for a given key does not exist, this method returns the requested key as the translation.

      The substitute placeholder (e.g. {0}) is replaced with the argument, following the standard Java ResourceBundle notion of index based substitution.

      Specified by:
      format in interface com.liferay.portal.kernel.language.Language
      Parameters:
      httpServletRequest - the request used to determine the current locale
      pattern - the key to look up in the current locale's resource file. The key follows the standard Java resource specification.
      argument - the single argument to be substituted into the pattern and translated, if possible
      translateArguments - whether the argument is translated
      Returns:
      the translated pattern, with the argument substituted in for the pattern's placeholder
    • format

      public String format(javax.servlet.http.HttpServletRequest httpServletRequest, String pattern, com.liferay.portal.kernel.language.LanguageWrapper[] arguments)
      Returns the translated pattern using the current request's locale or, if the current request locale is not available, the server's default locale.

      The lookup is done on the portlet configuration first, and if it's not found, it is done on the portal's resource bundle. If a translation for a given key does not exist, this method returns the requested key as the translation.

      The substitute placeholders (e.g. {0}, {1}, {2}, etc.) are replaced with the arguments, following the standard Java ResourceBundle notion of index based substitution.

      Specified by:
      format in interface com.liferay.portal.kernel.language.Language
      Parameters:
      httpServletRequest - the request used to determine the current locale
      pattern - the key to look up in the current locale's resource file. The key follows the standard Java resource specification.
      arguments - the arguments to be substituted into the pattern and translated, if possible
      Returns:
      the translated pattern, with the arguments substituted in for the pattern's placeholders
    • format

      public String format(javax.servlet.http.HttpServletRequest httpServletRequest, String pattern, com.liferay.portal.kernel.language.LanguageWrapper[] arguments, boolean translateArguments)
      Returns the translated pattern using the current request's locale or, if the current request locale is not available, the server's default locale.

      The lookup is done on the portlet configuration first, and if it's not found, it is done on the portal's resource bundle. If a translation for a given key does not exist, this method returns the requested key as the translation.

      The substitute placeholders (e.g. {0}, {1}, {2}, etc.) are replaced with the arguments, following the standard Java ResourceBundle notion of index based substitution.

      Specified by:
      format in interface com.liferay.portal.kernel.language.Language
      Parameters:
      httpServletRequest - the request used to determine the current locale
      pattern - the key to look up in the current locale's resource file. The key follows the standard Java resource specification.
      arguments - the arguments to be substituted into the pattern
      translateArguments - whether the arguments are translated
      Returns:
      the translated pattern, with the arguments substituted in for the pattern's placeholders
    • format

      public String format(javax.servlet.http.HttpServletRequest httpServletRequest, String pattern, Object argument)
      Returns the translated pattern using the current request's locale or, if the current request locale is not available, the server's default locale.

      The lookup is done on the portlet configuration first, and if it's not found, it is done on the portal's resource bundle. If a translation for a given key does not exist, this method returns the requested key as the translation.

      The substitute placeholder (e.g. {0}) is replaced with the argument, following the standard Java ResourceBundle notion of index based substitution.

      Specified by:
      format in interface com.liferay.portal.kernel.language.Language
      Parameters:
      httpServletRequest - the request used to determine the current locale
      pattern - the key to look up in the current locale's resource file. The key follows the standard Java resource specification.
      argument - the single argument to be substituted into the pattern and translated, if possible
      Returns:
      the translated pattern, with the argument substituted in for the pattern's placeholder
    • format

      public String format(javax.servlet.http.HttpServletRequest httpServletRequest, String pattern, Object argument, boolean translateArguments)
      Returns the translated pattern using the current request's locale or, if the current request locale is not available, the server's default locale.

      The lookup is done on the portlet configuration first, and if it's not found, it is done on the portal's resource bundle. If a translation for a given key does not exist, this method returns the requested key as the translation.

      The substitute placeholder (e.g. {0}) is replaced with the argument, following the standard Java ResourceBundle notion of index based substitution.

      Specified by:
      format in interface com.liferay.portal.kernel.language.Language
      Parameters:
      httpServletRequest - the request used to determine the current locale
      pattern - the key to look up in the current locale's resource file. The key follows the standard Java resource specification.
      argument - the single argument to be substituted into the pattern and translated, if possible
      translateArguments - whether the argument is translated
      Returns:
      the translated pattern, with the argument substituted in for the pattern's placeholder
    • format

      public String format(javax.servlet.http.HttpServletRequest httpServletRequest, String pattern, Object[] arguments)
      Returns the translated pattern using the current request's locale or, if the current request locale is not available, the server's default locale.

      The lookup is done on the portlet configuration first, and if it's not found, it is done on the portal's resource bundle. If a translation for a given key does not exist, this method returns the requested key as the translation.

      The substitute placeholders (e.g. {0}, {1}, {2}, etc.) are replaced with the arguments, following the standard Java ResourceBundle notion of index based substitution.

      Specified by:
      format in interface com.liferay.portal.kernel.language.Language
      Parameters:
      httpServletRequest - the request used to determine the current locale
      pattern - the key to look up in the current locale's resource file. The key follows the standard Java resource specification.
      arguments - the arguments to be substituted into the pattern and translated, if possible
      Returns:
      the translated pattern, with the arguments substituted in for the pattern's placeholders
    • format

      public String format(javax.servlet.http.HttpServletRequest httpServletRequest, String pattern, Object[] arguments, boolean translateArguments)
      Returns the translated pattern using the current request's locale or, if the current request locale is not available, the server's default locale.

      The lookup is done on the portlet configuration first, and if it's not found, it is done on the portal's resource bundle. If a translation for a given key does not exist, this method returns the requested key as the translation.

      The substitute placeholders (e.g. {0}, {1}, {2}, etc.) are replaced with the arguments, following the standard Java ResourceBundle notion of index based substitution.

      Specified by:
      format in interface com.liferay.portal.kernel.language.Language
      Parameters:
      httpServletRequest - the request used to determine the current locale
      pattern - the key to look up in the current locale's resource file. The key follows the standard Java resource specification.
      arguments - the arguments to be substituted into the pattern
      translateArguments - whether the arguments are translated
      Returns:
      the translated pattern, with the arguments substituted in for the pattern's placeholders
    • format

      public String format(Locale locale, String pattern, List<Object> arguments)
      Returns the translated pattern using the locale or, if the locale is not available, the server's default locale.

      The lookup is done on the portal's resource bundle. If a translation for a given key does not exist, this method returns the requested key as the translation.

      The substitute placeholders (e.g. {0}, {1}, {2}, etc.) are replaced with the arguments, following the standard Java ResourceBundle notion of index based substitution.

      Specified by:
      format in interface com.liferay.portal.kernel.language.Language
      Parameters:
      locale - the locale to translate to
      pattern - the key to look up in the current locale's resource file. The key follows the standard Java resource specification.
      arguments - the arguments to be substituted into the pattern
      Returns:
      the translated pattern, with the arguments substituted in for the pattern's placeholders
    • format

      public String format(Locale locale, String pattern, Object argument)
      Returns the translated pattern using the locale or, if the locale is not available, the server's default locale.

      The lookup is done on the portal's resource bundle. If a translation for a given key does not exist, this method returns the requested key as the translation.

      The substitute placeholder (e.g. {0}) is replaced with the argument, following the standard Java ResourceBundle notion of index based substitution.

      Specified by:
      format in interface com.liferay.portal.kernel.language.Language
      Parameters:
      locale - the locale to translate to
      pattern - the key to look up in the current locale's resource file. The key follows the standard Java resource specification.
      argument - the argument to be substituted into the pattern
      Returns:
      the translated pattern, with the argument substituted in for the pattern's placeholder
    • format

      public String format(Locale locale, String pattern, Object argument, boolean translateArguments)
      Returns the translated pattern using the locale or, if the locale is not available, the server's default locale.

      The lookup is done on the portal's resource bundle. If a translation for a given key does not exist, this method returns the requested key as the translation.

      The substitute placeholder (e.g. {0}) is replaced with the argument, following the standard Java ResourceBundle notion of index based substitution.

      Specified by:
      format in interface com.liferay.portal.kernel.language.Language
      Parameters:
      locale - the locale to translate to
      pattern - the key to look up in the current locale's resource file. The key follows the standard Java resource specification.
      argument - the argument to be substituted into the pattern
      translateArguments - whether the argument is translated
      Returns:
      the translated pattern, with the argument substituted in for the pattern's placeholder
    • format

      public String format(Locale locale, String pattern, Object[] arguments)
      Returns the translated pattern using the locale or, if the locale is not available, the server's default locale.

      The lookup is done on the portal's resource bundle. If a translation for a given key does not exist, this method returns the requested key as the translation.

      The substitute placeholders (e.g. {0}, {1}, {2}, etc.) are replaced with the arguments, following the standard Java ResourceBundle notion of index based substitution.

      Specified by:
      format in interface com.liferay.portal.kernel.language.Language
      Parameters:
      locale - the locale to translate to
      pattern - the key to look up in the current locale's resource file. The key follows the standard Java resource specification.
      arguments - the arguments to be substituted into the pattern
      Returns:
      the translated pattern, with the arguments substituted in for the pattern's placeholders
    • format

      public String format(Locale locale, String pattern, Object[] arguments, boolean translateArguments)
      Returns the translated pattern using the locale or, if the locale is not available, the server's default locale.

      The lookup is done on the portal's resource bundle. If a translation for a given key does not exist, this method returns the requested key as the translation.

      The substitute placeholders (e.g. {0}, {1}, {2}, etc.) are replaced with the arguments, following the standard Java ResourceBundle notion of index based substitution.

      Specified by:
      format in interface com.liferay.portal.kernel.language.Language
      Parameters:
      locale - the locale to translate to
      pattern - the key to look up in the current locale's resource file. The key follows the standard Java resource specification.
      arguments - the arguments to be substituted into the pattern
      translateArguments - whether the arguments are translated
      Returns:
      the translated pattern, with the arguments substituted in for the pattern's placeholders
    • format

      public String format(ResourceBundle resourceBundle, String pattern, Object argument)
      Returns the translated pattern in the resource bundle or, if the resource bundle is not available, the untranslated key. If a translation for a given key does not exist, this method returns the requested key as the translation.

      The substitute placeholder (e.g. {0}) is replaced with the argument, following the standard Java ResourceBundle notion of index based substitution.

      Specified by:
      format in interface com.liferay.portal.kernel.language.Language
      Parameters:
      resourceBundle - the requested key's resource bundle
      pattern - the key to look up in the resource bundle. The key follows the standard Java resource specification.
      argument - the argument to be substituted into the pattern
      Returns:
      the translated pattern, with the argument substituted in for the pattern's placeholder
    • format

      public String format(ResourceBundle resourceBundle, String pattern, Object argument, boolean translateArguments)
      Returns the translated pattern in the resource bundle or, if the resource bundle is not available, the untranslated key. If a translation for a given key does not exist, this method returns the requested key as the translation.

      The substitute placeholder (e.g. {0}) is replaced with the argument, following the standard Java ResourceBundle notion of index based substitution.

      Specified by:
      format in interface com.liferay.portal.kernel.language.Language
      Parameters:
      resourceBundle - the requested key's resource bundle
      pattern - the key to look up in the resource bundle. The key follows the standard Java resource specification.
      argument - the argument to be substituted into the pattern
      translateArguments - whether the argument is translated
      Returns:
      the translated pattern, with the argument substituted in for the pattern's placeholder
    • format

      public String format(ResourceBundle resourceBundle, String pattern, Object[] arguments)
      Returns the translated pattern in the resource bundle or, if the resource bundle is not available, the untranslated key. If a translation for a given key does not exist, this method returns the requested key as the translation.

      The substitute placeholders (e.g. {0}, {1}, {2}, etc.) are replaced with the arguments, following the standard Java ResourceBundle notion of index based substitution.

      Specified by:
      format in interface com.liferay.portal.kernel.language.Language
      Parameters:
      resourceBundle - the requested key's resource bundle
      pattern - the key to look up in the resource bundle. The key follows the standard Java resource specification.
      arguments - the arguments to be substituted into the pattern
      Returns:
      the translated pattern, with the arguments substituted in for the pattern's placeholder
    • format

      public String format(ResourceBundle resourceBundle, String pattern, Object[] arguments, boolean translateArguments)
      Returns the translated pattern in the resource bundle or, if the resource bundle is not available, the untranslated key. If a translation for a given key does not exist, this method returns the requested key as the translation.

      The substitute placeholders (e.g. {0}, {1}, {2}, etc.) are replaced with the arguments, following the standard Java ResourceBundle notion of index based substitution.

      Specified by:
      format in interface com.liferay.portal.kernel.language.Language
      Parameters:
      resourceBundle - the requested key's resource bundle
      pattern - the key to look up in the resource bundle. The key follows the standard Java resource specification.
      arguments - the arguments to be substituted into the pattern
      translateArguments - whether the arguments are translated
      Returns:
      the translated pattern, with the arguments substituted in for the pattern's placeholder
    • formatStorageSize

      public String formatStorageSize(double size, Locale locale)
      Returns the translated and formatted storage size
      Specified by:
      formatStorageSize in interface com.liferay.portal.kernel.language.Language
      Parameters:
      size - the storage size
      locale - the locale to translate to
      Returns:
      the translated storage size
    • get

      public String get(javax.servlet.http.HttpServletRequest httpServletRequest, ResourceBundle resourceBundle, String key)
      Returns the key's translation from the portlet configuration, or from the portal's resource bundle if the portlet configuration is unavailable.
      Specified by:
      get in interface com.liferay.portal.kernel.language.Language
      Parameters:
      httpServletRequest - the request used to determine the key's context and locale
      resourceBundle - the requested key's resource bundle
      key - the translation key
      Returns:
      the key's translation, or the key if the translation is unavailable
    • get

      public String get(javax.servlet.http.HttpServletRequest httpServletRequest, ResourceBundle resourceBundle, String key, String defaultValue)
      Specified by:
      get in interface com.liferay.portal.kernel.language.Language
    • get

      public String get(javax.servlet.http.HttpServletRequest httpServletRequest, String key)
      Specified by:
      get in interface com.liferay.portal.kernel.language.Language
    • get

      public String get(javax.servlet.http.HttpServletRequest httpServletRequest, String key, String defaultValue)
      Returns the key's translation from the portlet configuration, or from the portal's resource bundle if the portlet configuration is unavailable.
      Specified by:
      get in interface com.liferay.portal.kernel.language.Language
      Parameters:
      httpServletRequest - the request used to determine the key's context and locale
      key - the translation key
      defaultValue - the value to return if there is no matching translation
      Returns:
      the key's translation, or the default value if the translation is unavailable
    • get

      public String get(Locale locale, String key)
      Returns the key's translation from the portal's resource bundle.
      Specified by:
      get in interface com.liferay.portal.kernel.language.Language
      Parameters:
      locale - the key's locale
      key - the translation key
      Returns:
      the key's translation
    • get

      public String get(Locale locale, String key, String defaultValue)
      Returns the key's translation from the portal's resource bundle.
      Specified by:
      get in interface com.liferay.portal.kernel.language.Language
      Parameters:
      locale - the key's locale
      key - the translation key
      defaultValue - the value to return if there is no matching translation
      Returns:
      the key's translation, or the default value if the translation is unavailable
    • get

      public String get(ResourceBundle resourceBundle, String key)
      Returns the key's translation from the resource bundle.
      Specified by:
      get in interface com.liferay.portal.kernel.language.Language
      Parameters:
      resourceBundle - the requested key's resource bundle
      key - the translation key
      Returns:
      the key's translation
    • get

      public String get(ResourceBundle resourceBundle, String key, String defaultValue)
      Returns the key's translation from the resource bundle.
      Specified by:
      get in interface com.liferay.portal.kernel.language.Language
      Parameters:
      resourceBundle - the requested key's resource bundle
      key - the translation key
      defaultValue - the value to return if there is no matching translation
      Returns:
      the key's translation, or the default value if the translation is unavailable
    • getAvailableLocales

      public Set<Locale> getAvailableLocales()
      Returns the locales configured for the portal. Locales can be configured in portal.properties using the locales and locales.enabled keys.
      Specified by:
      getAvailableLocales in interface com.liferay.portal.kernel.language.Language
      Returns:
      the locales configured for the portal
    • getAvailableLocales

      public Set<Locale> getAvailableLocales(long groupId)
      Specified by:
      getAvailableLocales in interface com.liferay.portal.kernel.language.Language
    • getBCP47LangTag

      public String getBCP47LangTag(Locale locale)
      Specified by:
      getBCP47LangTag in interface com.liferay.portal.kernel.language.Language
    • getBCP47LanguageId

      public String getBCP47LanguageId(javax.servlet.http.HttpServletRequest httpServletRequest)
      Specified by:
      getBCP47LanguageId in interface com.liferay.portal.kernel.language.Language
    • getBCP47LanguageId

      public String getBCP47LanguageId(Locale locale)
      Specified by:
      getBCP47LanguageId in interface com.liferay.portal.kernel.language.Language
    • getBCP47LanguageId

      public String getBCP47LanguageId(PortletRequest portletRequest)
      Specified by:
      getBCP47LanguageId in interface com.liferay.portal.kernel.language.Language
    • getCompanyAvailableLocales

      public Set<Locale> getCompanyAvailableLocales(long companyId)
      Specified by:
      getCompanyAvailableLocales in interface com.liferay.portal.kernel.language.Language
    • getLanguageId

      public String getLanguageId(javax.servlet.http.HttpServletRequest httpServletRequest)
      Returns the language ID that the request is served with. The language ID is returned as a language code (e.g. en) or a specific variant (e.g. en_GB).
      Specified by:
      getLanguageId in interface com.liferay.portal.kernel.language.Language
      Parameters:
      httpServletRequest - the request used to determine the language ID
      Returns:
      the language ID that the request is served with
    • getLanguageId

      public String getLanguageId(Locale locale)
      Returns the language ID from the locale. The language ID is returned as a language code (e.g. en) or a specific variant (e.g. en_GB).
      Specified by:
      getLanguageId in interface com.liferay.portal.kernel.language.Language
      Parameters:
      locale - the locale used to determine the language ID
      Returns:
      the language ID from the locale
    • getLanguageId

      public String getLanguageId(PortletRequest portletRequest)
      Returns the language ID that the PortletRequest is served with. The language ID is returned as a language code (e.g. en) or a specific variant (e.g. en_GB).
      Specified by:
      getLanguageId in interface com.liferay.portal.kernel.language.Language
      Parameters:
      portletRequest - the portlet request used to determine the language ID
      Returns:
      the language ID that the portlet request is served with
    • getLastModified

      public long getLastModified()
      Returns the last time (in milliseconds) there was a change in the language's list, company, or group.
      Specified by:
      getLastModified in interface com.liferay.portal.kernel.language.Language
      Returns:
      the last moodified time in milliseconds
    • getLocale

      public Locale getLocale(long groupId, String languageCode)
      Specified by:
      getLocale in interface com.liferay.portal.kernel.language.Language
    • getLocale

      public Locale getLocale(String languageCode)
      Returns the locale associated with the language code.
      Specified by:
      getLocale in interface com.liferay.portal.kernel.language.Language
      Parameters:
      languageCode - the code representation of a language (e.g. en and en_GB)
      Returns:
      the locale associated with the language code
    • getResourceBundleLoader

      public com.liferay.portal.kernel.resource.bundle.ResourceBundleLoader getResourceBundleLoader()
      Specified by:
      getResourceBundleLoader in interface com.liferay.portal.kernel.language.Language
    • getSupportedLocales

      public Set<Locale> getSupportedLocales()
      Specified by:
      getSupportedLocales in interface com.liferay.portal.kernel.language.Language
    • getTimeDescription

      public String getTimeDescription(javax.servlet.http.HttpServletRequest httpServletRequest, long milliseconds)
      Returns an exact localized description of the time interval (in milliseconds) in the largest unit possible.

      For example, the following time intervals would be converted to the following time descriptions, using the English locale:

      • 1000 = 1 Second
      • 1001 = 1001 Milliseconds
      • 86400000 = 1 Day
      • 86401000 = 86401 Seconds
      Specified by:
      getTimeDescription in interface com.liferay.portal.kernel.language.Language
      Parameters:
      httpServletRequest - the request used to determine the current locale
      milliseconds - the time interval in milliseconds to describe
      Returns:
      an exact localized description of the time interval in the largest unit possible
    • getTimeDescription

      public String getTimeDescription(javax.servlet.http.HttpServletRequest httpServletRequest, long milliseconds, boolean approximate)
      Returns an approximate or exact localized description of the time interval (in milliseconds) in the largest unit possible.

      Approximate descriptions round the time to the largest possible unit and ignores the rest. For example, using the English locale:

      • Any time interval 1000-1999 = 1 Second
      • Any time interval 86400000-172799999 = 1 Day

      Otherwise, exact descriptions would follow a similar conversion pattern as below:

      • 1000 = 1 Second
      • 1001 = 1001 Milliseconds
      • 86400000 = 1 Day
      • 86401000 = 86401 Seconds
      Specified by:
      getTimeDescription in interface com.liferay.portal.kernel.language.Language
      Parameters:
      httpServletRequest - the request used to determine the current locale
      milliseconds - the time interval in milliseconds to describe
      approximate - whether the time description is approximate
      Returns:
      a localized description of the time interval in the largest unit possible
    • getTimeDescription

      public String getTimeDescription(javax.servlet.http.HttpServletRequest httpServletRequest, Long milliseconds)
      Returns an exact localized description of the time interval (in milliseconds) in the largest unit possible.

      For example, the following time intervals would be converted to the following time descriptions, using the English locale:

      • 1000 = 1 Second
      • 1001 = 1001 Milliseconds
      • 86400000 = 1 Day
      • 86401000 = 86401 Seconds
      Specified by:
      getTimeDescription in interface com.liferay.portal.kernel.language.Language
      Parameters:
      httpServletRequest - the request used to determine the current locale
      milliseconds - the time interval in milliseconds to describe
      Returns:
      an exact localized description of the time interval in the largest unit possible
    • getTimeDescription

      public String getTimeDescription(Locale locale, long milliseconds)
      Returns an exact localized description of the time interval (in milliseconds) in the largest unit possible.

      For example, the following time intervals would be converted to the following time descriptions, using the English locale:

      • 1000 = 1 Second
      • 1001 = 1001 Milliseconds
      • 86400000 = 1 Day
      • 86401000 = 86401 Seconds
      Specified by:
      getTimeDescription in interface com.liferay.portal.kernel.language.Language
      Parameters:
      locale - the locale used to determine the language
      milliseconds - the time interval in milliseconds to describe
      Returns:
      an exact localized description of the time interval in the largest unit possible
    • getTimeDescription

      public String getTimeDescription(Locale locale, long milliseconds, boolean approximate)
      Returns an approximate or exact localized description of the time interval (in milliseconds) in the largest unit possible.

      Approximate descriptions round the time to the largest possible unit and ignores the rest. For example, using the English locale:

      • Any time interval 1000-1999 = 1 Second
      • Any time interval 86400000-172799999 = 1 Day

      Otherwise, exact descriptions would follow a similar conversion pattern as below:

      • 1000 = 1 Second
      • 1001 = 1001 Milliseconds
      • 86400000 = 1 Day
      • 86401000 = 86401 Seconds
      Specified by:
      getTimeDescription in interface com.liferay.portal.kernel.language.Language
      Parameters:
      locale - the locale used to determine the language
      milliseconds - the time interval in milliseconds to describe
      approximate - whether the time description is approximate
      Returns:
      a localized description of the time interval in the largest unit possible
    • getTimeDescription

      public String getTimeDescription(Locale locale, Long milliseconds)
      Returns an exact localized description of the time interval (in milliseconds) in the largest unit possible.

      For example, the following time intervals would be converted to the following time descriptions, using the English locale:

      • 1000 = 1 Second
      • 1001 = 1001 Milliseconds
      • 86400000 = 1 Day
      • 86401000 = 86401 Seconds
      Specified by:
      getTimeDescription in interface com.liferay.portal.kernel.language.Language
      Parameters:
      locale - the locale used to determine the language
      milliseconds - the time interval in milliseconds to describe
      Returns:
      an exact localized description of the time interval in the largest unit possible
    • init

      public void init()
      Specified by:
      init in interface com.liferay.portal.kernel.language.Language
    • isAvailableLanguageCode

      public boolean isAvailableLanguageCode(String languageCode)
      Returns true if the language code is configured to be available. Locales can be configured in portal.properties using the locales and locales.enabled keys.
      Specified by:
      isAvailableLanguageCode in interface com.liferay.portal.kernel.language.Language
      Parameters:
      languageCode - the code representation of a language (e.g. en and en_GB) to search for
      Returns:
      true if the language code is configured to be available; false otherwise
    • isAvailableLocale

      public boolean isAvailableLocale(Locale locale)
      Returns true if the locale is configured to be available. Locales can be configured in portal.properties using the locales and locales.enabled keys.
      Specified by:
      isAvailableLocale in interface com.liferay.portal.kernel.language.Language
      Parameters:
      locale - the locale to search for
      Returns:
      true if the locale is configured to be available; false otherwise
    • isAvailableLocale

      public boolean isAvailableLocale(long groupId, Locale locale)
      Returns true if the locale is configured to be available in the group.
      Specified by:
      isAvailableLocale in interface com.liferay.portal.kernel.language.Language
      Parameters:
      groupId - the primary key of the group
      locale - the locale to search for
      Returns:
      true if the locale is configured to be available in the group; false otherwise
    • isAvailableLocale

      public boolean isAvailableLocale(long groupId, String languageId)
      Returns true if the language ID is configured to be available in the group.
      Specified by:
      isAvailableLocale in interface com.liferay.portal.kernel.language.Language
      Parameters:
      groupId - the primary key of the group
      languageId - the language ID to search for
      Returns:
      true if the language ID is configured to be available in the group; false otherwise
    • isAvailableLocale

      public boolean isAvailableLocale(String languageId)
      Returns true if the language ID is configured to be available.
      Specified by:
      isAvailableLocale in interface com.liferay.portal.kernel.language.Language
      Parameters:
      languageId - the language ID to search for
      Returns:
      true if the language ID is configured to be available; false otherwise
    • isBetaLocale

      public boolean isBetaLocale(Locale locale)
      Returns true if the locale is configured to be a beta language.
      Specified by:
      isBetaLocale in interface com.liferay.portal.kernel.language.Language
      Parameters:
      locale - the locale to search for
      Returns:
      true if the locale is configured to be a beta language; false otherwise
    • isDuplicateLanguageCode

      public boolean isDuplicateLanguageCode(String languageCode)
      Specified by:
      isDuplicateLanguageCode in interface com.liferay.portal.kernel.language.Language
    • isInheritLocales

      public boolean isInheritLocales(long groupId) throws com.liferay.portal.kernel.exception.PortalException
      Specified by:
      isInheritLocales in interface com.liferay.portal.kernel.language.Language
      Throws:
      com.liferay.portal.kernel.exception.PortalException
    • isSameLanguage

      public boolean isSameLanguage(Locale locale1, Locale locale2)
      Specified by:
      isSameLanguage in interface com.liferay.portal.kernel.language.Language
    • process

      public String process(Supplier<ResourceBundle> resourceBundleSupplier, Locale locale, String content)
      Specified by:
      process in interface com.liferay.portal.kernel.language.Language
    • resetAvailableGroupLocales

      public void resetAvailableGroupLocales(long groupId)
      Specified by:
      resetAvailableGroupLocales in interface com.liferay.portal.kernel.language.Language
    • resetAvailableLocales

      public void resetAvailableLocales(long companyId)
      Specified by:
      resetAvailableLocales in interface com.liferay.portal.kernel.language.Language
    • updateCookie

      public void updateCookie(javax.servlet.http.HttpServletRequest httpServletRequest, javax.servlet.http.HttpServletResponse httpServletResponse, Locale locale)
      Specified by:
      updateCookie in interface com.liferay.portal.kernel.language.Language