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      /**
18       * Given a request, resolve the {@link Locale} that should be used in internationalization and localization.
19       * The locale should be determined by first checking the remote users preferences, then defaulting to the
20       * application default locale if no preferred locale is set. May consult the given request for the preferred
21       * browser locales (if supported by the product).
22       *
23       * @param request Request to check
24       * @return Locale to be used in i18n and l10n. {@link Locale#getDefault()} if none found.
25       */
26      Locale getLocale(HttpServletRequest request);
27  
28      /**
29       * Resolve the Locale that should be used in internationalization and localization.  The
30       * locale should be determined by checking the preferences of the user in the current authentication
31       * context if available, then default to the application default locale if no preferred locale is set. May consult
32       * the current request for the preferred browser locales (if supported by the product).
33       *
34       * @return Locale to be used in i18n and l10n. {@link Locale#getDefault()} if none found.
35       */
36      Locale getLocale();
37  
38      /**
39       * Resolve the Locale that should be used in internationalization and localization.  The locale should be determined
40       * by checking the preferences of the given user. If no user is given, or the user cannot be found, or the user does
41       * not have any preferred locale, then default to the application default locale. Must not consult the current
42       * request for any preferred browser locales.
43       *
44       * @param userKey the user. Can be null.
45       * @return Locale to be used in i18n and l10n. {@link Locale#getDefault()} if none found.
46       * @since 2.10
47       */
48      Locale getLocale(@Nullable UserKey userKey);
49  
50      /**
51       * Returns a set of all the supported locales by the host application. This is all the language packs that
52       * are installed.
53       *
54       * @return an unmodifiable set of all the supported locales by the host application. Must contain at least one
55       * locale.
56       */
57      Set<Locale> getSupportedLocales();
58  }