Scriptrunner: Translate menu text of custom web item depending on users locale

Hans Hugo February 14, 2021

Hello community,

I use scriptrunner to automate a lot of processes in Jira. Thanks a lot for this great addon to Jira.

But now I come up with a question: I want to add a new web item (with a web section and more web items) in the top navigation menu.

I used the tutorial https://scriptrunner.adaptavist.com/latest/jira/fragments/WebItem.html to do this and it works perfectly. But now I want to translate the menu text depending on the users locale.

So my next try was to use the Web Item Provider Built-In Script (https://scriptrunner.adaptavist.com/latest/jira/fragments/WebItemProvider.html). I can code the label depending on the user setting, but now I cannot choose the created web item as parent for the web section (the dropdown doesn't list the key from the web item provider).

So either I use the web item but without menu text translation or I use the web item provider with menu text translation but without any chance to integrate further items (here: web section) as children of the web item.

My problem is, I need both :) Do you have any ideas?

I use Jira 8.13.3 (Server / self hosted) and Scriptrunner 6.18.0.

Thank you for your replies.

2 answers

1 accepted

0 votes
Answer accepted
Hans Hugo April 3, 2021

I solved the problem by duplicating the Web Item, Web Section and Web Item Provider. I use the condition to check the users locale and to decide which option to go for.

My condition is:

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.user.ApplicationUser;
import com.atlassian.jira.user.preferences.PreferenceKeys;

ApplicationUser loggedInUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();
String userLocale = ComponentAccessor.getUserPreferencesManager().getExtendedPreferences(loggedInUser).getString(PreferenceKeys.USER_LOCALE)

return "de_DE".equals(userLocale);
0 votes
Hans Hugo March 1, 2021

Any news on this topic? Thanks in advance.

Suggest an answer

Log in or Sign up to answer