Class LocalizationScriptService

  • All Implemented Interfaces:
    org.xwiki.script.service.ScriptService

    @Component
    @Named("localization")
    @Singleton
    public class LocalizationScriptService
    extends Object
    implements org.xwiki.script.service.ScriptService
    Provides Component-specific Scripting APIs.
    Since:
    4.3M2
    Version:
    $Id: 84f6b0f4b35c83b2e35de5d0d5cf7fbe3d3a0e88 $
    • Constructor Detail

      • LocalizationScriptService

        public LocalizationScriptService()
    • Method Detail

      • get

        public Translation get​(String key)
        Parameters:
        key - the translation key
        Returns:
        the translation, null if none can be found
      • get

        public Translation get​(String key,
                               Locale locale)
        Parameters:
        key - the translation key
        locale - the Locale for which this translation is searched. The result might me associated to a different Locale (for example getting the fr translation when asking for the fr_FR one).
        Returns:
        the translation, null if none can be found
        Since:
        9.0RC1, 8.4.2
      • use

        public boolean use​(String bundleType,
                           String bundleId)
        Parameters:
        bundleType - the hint of the TranslationBundleFactory to use to get the actual bundle
        bundleId - the identifier of the bundle for the passed type
        Returns:
        true if the bundle has been found and properly added to the list of current translation bundles, false otherwise
      • getCurrentLocale

        public Locale getCurrentLocale()
        Returns:
        the Locale to use by default in the current context
      • getDefaultLocale

        public Locale getDefaultLocale()
        Returns:
        the Locale configured as the default
        Since:
        14.1RC1, 13.10.3
      • toLocale

        public Locale toLocale​(String str)
        Converts the given string to a locale. E.g. the string "pt_BR" is converted to a locale with the language set to Portuguese and the country set to Brazil.
        Parameters:
        str - the String to convert to Locale
        Returns:
        the corresponding locale, or Locale.ROOT if the given string is null or empty; if the given string doesn't represent a locale (e.g. invalid format) then null is returned
        Since:
        5.3M2
        See Also:
        LocaleUtils.toLocale(String)
      • render

        public String render​(String key)
        Parameters:
        key - the translation key
        Returns:
        the rendered translation message
      • render

        public String render​(Collection<String> keys)
        Parameters:
        keys - the translations keys to try one by one
        Returns:
        the rendered translation message
        Since:
        10.2
      • render

        public String render​(String key,
                             Locale locale)
        Parameters:
        key - the translation key
        locale - the Locale for which this translation is searched. The result might me associated to a different Locale (for example getting the fr translation when asking for the fr_FR one).
        Returns:
        the rendered translation message
        Since:
        9.0RC1, 8.4.2
      • render

        public String render​(Collection<String> keys,
                             Locale locale)
        Parameters:
        keys - the translations keys to try one by one
        locale - the Locale for which this translation is searched. The result might me associated to a different Locale (for example getting the fr translation when asking for the fr_FR one).
        Returns:
        the rendered translation message
        Since:
        10.2
      • render

        public String render​(String key,
                             Collection<?> parameters)
        Parameters:
        key - the translation key
        parameters - the translation parameters
        Returns:
        the rendered translation message
      • render

        public String render​(Collection<String> keys,
                             Collection<?> parameters)
        Parameters:
        keys - the translations keys to try one by one
        parameters - the translation parameters
        Returns:
        the rendered translation message
      • render

        public String render​(String key,
                             Collection<?> parameters,
                             Locale locale)
        Parameters:
        key - the translation key
        parameters - the translation parameters
        locale - the Locale for which this translation is searched. The result might me associated to a different Locale (for example getting the fr translation when asking for the fr_FR one).
        Returns:
        the rendered translation message
        Since:
        9.0RC1
      • render

        public String render​(Collection<String> keys,
                             Collection<?> parameters,
                             Locale locale)
        Parameters:
        keys - the translations keys to try one by one
        parameters - the translation parameters
        locale - the Locale for which this translation is searched. The result might me associated to a different Locale (for example getting the fr translation when asking for the fr_FR one).
        Returns:
        the rendered translation message
        Since:
        10.2
      • render

        public String render​(String key,
                             org.xwiki.rendering.syntax.Syntax syntax)
        Parameters:
        key - the translation key
        syntax - the syntax in which to render the translation message
        Returns:
        the rendered translation message, the key if no translation can be found and null if the rendering failed
        Since:
        5.1M2
      • render

        public String render​(Collection<String> keys,
                             org.xwiki.rendering.syntax.Syntax syntax)
        Parameters:
        keys - the translations keys to try one by one
        syntax - the syntax in which to render the translation message
        Returns:
        the rendered translation message, the key if no translation can be found and null if the rendering failed
        Since:
        10.2
      • render

        public String render​(String key,
                             org.xwiki.rendering.syntax.Syntax syntax,
                             Locale locale)
        Parameters:
        key - the translation key
        syntax - the syntax in which to render the translation message
        locale - the Locale for which this translation is searched. The result might me associated to a different Locale (for example getting the fr translation when asking for the fr_FR one).
        Returns:
        the rendered translation message, the key if no translation can be found and null if the rendering failed
        Since:
        9.0RC1
      • render

        public String render​(Collection<String> keys,
                             org.xwiki.rendering.syntax.Syntax syntax,
                             Locale locale)
        Parameters:
        keys - the translations keys to try one by one
        syntax - the syntax in which to render the translation message
        locale - the Locale for which this translation is searched. The result might me associated to a different Locale (for example getting the fr translation when asking for the fr_FR one).
        Returns:
        the rendered translation message, the key if no translation can be found and null if the rendering failed
        Since:
        10.2
      • render

        public String render​(String key,
                             org.xwiki.rendering.syntax.Syntax syntax,
                             Collection<?> parameters)
        Parameters:
        key - the translation key
        syntax - the syntax in which to render the translation message
        parameters - the translation parameters
        Returns:
        the rendered translation message, the key if no translation can be found and null if the rendering failed
      • render

        public String render​(Collection<String> keys,
                             org.xwiki.rendering.syntax.Syntax syntax,
                             Collection<?> parameters)
        Parameters:
        keys - the translations keys to try one by one
        syntax - the syntax in which to render the translation message
        parameters - the translation parameters
        Returns:
        the rendered translation message, the key if no translation can be found and null if the rendering failed
        Since:
        10.2
      • render

        public String render​(String key,
                             org.xwiki.rendering.syntax.Syntax syntax,
                             Collection<?> parameters,
                             Locale locale)
        Parameters:
        key - the translation key
        syntax - the syntax in which to render the translation message
        parameters - the translation parameters
        locale - the Locale for which this translation is searched. The result might me associated to a different Locale (for example getting the fr translation when asking for the fr_FR one).
        Returns:
        the rendered translation message, the key if no translation can be found and null if the rendering failed
        Since:
        9.0RC1
      • render

        public String render​(Collection<String> keys,
                             org.xwiki.rendering.syntax.Syntax syntax,
                             Collection<?> parameters,
                             Locale locale)
        Parameters:
        keys - the translations keys to try one by one
        syntax - the syntax in which to render the translation message
        parameters - the translation parameters
        locale - the Locale for which this translation is searched. The result might me associated to a different Locale (for example getting the fr translation when asking for the fr_FR one).
        Returns:
        the rendered translation message, the key if no translation can be found and null if the rendering failed
        Since:
        10.2
      • getAvailableLocales

        public Set<Locale> getAvailableLocales()
        Returns:
        the list of available locales for XWiki translations
        Since:
        9.7RC1, 8.4.6, 9.6.1