Class RootDirectoryBasedLocaleContextResolver
- All Implemented Interfaces:
org.springframework.web.servlet.LocaleResolver
-
Field Summary
FieldsModifier and TypeFieldDescriptionAll language codes that the application has already been translated to. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static @NonNull StringgetRootDirectory(@NonNull jakarta.servlet.http.HttpServletRequest request) Determines the top-level directory denoted by the URL path of the request.@NonNull LocaleresolveLocale(@NonNull jakarta.servlet.http.HttpServletRequest request) Determines the appropriateLocalethat shall be used to translate the resource requested.voidsetDefaultLocale(@NonNull Locale locale) Alias forLocale.setDefault(Locale).voidsetLocale(@NonNull jakarta.servlet.http.HttpServletRequest request, @Nullable jakarta.servlet.http.HttpServletResponse response, @Nullable Locale locale) Warning
Always throws
UnsupportedOperationException! This is because the locale appropriate for a request depends only on the URL path and not on anything else.
-
Field Details
-
supportedLocaleCodes
-
-
Constructor Details
-
RootDirectoryBasedLocaleContextResolver
public RootDirectoryBasedLocaleContextResolver()
-
-
Method Details
-
getRootDirectory
@Contract(pure=true) @NonNull private static @NonNull String getRootDirectory(@NonNull @NonNull jakarta.servlet.http.HttpServletRequest request) Determines the top-level directory denoted by the URL path of the request. For example,
/en/benutzer/@jasonreturnsen/räumereturnsräume/admin/benutzerreturnsadmin.
- Parameters:
request- The request whose URL path's root directory shall be determined.- Returns:
- The top-level directory of the URL path.
-
resolveLocale
@Contract(pure=true) @NonNull public @NonNull Locale resolveLocale(@NonNull @NonNull jakarta.servlet.http.HttpServletRequest request) Determines the appropriate
Localethat shall be used to translate the resource requested. The locale is determined based on the presence of a language code as the root directory of the URL path requested.If no language code is present or if the language is not supported, the default locale is used instead.
All headers, cookies, URL parameters etc. are completely ignored.
- Specified by:
resolveLocalein interfaceorg.springframework.web.servlet.LocaleResolver- Parameters:
request- The request for which the correct language shall be determined.- Returns:
- The language appropriate for the request.
-
setLocale
@Contract(pure=true) public void setLocale(@NonNull @NonNull jakarta.servlet.http.HttpServletRequest request, @Nullable @Nullable jakarta.servlet.http.HttpServletResponse response, @Nullable @Nullable Locale locale) throws UnsupportedOperationException Warning
Always throws
UnsupportedOperationException! This is because the locale appropriate for a request depends only on the URL path and not on anything else.- Specified by:
setLocalein interfaceorg.springframework.web.servlet.LocaleResolver- Parameters:
request- Ignored.response- Ignored.locale- Ignored.- Throws:
UnsupportedOperationException- Always!
-
setDefaultLocale
Alias forLocale.setDefault(Locale).- Parameters:
locale- The new standard language if no other language is determined as appropriate.
-