@PublicApi @InjectableComponent public interface

I18nHelper

com.atlassian.jira.util.I18nHelper
Known Indirect Subclasses

@PublicApi

This interface is designed for plugins to consume (call its methods).

Clients of @PublicApi can expect that programs compiled against a given version will remain binary compatible with later versions of the @PublicApi as per each product's API policy as long as the client does not implement/extend @PublicApi interfaces or classes (refer to each product's API policy for the exact guarantee---usually binary compatibility is guaranteed at least across minor versions).

Note: since @PublicApi interfaces and classes are not designed to be implemented or extended by clients, we may perform certain types of binary-incompatible changes to these classes and interfaces, but these will not affect well-behaved clients that do not extend/implement these types (in general, only classes and interfaces annotated with @PublicSpi are safe to extend/implement).

Class Overview

I18nHelper is the main interface for finding internationalised text in JIRA.

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 getI18nHelper() or I18nHelper.BeanFactory. Both of these are available in PICO to be dependency injected or available from getI18nHelperFactory() or 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.

Summary

Nested Classes
interface I18nHelper.BeanFactory Ths BeanFactory is used to instantiate I18nHelper instances for a specific Locale or User. 
Public Methods
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, 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, 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, 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 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, 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 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, 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)
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, 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, 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, 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 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 TranslationTransforms.
boolean isKeyDefined(String key)

For the given key, checks whether such a key is defined in the locale context represented by this helper instance.

Public Methods

public ResourceBundle getDefaultResourceBundle ()

Returns the default ResourceBundle within JIRA, which does not include translations provided by plugins. For use cases where non-English translations are required, call getResourceBundle() instead.

Returns
  • a non-null bundle

public Set<String> getKeysForPrefix (String prefix)

Given a prefix for an i18n key, this method will return all keys that start with the prefix specified.

Parameters
prefix The prefix for i18n keys. May not be null
Returns
  • An immutable set of translation keys that start with the prefix specified.

public Locale getLocale ()

Returns
  • the Locale that is associated with this I18nHelper

public ResourceBundle getResourceBundle ()

Returns the consolidated ResourceBundle for this I18nHelper, which includes translations provided by plugins.

Returns
  • a non-null bundle

public 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

Parameters
key the key of the i18n message
value1 a value to be substituted into the message
value2 a value to be substituted into the message
value3 a value to be substituted into the message
value4 a value to be substituted into the message
value5 a value to be substituted into the message
value6 a value to be substituted into the message
value7 a value to be substituted into the message
Returns
  • the formatted text or the key itself if no i18n message can be found

public 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

Parameters
key the key of the i18n message
value1 a value to be substituted into the message
value2 a value to be substituted into the message
value3 a value to be substituted into the message
value4 a value to be substituted into the message
Returns
  • the formatted text or the key itself if no i18n message can be found

public 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

Parameters
key the key of the i18n message
value1 a value to be substituted into the message
value2 a value to be substituted into the message
value3 a value to be substituted into the message
value4 a value to be substituted into the message
Returns
  • the formatted text or the key itself if no i18n message can be found

public 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.

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.

Parameters
key the key of the i18n message
parameters This can be an Array, a List and Array or a single object parameter
Returns
  • the formatted text or the key itself if no i18n message can be found

public 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

Parameters
key the key of the i18n message
value1 a value to be substituted into the message
value2 a value to be substituted into the message
value3 a value to be substituted into the message
value4 a value to be substituted into the message
value5 a value to be substituted into the message
value6 a value to be substituted into the message
value7 a value to be substituted into the message
value8 a value to be substituted into the message
value9 a value to be substituted into the message
Returns
  • the formatted text or the key itself if no i18n message can be found

public 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

Parameters
key the key of the i18n message
value1 a value to be substituted into the message
value2 a value to be substituted into the message
value3 a value to be substituted into the message
value4 a value to be substituted into the message
value5 a value to be substituted into the message
Returns
  • the formatted text or the key itself if no i18n message can be found

public 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

Parameters
key the key of the i18n message
value1 a value to be substituted into the message
value2 a value to be substituted into the message
value3 a value to be substituted into the message
value4 a value to be substituted into the message
value5 a value to be substituted into the message
value6 a value to be substituted into the message
Returns
  • the formatted text or the key itself if no i18n message can be found

public 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

Parameters
key the key of the i18n message
value1 a value to be substituted into the message
value2 a value to be substituted into the message
value3 a value to be substituted into the message
Returns
  • the formatted text or the key itself if no i18n message can be found

public 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

Parameters
key the key of the i18n message
Returns
  • the formatted text or the key itself if no i18n message can be found

public 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

Parameters
key the key of the i18n message
value1 a value to be substituted into the message
value2 a value to be substituted into the message
value3 a value to be substituted into the message
value4 a value to be substituted into the message
value5 a value to be substituted into the message
value6 a value to be substituted into the message
value7 a value to be substituted into the message
value8 a value to be substituted into the message
Returns
  • the formatted text or the key itself if no i18n message can be found

public 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

Parameters
key the key of the i18n message
value1 a value to be substituted into the message
Returns
  • the formatted text or the key itself if no i18n message can be found

public 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

Parameters
key the key of the i18n message
value1 a value to be substituted into the message
value2 a value to be substituted into the message
value3 a value to be substituted into the message
value4 a value to be substituted into the message
value5 a value to be substituted into the message
value6 a value to be substituted into the message
value7 a value to be substituted into the message
Returns
  • the formatted text or the key itself if no i18n message can be found

public 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

Parameters
key the key of the i18n message
value1 a value to be substituted into the message
value2 a value to be substituted into the message
value3 a value to be substituted into the message
Returns
  • the formatted text or the key itself if no i18n message can be found

public 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

Parameters
key the key of the i18n message
value1 a value to be substituted into the message
value2 a value to be substituted into the message
Returns
  • the formatted text or the key itself if no i18n message can be found

public 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

Parameters
key the key of the i18n message
Returns
  • the un-formatted, translated, text or the key itself if no i18n message can be found

public String getUntransformedRawText (String key)

Same as getUnescapedText(String) but does not apply any TranslationTransforms.

Parameters
key the key of the i18n message
Returns
  • the un-formatted text or the key itself if no i18n message can be found

public boolean 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.

Parameters
key translation key
Returns
  • true, if any translation for such key exists, false otherwise