How can i change language in jira from Jira API in Java ?

Hi Guys.

How can i change default language for user in jira from Jira API in Java ?

I must do it in my own plugin.

Thanks for any help.

Regards

Mik

3 answers

2 votes

Are you sure this is necessary? The default language is a one-off setting which your admin will generally set during installation. It's rare to need to change it again, and even then you really really want your admins to do it because they'll think about it. I'd never use a plugin that did that because I absolutely do not want the default language to change without me doing it explicitly.

Hi Mik,

Here's how I do:

private Locale getLocale(User user)
	{
		if (user == null)
			return Locale.getDefault();
		
		String userLocaleString = getUserPreferencesManager().getPreferences(user).getString(PreferenceKeys.USER_LOCALE);
		
		if (userLocaleString == null)
			return Locale.getDefault();
		
		StringTokenizer tokenizer = new StringTokenizer(userLocaleString, "_");
		String language = tokenizer.nextToken();
		String region = tokenizer.nextToken();
		
		if (language != null && region != null)
			return new Locale(language, region);
		else
			return Locale.getDefault();
		
	}

As you can see my entry point is a User (com.atlassian.crowd.embedded.api.User), and from this I get its locale (its locale is the language the user set in its preferences).

Then I instantiate a I18NHelper with this locale:

ComponentAccessor.getI18nHelperFactory().getInstance(getLocale(user));

So that the language used to display 18N Strings is the one set by the user if any, or JIRA server language if user language is not set,

Hope this helps,

Fred

I understood the need was to display strings depending on the language set by user...

I suspect your understanding was better than mine. The use of the word "default" made me jump because it's rather upsetting for admins to have things they've chosen changed without warning.

But, setting an individual user's preferred language from their chosen region is a friendly and useful thing to do.

This doesn't change the default language for a user, it sets their preference for them based on their chosen location. (Which is really nice)

Yes I agree, I find this more logical to have a language set for the whole instance, and then let users define another one if they want to. The code I pasted is to make a plugin sensitive to this user setting.

Hi Frédéric,

This is exectly what I needed.

Thanks for discusion guys.

Regards

Mik

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

3,240 views 14 19
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot