Package com.vaadin.flow.i18n
Class TranslationFileRequestHandler
java.lang.Object
com.vaadin.flow.server.SynchronizedRequestHandler
com.vaadin.flow.i18n.TranslationFileRequestHandler
- All Implemented Interfaces:
RequestHandler,SessionExpiredHandler,Serializable
public class TranslationFileRequestHandler
extends SynchronizedRequestHandler
implements SessionExpiredHandler
Handles translation file requests. Translation file requests are internal
requests sent by the client-side to retrieve the translation file for the
specified language tag. The response contains the translations in JSON
format. Also, the language tag of the retrieved translation file is included
as a header with the name
X-Vaadin-Retrieved-Locale. The language tag
parameter langtag supports both dash and underscore as separators.
The translation file to return is determined by matching the requested locale to the available bundles with the following prioritization order:
- Exact match
- Language and country match
- Language match
- Default bundle (root bundle)
For internal use only. May be renamed or removed in a future release.
- Since:
- 24.4
- Author:
- Vaadin Ltd
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class com.vaadin.flow.server.SynchronizedRequestHandler
SynchronizedRequestHandler.ResponseWriter -
Field Summary
Fields inherited from class com.vaadin.flow.server.SynchronizedRequestHandler
MAX_BUFFER_SIZE -
Constructor Summary
ConstructorsConstructorDescriptionTranslationFileRequestHandler(I18NProvider i18NProvider, ClassLoader classLoader) -
Method Summary
Modifier and TypeMethodDescriptionprotected booleancanHandleRequest(VaadinRequest request) Check whether a request may be handled by this handler.booleanhandleSessionExpired(VaadinRequest request, VaadinResponse response) Handles translation file requests when the session has expired or does not exist.booleansynchronizedHandleRequest(VaadinSession session, VaadinRequest request, VaadinResponse response) Identical toSynchronizedRequestHandler.handleRequest(VaadinSession, VaadinRequest, VaadinResponse)except theVaadinSessionis locked before this is called and unlocked after this has completed.Methods inherited from class com.vaadin.flow.server.SynchronizedRequestHandler
getRequestBody, handleRequest, isReadAndWriteOutsideSessionLock, synchronizedHandleRequestMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.vaadin.flow.server.RequestHandler
handleRequest
-
Constructor Details
-
TranslationFileRequestHandler
-
-
Method Details
-
synchronizedHandleRequest
public boolean synchronizedHandleRequest(VaadinSession session, VaadinRequest request, VaadinResponse response) throws IOException Description copied from class:SynchronizedRequestHandlerIdentical toSynchronizedRequestHandler.handleRequest(VaadinSession, VaadinRequest, VaadinResponse)except theVaadinSessionis locked before this is called and unlocked after this has completed.- Specified by:
synchronizedHandleRequestin classSynchronizedRequestHandler- Parameters:
session- The session for the requestrequest- The request to handleresponse- The response object to which a response can be written.- Returns:
- true if a response has been written and no further request handlers should be called, otherwise false
- Throws:
IOException- If an IO error occurred- See Also:
-
handleSessionExpired
public boolean handleSessionExpired(VaadinRequest request, VaadinResponse response) throws IOException Handles translation file requests when the session has expired or does not exist. Since translations are stateless (they only depend on theI18NProviderand locale), they can be served without requiring an active session.- Specified by:
handleSessionExpiredin interfaceSessionExpiredHandler- Parameters:
request- the request to handleresponse- the response object to which a response can be written- Returns:
trueif the request was handled,falseif this handler does not handle the given request type- Throws:
IOException- if an IO error occurred
-
canHandleRequest
Description copied from class:SynchronizedRequestHandlerCheck whether a request may be handled by this handler. This can be used as an optimization to avoid locking the session just to investigate some method property. The default implementation just returnstruewhich means that all requests will be handled by callingSynchronizedRequestHandler.synchronizedHandleRequest(VaadinSession, VaadinRequest, VaadinResponse)with the session locked.- Overrides:
canHandleRequestin classSynchronizedRequestHandler- Parameters:
request- the request to handle- Returns:
trueif the request handling should continue once the session has been locked;falseif there's no need to lock the session since the request would still not be handled.
-