Adding Custom I18N Strings

Document created by resplin Employee on Jun 6, 2015
Version 1Show Document
  • View in full screen mode

Obsolete Pages{{Obsolete}}

The official documentation is at: http://docs.alfresco.com



Web Client Customization


Introduction


Alfresco 1.3 introduced a mechanism allowing you to include custom I18N strings.  Previously webclient.properties would have to be changed and then re-merged when you upgraded.

A webclient.properties file can now be placed in the alfresco.extension package. This will be automatically picked up by the web client, except for messages displayed via JSF message tags directly in JSPs.




Using custom strings in JSPs


If you want to use a custom string in any of your JSPs then the options include:


Option 1


The standard JSF mechanism can be used to load your custom bundle, for example add the following line to the top of your custom JSP page:



<f:loadBundle basename='alfresco.extension.webclient' var='yourMsgs'/>

This will make your strings available via the yourMsgs variable. For example, if you have a custom string with a key of custom_string, you can output that string in your JSP by using the code below.



<h:outputText value='#{yourMsgs.custom_string}' />

There is an example showing this approach in the Customising An Alfresco JSP example.


Option 2


It is also possible to use Application.getMessage() which will load 'alfresco.messages.webclient' and 'alfresco.extension.webclient' resource bundles.




You can output a custom_string (defined in your custom version of the webclient.properties file) in your JSP by using the code below.



<r:loadBundle var='msgs'/>

You can output a custom_string (defined in your custom version of the webclient.properties file) in your JSP by using the code below.



<h:outputText value='#{yourMsgs.custom_string}' />

Note: In order to support dynamic web client properties the ResourceBundleWrapper will now order the resource bundles such that the repository extension (ie. /Company Home/Data Dictionary/Web Client Extension/webclient.properties) is searched first (if available) before the standard webclient.properties. This enables existing strings to be customised (for example, in a multi-tenant environment) in addition to adding new custom strings.


Using custom strings in configuration & beans


When we refer to I18N strings in configuration files or programtically via the Application.getMessage() call the standard webclient.properties and your custom webclient.properties (if present) are loaded.

For example, if you have a custom string with a key of custom_string, you could use it as the label for a property as follows:



<config>
   <property-sheet>
      <show-property name='name' display-label-id='custom_string' />
   </property-sheet>
</config>

Or if you want to refer to the string in your beans, for example as the label of the finish button in a dialog:



public String getFinishButtonLabel()
{
   return Application.getMessage(FacesContext.getCurrentInstance(), 'custom_string');
}




Defining custom Message properties files (from Alfresco Labs 3 onwards)


You basically have 2 different beans dealing with messages:



  1. org.alfresco.i18n.ResourceBundleBootstrapComponent

  2. This is the normal Alfresco one (loading system-messages, dictionary-messages etc).
    It is defined and configured inside:

    WEB-INF/classes/alfresco/core-services-context.xml


  3. org.alfresco.web.app.ResourceBundleBootstrap

  4. This is the one used by the Webclient, but it is not defined anywhere.
    It is used by org.alfresco.web.app.ResourceBundleWrapper, which serves as
    an entry point for getting Webclient messages.


So, if you want to use another message properties file in the Webclient than webclient.properties, you need to define a bean using the
org.alfresco.web.app.ResourceBundleBootstrap.

In order to do so, you can create a file :

WEB-INF/classes/alfresco/extension/custom-webclient-context.xml

contents:



<beans>

   <bean id='resourceBundlesWebApp' class='org.alfresco.web.app.ResourceBundleBootstrap'>
      <property name='resourceBundles'>
         <list>
             <value>alfresco.extension.custom-webclient</value>
         </list>
      </property>      
   </bean>
  
  
</beans>


And then put you're properties into:

WEB-INF/classes/alfresco/extension/custom-webclient.properties

If you add a line to log4j.properties, you should see you're resource bundle loaded
in the logs :

log4j.logger.org.alfresco.web.app.ResourceBundleWrapper=debug



Inside a jsp file, you still need to reference it directly:



<f:loadBundle basename='alfresco.extension.custom-webclient' var='customMsg'/>

Attachments

    Outcomes