Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to use AJS.I18n?

grundic
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.
November 9, 2011

Hello!

I saw some examples in Jira's code about using AJS.I18n:

AJS.I18n.getText("common.words.close");

Also I read these docs.

But for some reason, when I execute it from my plugin or from Firebug it returns the same common.words.close

Does any one know how to use it?

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

13 votes
Answer accepted
Wojciech Seliga
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.
November 11, 2011

AJS.I18n.getText() requires pre-processing on the server side. It does not do any magic on the client side :)

To switch on i18n preprocessing you need to configure appropriate transformation.

In your atlassian-plugin.xml you need something like:

 

<web-resource key="your-resource-key">
        <transformation extension="js">
            <transformer key="jsI18n"/>
        </transformation>
...
       <resource type="typehere" name="yourjavascriptfile.js" location="yourlocationofthefileinpluginstructure.js" />

 ...

 

 

All this applies for files which are generally interpreted by the browser (like javascript or CSS).

If you need i18n in your standard Velocity templates (fully processed on the server side) then you don't need to bother with AJS.I18n.getText() at all. Just use getText("your.i18n.key") method which is available in all webwork actions via JiraActionSupport superclass.

 

grundic
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.
November 15, 2011

Great! It worked :)

Thanks a lot :)

Nikolai Matveev July 29, 2015

Still not working for me. Could you please suggest a way to debug the issue?

0 votes
tatoo988 November 10, 2011

can't you do this?

create a i18n.properties file on theresources.

Then add it on your plugin descriptor

<resourcetype="i18n" location="i18n/i18n" name="i18n" />

and then call the i18n messages this way:

label: gadget.getMsg("gadget.workloadpie.field.issuetimetype.name")

At least this seems to work fine, i haven't proved the other way.

grundic
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.
November 10, 2011

In previous example I used standard Jira's resource message common.words.close - it should be availaible anywhere, I suppose.

And I need this functionality not in gadget, but in web-work action, in velocity template.

With my custom properties file it wont work either.

TAGS
AUG Leaders

Atlassian Community Events