The Silver Lining

Lessons & Learnings from a salesforce certified technical architect.

Dynamic Custom Labels

with one comment

I know what you’re thinking, ‘this is cRAzY talk’. But do not doubt my friend, Salesforce has a very powerful translation framework.

Besides being able to change the language used by the Salesforce standard areas with the flick of a picklist, you can include translatable Custom Labels in most of your custom application. To do this you will need to request that the ‘Translation Workbench’ feature be enable for you Salesforce development environment, after which you will find new areas in your ‘Setup’ menu.

Post enablement you can then create a Custom Labels and include them where necessary within your code. This can be done within a VisualForce page like so


<apex:outputText value="{!$Label.customlabel}"/>

or within your Apex code thus


String err_message = System.Label.customlabel;

This in itself is awesomesauce, but you can further leverage this power by capturing what I like to call tokens within the Custom Label text e.g.

You need a translatable Custom Label that outputs some dynamically created value so you capture the text as:

There are currently {0} accounts outstanding.

You can now dynamically populate the token with a value retrieved by some method by doing the following within your page:

<apex:outputText value="{!$Label.customlabel}">

	<apex:param value="{!value}"/>

</apex:outputText>

When the page is displayed it will then display the appropriate value within the text field. Should you need more tokens within your label, simply include more curly braced tokens with the values being consecutively increasing integers. Simple yet powerful. Brings a tear to the eye.

Advertisements

Written by Wes

June 10, 2009 at 5:11 pm

One Response

Subscribe to comments with RSS.

  1. […] Dynamic Custom Labels – Part 2 By Wes Leave a Comment Categories: SalesForce, VisualForce and force.com Tags: custom labels, dynamic, force.com, VisualForce Quite recently I came across an interesting forum post by XactiumBen that mentioned some awesomesauce abilities of params in outputTexts. I’ve written an article detailing the basics of this functionality, and thought I’d document these advanced capabilities too. For anyone interested you can read Part 1 here. […]


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: