Package org.xwiki.localization.script
Class LocalizationScriptService
- java.lang.Object
-
- org.xwiki.localization.script.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 Summary
Constructors Constructor Description LocalizationScriptService()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Translation
get(String key)
Translation
get(String key, Locale locale)
Set<Locale>
getAvailableLocales()
Locale
getCurrentLocale()
Locale
getDefaultLocale()
String
render(String key)
String
render(String key, Collection<?> parameters)
String
render(String key, Collection<?> parameters, Locale locale)
String
render(String key, Locale locale)
String
render(String key, org.xwiki.rendering.syntax.Syntax syntax)
String
render(String key, org.xwiki.rendering.syntax.Syntax syntax, Collection<?> parameters)
String
render(String key, org.xwiki.rendering.syntax.Syntax syntax, Collection<?> parameters, Locale locale)
String
render(String key, org.xwiki.rendering.syntax.Syntax syntax, Locale locale)
String
render(Collection<String> keys)
String
render(Collection<String> keys, Collection<?> parameters)
String
render(Collection<String> keys, Collection<?> parameters, Locale locale)
String
render(Collection<String> keys, Locale locale)
String
render(Collection<String> keys, org.xwiki.rendering.syntax.Syntax syntax)
String
render(Collection<String> keys, org.xwiki.rendering.syntax.Syntax syntax, Collection<?> parameters)
String
render(Collection<String> keys, org.xwiki.rendering.syntax.Syntax syntax, Collection<?> parameters, Locale locale)
String
render(Collection<String> keys, org.xwiki.rendering.syntax.Syntax syntax, Locale locale)
Locale
toLocale(String str)
Converts the given string to a locale.boolean
use(String bundleType, String bundleId)
-
-
-
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)
-
use
public boolean use(String bundleType, String bundleId)
- Parameters:
bundleType
- the hint of theTranslationBundleFactory
to use to get the actual bundlebundleId
- 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 isnull
or empty; if the given string doesn't represent a locale (e.g. invalid format) thennull
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(Collection<String> keys, Locale locale)
-
render
public String render(String key, Collection<?> parameters)
- Parameters:
key
- the translation keyparameters
- 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 oneparameters
- the translation parameters- Returns:
- the rendered translation message
-
render
public String render(String key, Collection<?> parameters, Locale locale)
- Parameters:
key
- the translation keyparameters
- the translation parameterslocale
- theLocale
for which this translation is searched. The result might me associated to a differentLocale
(for example getting thefr
translation when asking for thefr_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 oneparameters
- the translation parameterslocale
- theLocale
for which this translation is searched. The result might me associated to a differentLocale
(for example getting thefr
translation when asking for thefr_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 keysyntax
- 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 onesyntax
- 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 keysyntax
- the syntax in which to render the translation messagelocale
- theLocale
for which this translation is searched. The result might me associated to a differentLocale
(for example getting thefr
translation when asking for thefr_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 onesyntax
- the syntax in which to render the translation messagelocale
- theLocale
for which this translation is searched. The result might me associated to a differentLocale
(for example getting thefr
translation when asking for thefr_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 keysyntax
- the syntax in which to render the translation messageparameters
- 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 onesyntax
- the syntax in which to render the translation messageparameters
- 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 keysyntax
- the syntax in which to render the translation messageparameters
- the translation parameterslocale
- theLocale
for which this translation is searched. The result might me associated to a differentLocale
(for example getting thefr
translation when asking for thefr_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 onesyntax
- the syntax in which to render the translation messageparameters
- the translation parameterslocale
- theLocale
for which this translation is searched. The result might me associated to a differentLocale
(for example getting thefr
translation when asking for thefr_FR
one).- Returns:
- the rendered translation message, the key if no translation can be found and null if the rendering failed
- Since:
- 10.2
-
-