Class TranslationFileRequestHandler

java.lang.Object
com.vaadin.flow.i18n.TranslationFileRequestHandler
All Implemented Interfaces:
SessionlessRequestHandler, Serializable

public class TranslationFileRequestHandler extends Object implements SessionlessRequestHandler
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)

This is a SessionlessRequestHandler, so the I18NProvider is called without a VaadinSession: it gets the requested locale and must not depend on VaadinSession.getCurrent().

For internal use only. May be renamed or removed in a future release.

Since:
24.4
Author:
Vaadin Ltd
See Also:
  • Constructor Details

    • TranslationFileRequestHandler

      public TranslationFileRequestHandler(I18NProvider i18NProvider, ClassLoader classLoader)
  • Method Details

    • handleRequest

      public boolean handleRequest(VaadinRequest request, VaadinResponse response) throws IOException
      Handles translation file requests. Translations only depend on the I18NProvider and the requested locale, so they are served without a session.
      Specified by:
      handleRequest in interface SessionlessRequestHandler
      Parameters:
      request - the request to handle
      response - the response object to which a response can be written
      Returns:
      true if the request was handled, false if this handler does not handle the given request type
      Throws:
      IOException - if an IO error occurred