@PublicApi @InjectableComponent public interface I18nHelper
Since JIRA 6.0 you can have an I18nHelper injected directly into any JIRA or plugin component (this will use the locale if the currently logged in user, or the default locale if there is no logged in user).
In versions prior to 6.0 you should only use the i18nHelper in your code which generally you get from JiraAuthenticationContext.getI18nHelper()
or I18nHelper.BeanFactory
. Both of
these are available in PICO to be dependency injected or available from ComponentAccessor.getI18nHelperFactory()
or ComponentAccessor.getJiraAuthenticationContext()
.
You MUST never directly instantiate the underlying I18nBean. You will get it wrong and miss out on cool stuff like flyweight caching.
You SHOULD NOT hold onto this Helper for any extended period of time for 2 reasons. Firstly you will be using a
cached Locale and values, so the Locale is now locked in for the duration of holding onto the helper. Secondly you are holding onto a
large memory resource for longer than needed. Instead you should keep hold of the JiraAuthenticationContext
or the I18nHelper.BeanFactory
and retrieve the helper when needed.
Modifier and Type | Interface and Description |
---|---|
static interface |
I18nHelper.BeanFactory
Ths BeanFactory is used to instantiate
I18nHelper instances for a specific Locale or User. |
Modifier and Type | Method and Description |
---|---|
ResourceBundle |
getDefaultResourceBundle()
Returns the default
ResourceBundle within JIRA, which does not include translations provided by plugins. |
Set<String> |
getKeysForPrefix(String prefix)
Given a prefix for an i18n key, this method will return all keys that start with the prefix specified.
|
Locale |
getLocale() |
ResourceBundle |
getResourceBundle()
Returns the consolidated ResourceBundle for this I18nHelper, which includes translations provided by plugins.
|
String |
getText(String key)
Called to return the formatted text of the specified i18n key or the key itself if no message can be found
|
String |
getText(String key,
Object parameters)
Called to return the formatted text of the specified i18n key or the key itself if no message can be found.
|
String |
getText(String key,
Object value1,
Object value2,
Object value3)
Called to return the formatted text of the specified i18n key or the key itself if no message can be found
|
String |
getText(String key,
Object value1,
Object value2,
Object value3,
Object value4)
Called to return the formatted text of the specified i18n key or the key itself if no message can be found
|
String |
getText(String key,
Object value1,
Object value2,
Object value3,
Object value4,
Object value5)
Called to return the formatted text of the specified i18n key or the key itself if no message can be found
|
String |
getText(String key,
Object value1,
Object value2,
Object value3,
Object value4,
Object value5,
Object value6)
Called to return the formatted text of the specified i18n key or the key itself if no message can be found
|
String |
getText(String key,
Object value1,
Object value2,
Object value3,
Object value4,
Object value5,
Object value6,
Object value7)
Called to return the formatted text of the specified i18n key or the key itself if no message can be found
|
String |
getText(String key,
Object value1,
Object value2,
Object value3,
Object value4,
Object value5,
Object value6,
Object value7,
Object value8)
Called to return the formatted text of the specified i18n key or the key itself if no message can be found
|
String |
getText(String key,
String value1)
Called to return the formatted text of the specified i18n key or the key itself if no message can be found
|
String |
getText(String key,
String value1,
String value2)
Called to return the formatted text of the specified i18n key or the key itself if no message can be found
|
String |
getText(String key,
String value1,
String value2,
String value3)
Called to return the formatted text of the specified i18n key or the key itself if no message can be found
|
String |
getText(String key,
String value1,
String value2,
String value3,
String value4)
Called to return the formatted text of the specified i18n key or the key itself if no message can be found
|
String |
getText(String key,
String value1,
String value2,
String value3,
String value4,
String value5,
String value6,
String value7)
Called to return the formatted text of the specified i18n key
|
String |
getText(String key,
String value1,
String value2,
String value3,
String value4,
String value5,
String value6,
String value7,
String value8,
String value9)
Called to return the formatted text of the specified i18n key or the key itself if no message can be found
|
String |
getUnescapedText(String key)
Called to return the un-formatted text of the specified i18n key or the key itself if no message can be found
|
String |
getUntransformedRawText(String key)
Same as
getUnescapedText(String) but does not apply any TranslationTransform s. |
boolean |
isKeyDefined(String key)
For the given key, checks whether such a key is defined in the locale context represented by this helper
instance.
|
ResourceBundle getDefaultResourceBundle()
ResourceBundle
within JIRA, which does not include translations provided by plugins.
For use cases where non-English translations are required, call getResourceBundle()
instead.getResourceBundle()
String getUnescapedText(String key)
key
- the key of the i18n messageString getUntransformedRawText(String key)
getUnescapedText(String)
but does not apply any TranslationTransform
s.key
- the key of the i18n messageboolean isKeyDefined(String key)
For the given key, checks whether such a key is defined in the locale context represented by this helper instance. Note that the actual translation may be in the 'fallback' default locale rather than the current locale.
The contract of this is method is correlated with getUntransformedRawText(String)
, whereby if this
method returns false
, getUntransformedRawText(String)
will return the key provided as an
argument, and if this method returns true
, getUntransformedRawText(String)
will generally
return the translation, which in some very unlikely cases may be equal to the key.
key
- translation keytrue
, if any translation for such key exists, false
otherwiseString getText(String key)
key
- the key of the i18n messageString getText(String key, String value1)
key
- the key of the i18n messagevalue1
- a value to be substituted into the messageString getText(String key, String value1, String value2)
key
- the key of the i18n messagevalue1
- a value to be substituted into the messagevalue2
- a value to be substituted into the messageString getText(String key, String value1, String value2, String value3)
key
- the key of the i18n messagevalue1
- a value to be substituted into the messagevalue2
- a value to be substituted into the messagevalue3
- a value to be substituted into the messageString getText(String key, String value1, String value2, String value3, String value4)
key
- the key of the i18n messagevalue1
- a value to be substituted into the messagevalue2
- a value to be substituted into the messagevalue3
- a value to be substituted into the messagevalue4
- a value to be substituted into the messageString getText(String key, Object value1, Object value2, Object value3)
key
- the key of the i18n messagevalue1
- a value to be substituted into the messagevalue2
- a value to be substituted into the messagevalue3
- a value to be substituted into the messageString getText(String key, Object value1, Object value2, Object value3, Object value4)
key
- the key of the i18n messagevalue1
- a value to be substituted into the messagevalue2
- a value to be substituted into the messagevalue3
- a value to be substituted into the messagevalue4
- a value to be substituted into the messageString getText(String key, Object value1, Object value2, Object value3, Object value4, Object value5)
key
- the key of the i18n messagevalue1
- a value to be substituted into the messagevalue2
- a value to be substituted into the messagevalue3
- a value to be substituted into the messagevalue4
- a value to be substituted into the messagevalue5
- a value to be substituted into the messageString getText(String key, Object value1, Object value2, Object value3, Object value4, Object value5, Object value6)
key
- the key of the i18n messagevalue1
- a value to be substituted into the messagevalue2
- a value to be substituted into the messagevalue3
- a value to be substituted into the messagevalue4
- a value to be substituted into the messagevalue5
- a value to be substituted into the messagevalue6
- a value to be substituted into the messageString getText(String key, Object value1, Object value2, Object value3, Object value4, Object value5, Object value6, Object value7)
key
- the key of the i18n messagevalue1
- a value to be substituted into the messagevalue2
- a value to be substituted into the messagevalue3
- a value to be substituted into the messagevalue4
- a value to be substituted into the messagevalue5
- a value to be substituted into the messagevalue6
- a value to be substituted into the messagevalue7
- a value to be substituted into the messageString getText(String key, String value1, String value2, String value3, String value4, String value5, String value6, String value7)
key
- the key of the i18n messagevalue1
- a value to be substituted into the messagevalue2
- a value to be substituted into the messagevalue3
- a value to be substituted into the messagevalue4
- a value to be substituted into the messagevalue5
- a value to be substituted into the messagevalue6
- a value to be substituted into the messagevalue7
- a value to be substituted into the messageString getText(String key, Object value1, Object value2, Object value3, Object value4, Object value5, Object value6, Object value7, Object value8)
key
- the key of the i18n messagevalue1
- a value to be substituted into the messagevalue2
- a value to be substituted into the messagevalue3
- a value to be substituted into the messagevalue4
- a value to be substituted into the messagevalue5
- a value to be substituted into the messagevalue6
- a value to be substituted into the messagevalue7
- a value to be substituted into the messagevalue8
- a value to be substituted into the messageString getText(String key, String value1, String value2, String value3, String value4, String value5, String value6, String value7, String value8, String value9)
key
- the key of the i18n messagevalue1
- a value to be substituted into the messagevalue2
- a value to be substituted into the messagevalue3
- a value to be substituted into the messagevalue4
- a value to be substituted into the messagevalue5
- a value to be substituted into the messagevalue6
- a value to be substituted into the messagevalue7
- a value to be substituted into the messagevalue8
- a value to be substituted into the messagevalue9
- a value to be substituted into the messageString getText(String key, Object parameters)
The object passed in can be an array, a List
} or a single parameter object. It will be then
used as substitution parameters within the message.
key
- the key of the i18n messageparameters
- This can be an Array, a List
and Array or a single object parameterSet<String> getKeysForPrefix(String prefix)
prefix
- The prefix for i18n keys. May not be nullResourceBundle getResourceBundle()
getDefaultResourceBundle()
Copyright © 2002-2024 Atlassian. All Rights Reserved.