Our code base uses both I18nHelper
and I18nResolver
in various places. What is the difference between them, and in what situations should one be chosen over the other?
Update: We excised all use of I18nResolver
from our code base, unifying on I18nHelper
obtained from JiraAuthenticationContext
instances (as pointed out in Titus' answer). This approach appears to function correctly.
Community moderators have prevented the ability to post new answers.
We usually use I18nHelper
in our JIRA plugin.
An instance could be received using the component accessor:
I18nHelper i18n = ComponentAccessor.getJiraAuthenticationContext().getI18nHelper()
The advantage is, that the JIRA authentication context will return the correct initalized helper. After that the localized messages could be accessed using:
i18n.getText("message.property")
or with additional values like
i18n.getText("message.property", string1, string2, ...)
wich will be substituted into the message with the key "message.property" e.g.
message.property="string1 {0} and string2 {1}"
Titus
I apologize that the question wasn't clear enough–I rephrased the question to emphasize the request for an explanation of the difference between I18nHelper and I18nResolver.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The main difference is, that I18nHelper is especially for JIRA as I18nResolver belongs to the shared access layer of Atlassian. So if you intend to write plugins for more than one of Atlassian applications like jira, confluence or bamboo you should use I18nResolver. Otherwise if your plugin is supposed to run only in one of Atlassians applications you can use the application api e.g. I18nHelper in jira. https://developer.atlassian.com/docs/atlassian-platform-common-components/shared-access-layer
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Found one difference.
When listening for plugin enable and disable events using InitializingBean, i18nHelper from within JiraAuthenticationContext does not work (not sure why, maybe too early to be wired?).
However, instantiating an i18nResolver using the the same injected JiraAuthenticationContext plus a I18nHelper.BeanFactory will allow your i18n getText() method to work during such time.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.