View Javadoc
1   package com.atlassian.sal.api.message;
2   
3   import com.atlassian.sal.api.user.UserKey;
4   
5   import javax.annotation.Nullable;
6   import javax.servlet.http.HttpServletRequest;
7   import java.util.Locale;
8   import java.util.Set;
9   
10  /**
11   * This interface is responsible for resolving the current locale.
12   *
13   * @since 2.0
14   */
15  public interface LocaleResolver {
16      /**
17       * Given a request, resolve the {@link Locale} that should be used in internationalization and localization.
18       * The locale should be determined by first checking the remote users preferences, then defaulting to the
19       * application default locale if no preferred locale is set. May consult the given request for the preferred
20       * browser locales (if supported by the product).
21       *
22       * @param request Request to check
23       * @return Locale to be used in i18n and l10n. {@link Locale#getDefault()} if none found.
24       */
25      Locale getLocale(HttpServletRequest request);
26  
27      /**
28       * Resolve the Locale that should be used in internationalization and localization.  The
29       * locale should be determined by checking the preferences of the user in the current authentication
30       * context if available, then default to the application default locale if no preferred locale is set. May consult
31       * the current request for the preferred browser locales (if supported by the product).
32       *
33       * @return Locale to be used in i18n and l10n. {@link Locale#getDefault()} if none found.
34       */
35      Locale getLocale();
36  
37      /**
38       * Resolve the Locale that should be used in internationalization and localization.  The locale should be determined
39       * by checking the preferences of the given user. If no user is given, or the user cannot be found, or the user does
40       * not have any preferred locale, then default to the application default locale. Must not consult the current
41       * request for any preferred browser locales.
42       *
43       * @param userKey the user. Can be null.
44       * @return Locale to be used in i18n and l10n. {@link Locale#getDefault()} if none found.
45       * @since 2.10
46       */
47      Locale getLocale(@Nullable UserKey userKey);
48  
49      /**
50       * Returns a set of all the supported locales by the host application. This is all the language packs that
51       * are installed.
52       *
53       * @return an unmodifiable set of all the supported locales by the host application. Must contain at least one
54       * locale.
55       */
56      Set<Locale> getSupportedLocales();
57  }