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

This widget could not be displayed.

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.

This widget could not be displayed.

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.

This widget could not be displayed.

Hi Frédéric,

This is exectly what I needed.

Thanks for discusion guys.

Regards

Mik

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Wednesday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

175 views 2 0
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