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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I understood the need was to display strings depending on the language set by user...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
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.