[SalesForce] Translate picklist value in PageBlock title

We are using

<apex:pageBlock title="{account.MyField__c}">

where MyField is a picklist with the corresponding translations. The problem is that the picklist value is not translated to the user's language. From here I found that including raw picklist fields in VF doesn't get translated and that we should use apex:outputField. But I can't find a way of using it inside the pageBlock title attribute.

Any ideas on how to get the translation inside the title?

Best Answer

This might do the trick:

Schema.DescribeFieldResult F = Account.MyField__c.getDescribe(); 
List<Schema.PicklistEntry> P = F.getPicklistValues(); 
Map<String, String> mapMyFieldTranslation = new Map<String, String>(); 

for(Schema.PicklistEntry e : P){
    mapMyFieldTranslation.put(e.value, e.label); 
}

String result = mapMyFieldTranslation.get(myAccount.MyField__c));

With 'result' containing the translation.

Related Topic