Change the language of a custom notification template

Since 1.9.10/1.8.35/1.7.79

Summary

The language of JEMH's custom notification templates can now be manipulated by calling a method through velocity template language.

Velocity Method Usage

For ease of use, it is recommended to set up a custom Velocimacro, so that your notification templates are cleaner and easier to maintain. In order to create the custom macro, go to JEMH>Template Sets and choose the User Macros tab.  Then, click the edit icon to the right of the window.

At the end of your User Macro list, add your new macro.  Below is an example of what this may look like.  Make sure that your macro is set up to take an argument (in this case called $locale), as this is needed to retrieve the locale.

Example Velocimacro
#macro (setLocale $localeID) #if ($localeID) #set ($i18n = $jemhUtils.getLocaleI18nBean($localeID)) #end #end

Once the macro has been defined, press submit to save the changes that you have made.

 

Using the Macro in a template

You can now call this macro in a custom template, passing a locale string in a particular format.  Here is a list of common locale codes:

Locale support can vary and is dependant on the locales supported by the Java Runtime Environment.

Language

Country

Locale ID

Language

Country

Locale ID

Arabic

Saudia Arabia

ar_SA

Chinese (simplified)

China

zh_CN

Chinese (traditional)

Taiwan

zh_TW

Dutch

Netherlands

nl_NL

English

United Kingdom

en_GB

English

United States

en_US

French

Canada

fr_CA

French

France

fr_FR

German

Germany

de_DE

Hebrew

Israel

he_IL

Hindi

India

hi_IN

Italian

Italy

it_IT

Japanese

Japan

ja_JP

Korean

South Korea

ko_KR

Portuguese

Brazil

pt_BR

Spanish

Spain

es_ES

The below is a small test template that demonstrates the locale being changed.  First the words for "username" and "full name" will be rendered using the default locale for language.  Then, the locale is changed to German using the macro we created.  Lastly, the same words are again rendered.  This time they will be translated to the locale we provided in the macro.

Example Usage in Notification Template (Text Format)
$i18n.getText('template.user.details.username') $i18n.getText('template.user.details.fullname') #setLocale("de_DE") ----- $i18n.getText('template.user.details.username') $i18n.getText('template.user.details.fullname')

If your JIRA instance has the appropriate translation available, the outcome of the above template should look like this:

Template Preview
Username Full Name ----- Benutzername Voller Name

Related Articles