I18nHelper or I18nResolver?

Keiei Tanto _Vivid_ September 19, 2015

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.

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Answer accepted
Titus
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 29, 2015

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

Keiei Tanto _Vivid_ September 29, 2015

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.

Titus
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 29, 2015

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

0 votes
Lee Alexis Bermejo March 13, 2018

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.

TAGS
AUG Leaders

Atlassian Community Events