Hi,
this might be a short question, but I did not find any help anywhere:
How can I get the translated name of System fields via Groovy scripts in ScriptRunner?
I know that I can get the translations using the TranslationManager and CustomFields but I did not find any documentation on using this for System fields (for example "summary").
In my example, I would like to get the name "Zusammenfassung" for the system field "summary".
Thanks!
Stefan
I have found an answer to the question, which is using the i18n functions.
The following script lists all the system fields and the custom fields each with its translations. It assumes to be executed with an english user profile and will display the German translation as well:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.fields.OrderableField
import com.atlassian.jira.issue.fields.layout.field.FieldLayoutItem
import com.atlassian.jira.util.I18nHelper
import com.atlassian.jira.web.action.admin.translation.TranslationManager
TranslationManager tm = ComponentAccessor.translationManager
List<FieldLayoutItem> items = ComponentAccessor.fieldLayoutManager.editableFieldLayouts.find{it.id == 10000}.fieldLayoutItems
List<OrderableField> systemFields = items.collect{it.orderableField}.findAll{!it.id.startsWith("customfield")}
List<OrderableField> customFields = items.collect{it.orderableField}.findAll{it.id.startsWith("customfield")}
I18nHelper i18n = ComponentAccessor.getI18nHelperFactory().getInstance(Locale.GERMANY)
log.debug(":::System Fields:::")
systemFields.each {cf ->
log.debug("${cf.name} : ${i18n.getText(cf.getNameKey())}" )
}
log.debug(":::Custom Fields:::")
customFields.each {cf ->
CustomField _cf = cf as CustomField
log.debug("${_cf.untranslatedName} : ${tm.getCustomFieldNameTranslation(_cf,Locale.GERMANY)}" )
}
If I understand your query correctly, you want to get translated name (german to english) of system field using groovy script.
You can try below script in script runner:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.fields.CustomField
def issueManager = ComponentAccessor.getIssueManager()
def issue = issueManager.getIssueObject("ISSUE-KEY") // Replace with your issue key
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def nameField = customFieldManager.getCustomFieldObjectByName("Name Field") // Replace with your field name
def nameValue = issue.getCustomFieldValue(nameField)
// Implement your translation logic here
def translatedName = translateName(nameValue) // Define this function based on your translation logic
issue.setCustomFieldValue(nameField, translatedName)
// Save the changes
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
issueManager.updateIssue(user, issue, EventDispatchOption.DO_NOT_DISPATCH, false)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Dilip
this is not what I meant.
I want to get the translated name of the system field "summary". I do not need the value, but instead the name of the field.
What I want to get is a complete list of available fields in the Jira instance and that would require to have the respective translations of the names of system fields (such as "summary" or "description") also being available.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.