Hi,
could someone tell me how to use i18n in groovy script on this example:
import com.atlassian.jira.issue.Issue import com.opensymphony.workflow.InvalidInputException def locales = [new Locale("en", "US"), new Locale("de", "DE")] // loop all versions for (int i = 0; i < issue.getFixVersions().size(); i++) { if ((issue.getFixVersions().get(i).released)) { //Only execute if the fix version is released invalidInputException = new InvalidInputException("assignee", "Issue could not be reopened. Version \"" + issue.getFixVersions().get(i).name + "\" has already been released.") break; } }
I would like to translate the following:
"Issue could not be reopened. Version \"" + issue.getFixVersions().get(i).name + "\" has already been released." .
Community moderators have prevented the ability to post new answers.
Same as the java way probably. You should add your strings to a resource bundle, then you use the i18nHelper... for example (to test this you need greenhopper installed), you can run the following in the script console;
import com.atlassian.jira.component.ComponentAccessor ComponentAccessor.getJiraAuthenticationContext().getI18nHelper().getText("gh.boards.linefieldcomponentboard")
If you change your language to French via your profile you will get different text.
If you want to do it the hacky way (I approve) and handle it all in your script, you can get the language code like:
ComponentAccessor.getJiraAuthenticationContext().getI18nHelper().getLocale().getLanguage()
Ok, I'm somehow using it wrong.
checkVersionIsReleased.groovy:
import com.atlassian.jira.issue.Issue import com.opensymphony.workflow.InvalidInputException import com.atlassian.jira.component.ComponentAccessor def firstPart = ComponentAccessor.getJiraAuthenticationContext().getI18nHelper().getText("com.test.checkVersionIsReleased.firstPart") def secondPart = ComponentAccessor.getJiraAuthenticationContext().getI18nHelper().getText("com.test.checkVersionIsReleased.secondPart") // loop all versions for (int i = 0; i < issue.getFixVersions().size(); i++) { if ((issue.getFixVersions().get(i).released)) { //Only execute if the fix version is released invalidInputException = new InvalidInputException("assignee", firstPart + issue.getFixVersions().get(i).name + secondPart) break; } }
checkVersionIsReleased.properties:
com.test.checkVersionIsReleased.firstPart = "Issue could not be reopened. Version \"" com.test.checkVersionIsReleased.secondPart = "\" has already been released."
checkVersionIsReleased_de.properties:
com.test.checkVersionIsReleased.firstPart = "Der Vorgang konnte nicht geöffnet werden. Version \"" com.test.checkVersionIsReleased.secondPart = "\" wurde schon veröffentlicht."
The result is:
"com.test.checkVersionIsReleased.firstPartTest The Released Version com.test.checkVersionIsReleased.secondPart"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You meant ? :
import com.atlassian.jira.issue.Issue import com.opensymphony.workflow.InvalidInputException import com.atlassian.jira.component.ComponentAccessor // loop all versions for (int i = 0; i < issue.getFixVersions().size(); i++) { if ((issue.getFixVersions().get(i).released)) { //Only execute if the fix version is released invalidInputException = new InvalidInputException("assignee", ComponentAccessor.getJiraAuthenticationContext().getI18nHelper().getText("com.test.checkVersionIsReleased.firstPart") + issue.getFixVersions().get(i).name + ComponentAccessor.getJiraAuthenticationContext().getI18nHelper().getText("com.test.checkVersionIsReleased.secondPart")) break; } }
All files are in: C:\Program Files\Atlassian\Application Data\JIRA
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You can put parameters in your i18n messages btw.
So it's failing to find the resource bundle clearly. Where have you put your properties files?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I meant https://developer.atlassian.com/static/javadoc/jira/6.0/reference/com/atlassian/jira/util/I18nHelper.html#getText(java.lang.String, java.lang.String) or one of its friends.
The resource bundle needs to be on the classpath, that location isn't afaik. You prob need to restart as well to have jira pick it up.
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.