Monday, January 14, 2013

How to disable localization in Alfresco Share

If you have the requirement that Alfresco Share should be available in only one single language then this is not that trivial. By default Alfresco Share takes the web browser language into account. There is out of the box no way to choose the language. This post describes how to set the language to just the English one. What you need to know is that there is a Spring Bean with the Id 'localeResolver'. So we need to override the Bean by using an own implementation of it.If you do not know the Spring framework, then what you need to know at this point is that you can configure Java Classes as Beans by using XML. An instance of the Class is then available via the Spring Context. So you get get an instance of the Class by asking the Spring Context for a Bean with a specific id. It's possible to have multiple instances with different id-s and parameters. So a lot of stuff  in Alfresco is accessible via Spring Beans. If something is available via the above mentioned context, then you can just override it. This changes Alfresco's default behavior. The reason why it works is that the custom configuration becomes loaded later than the original configuration and so the original Spring Bean definition becomes overridden. Here the steps:
  1. In '${TOMCAT_HOME}/shared/classes/alfresco/web-extension' create a context file by naming it to 'custom-slingshot-application-context.xml'. I believe the only important thing here is that it ends with '-context.xml'.
  2. In this file define a Spring Bean by using the following code:
 <?xml version='1.0' encoding='UTF-8'?>
<beans xmlns=""
        <bean id='localeResolver' class='de.ecmgeek.alfresco.MyLocaleResolver'/>

Now you can just implement your own LocaleResolver and put it to the classpath (E.G. as a JAR file):

package de.ecmgeek.alfresco;

import java.util.Locale;
import javax.servlet.http.HttpServletRequest;

public class MyLocaleResolver extends LocaleResolver
    public Locale resolveLocale(HttpServletRequest request)

        /* Here we could set the locale by getting the value of the 

           cookie with the name ALFRESCO_UI_PREFLANG or by handling

           a request parameter. For now this value is just null. */

        Locale locale = null;
        if (locale == null)

            //To set a constant value

            locale = I18NUtil.parseLocale("en_EN");




        return locale;

No comments:

Post a Comment