Acegi internationalization for apps without Spring DispatcherServlet

Acegi by default provides i18n support(For version 1.0.5, it supports Chinese,French, German and English). Unlike specified in the documentation(please read this before reading this post), you don’t need to specify explicit message source, unless you have existing MessageSource defined with id ‘messageSource’ or you need support for additional languages or both, in which case you need to copy acegi related keys from acegis files(which can be found under org.acegisecurity package) to your respective message bundles. AcegiMessageSource takes care of language bundles provided by default.

If you don’t provide message source, acegi classes use AcegiMessageSource through MessageSourceAccessor(Helper class which wraps MessageSource and provides overloaded getMessage methods). If you call one of the getMessage() method on MessageSourceAccessor with out Locale as argument, it tries to get message in default locale provided to it. If default locale is not set, then it tries to get Locale from LocaleContextHolder. But who sets Locale to the LocaleContextHolder? If you are using Spring DispatcherServlet for your requests,a LocaleResolver will do the job for you. For other apps you need to do this before authentication processing filters(For example, AuthenticationProcessingFilter) kicks in. Otherwise i18n won’t work.

In summary, you need to set the Locale to LocaleContextHolder, for apps not using DispatcherServlet, for Acegi’s localization to work. Let me know, if there are any workarounds or I am missing something here.