org.apache.struts2.interceptor

## Class I18nInterceptor

- java.lang.Object
- - org.apache.struts2.interceptor.AbstractInterceptor
  - - com.opensymphony.xwork2.interceptor.AbstractInterceptor
    - - org.apache.struts2.interceptor.I18nInterceptor

- All Implemented Interfaces:
    Serializable, ConditionalInterceptor, Interceptor

      public class I18nInterceptor
      extends AbstractInterceptor

  An interceptor that handles setting the locale specified in a session as the locale for the current action request.
  See Also:
    Serialized Form

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `protected class` | `I18nInterceptor.AcceptLanguageLocaleHandler`
    `protected class` | `I18nInterceptor.CookieLocaleHandler`
    `protected static interface` | `I18nInterceptor.LocaleHandler` Uses to handle reading/storing Locale from/in different locations
    `protected class` | `I18nInterceptor.RequestLocaleHandler`
    `protected class` | `I18nInterceptor.SessionLocaleHandler`
    `protected static class` | `I18nInterceptor.Storage`

    - ### Nested classes/interfaces inherited from interface com.opensymphony.xwork2.interceptor.ConditionalInterceptor

      `ConditionalInterceptor.LegacyAdapter`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected String` | `attributeName`
    `static String` | `DEFAULT_COOKIE_ATTRIBUTE`
    `static String` | `DEFAULT_COOKIE_PARAMETER`
    `static String` | `DEFAULT_PARAMETER`
    `static String` | `DEFAULT_REQUEST_ONLY_PARAMETER`
    `static String` | `DEFAULT_SESSION_ATTRIBUTE`
    `protected LocaleProviderFactory` | `localeProviderFactory`
    `protected String` | `parameterName`
    `protected String` | `requestCookieParameterName`
    `protected String` | `requestOnlyParameterName`
    `protected I18nInterceptor.Storage` | `storage`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `I18nInterceptor()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected Parameter` | `findLocaleParameter(ActionInvocation invocation, String parameterName)`
    `protected Locale` | `getLocaleFromParam(String requestedLocale)` Creates a Locale object from the request param
    `protected I18nInterceptor.LocaleHandler` | `getLocaleHandler(ActionInvocation invocation)` Override this method to use your own implementation of `I18nInterceptor.LocaleHandler`
    `String` | `intercept(ActionInvocation invocation)` Override to handle interception
    `protected boolean` | `isLocaleSupported(Locale locale)`
    `void` | `setAttributeName(String attributeName)`
    `void` | `setLocaleProviderFactory(LocaleProviderFactory localeProviderFactory)`
    `void` | `setLocaleStorage(String storageName)`
    `void` | `setParameterName(String parameterName)`
    `void` | `setRequestCookieParameterName(String requestCookieParameterName)`
    `void` | `setRequestOnlyParameterName(String requestOnlyParameterName)`
    `void` | `setSupportedLocale(String supportedLocale)` Sets supported Locales by the application
    `protected void` | `useLocale(ActionInvocation invocation, Locale locale)` Save the given locale to the ActionInvocation.

    - ### Methods inherited from class com.opensymphony.xwork2.interceptor.AbstractInterceptor

      `intercept, shouldIntercept, shouldIntercept`

    - ### Methods inherited from class org.apache.struts2.interceptor.AbstractInterceptor

      `destroy, init, setDisabled`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface com.opensymphony.xwork2.interceptor.ConditionalInterceptor

      `adapt`

    - ### Methods inherited from interface com.opensymphony.xwork2.interceptor.Interceptor

      `adapt`

    - ### Methods inherited from interface org.apache.struts2.interceptor.Interceptor

      `destroy, init`

- - ### Field Detail

    - #### DEFAULT_SESSION_ATTRIBUTE

          public static final String DEFAULT_SESSION_ATTRIBUTE

      See Also:
        Constant Field Values

    - #### DEFAULT_PARAMETER

          public static final String DEFAULT_PARAMETER

      See Also:
        Constant Field Values

    - #### DEFAULT_REQUEST_ONLY_PARAMETER

          public static final String DEFAULT_REQUEST_ONLY_PARAMETER

      See Also:
        Constant Field Values

    - #### DEFAULT_COOKIE_ATTRIBUTE

          public static final String DEFAULT_COOKIE_ATTRIBUTE

      See Also:
        Constant Field Values

    - #### DEFAULT_COOKIE_PARAMETER

          public static final String DEFAULT_COOKIE_PARAMETER

      See Also:
        Constant Field Values

    - #### parameterName

          protected String parameterName

    - #### requestOnlyParameterName

          protected String requestOnlyParameterName

    - #### attributeName

          protected String attributeName

    - #### requestCookieParameterName

          protected String requestCookieParameterName

    - #### storage

          protected I18nInterceptor.Storage storage

    - #### localeProviderFactory

          protected LocaleProviderFactory localeProviderFactory

  - ### Constructor Detail

    - #### I18nInterceptor

          public I18nInterceptor()

  - ### Method Detail

    - #### setParameterName

          public void setParameterName(String parameterName)

    - #### setAttributeName

          public void setAttributeName(String attributeName)

    - #### setRequestOnlyParameterName

          public void setRequestOnlyParameterName(String requestOnlyParameterName)

    - #### setRequestCookieParameterName

          public void setRequestCookieParameterName(String requestCookieParameterName)

    - #### setLocaleStorage

          public void setLocaleStorage(String storageName)

    - #### setSupportedLocale

          public void setSupportedLocale(String supportedLocale)

      Sets supported Locales by the application
      Parameters:
        `supportedLocale` - a comma separated list of supported Locale

    - #### isLocaleSupported

          protected boolean isLocaleSupported(Locale locale)

    - #### setLocaleProviderFactory

          public void setLocaleProviderFactory(LocaleProviderFactory localeProviderFactory)

    - #### intercept

          public String intercept(ActionInvocation invocation)
                           throws Exception

      Description copied from class: `AbstractInterceptor`
      Override to handle interception
      Specified by:
        `intercept` in class `AbstractInterceptor`
      Throws:
        `Exception`

    - #### getLocaleHandler

          protected I18nInterceptor.LocaleHandler getLocaleHandler(ActionInvocation invocation)

      Override this method to use your own implementation of `I18nInterceptor.LocaleHandler`
      Parameters:
        `invocation` - current action invocation context
      Returns:
        instance of `I18nInterceptor.LocaleHandler`

    - #### getLocaleFromParam

          protected Locale getLocaleFromParam(String requestedLocale)

      Creates a Locale object from the request param
      Parameters:
        `requestedLocale` - the parameter from the request
      Returns:
        instance of `Locale` or null

    - #### findLocaleParameter

          protected Parameter findLocaleParameter(ActionInvocation invocation,
                                                  String parameterName)

    - #### useLocale

          protected void useLocale(ActionInvocation invocation,
                                   Locale locale)

      Save the given locale to the ActionInvocation.
      Parameters:
        `invocation` - The ActionInvocation.
        `locale` - The locale to save.

Copyright © 2000–2026 Apache Software Foundation. All rights reserved.