I have created a custom picklist field, and have added values for different languages using translation workbench. We have a requirement to display the field on a VF page for a specified language. We also have a requirement to use VF dynamic components. When I use the "language" attribute directly on the VF page, this works perfectly.
VF Page:
<apex:page controller="setranstest" language="fr" showHeader="false" sidebar="false">
<apex:outputPanel >
<apex:dynamicComponent componentValue="{!DynamicText}" invokeAfterAction="true"/>
</apex:outputPanel>
</apex:page>
Apex Class:
public class setranstest {
public Case casex {get;set;}
public setranstest() {
casex = [select Id,toLabel(CEC_Case_Category__c) from Case where Id = '500Dh00000Db4xMIAR'];
}
public Component.Apex.OutputText getDynamicText() {
Component.Apex.OutputText outx = new Component.Apex.OutputText();
outx.expressions.value = 'The category is:{!casex.CEC_Case_Category__c}';
outx.escape = false;
return outx;
}
}
Output:
The category is:Bonjour
Now we then try to make the language dynamic, based on a variable in the Apex controller.
VF Page:
<apex:page controller="setranstest" language="{!specifiedLanguage}" showHeader="false" sidebar="false">
<apex:outputPanel >
<apex:dynamicComponent componentValue="{!DynamicText}" invokeAfterAction="true"/>
</apex:outputPanel>
</apex:page>
Apex Class:
public class setranstest {
public Case casex {get;set;}
public string specifiedLanguage {get;set;}
public setranstest() {
specifiedLanguage = 'fr';
casex = [select Id,toLabel(CEC_Case_Category__c) from Case where Id = '500Dh00000Db4xMIAR'];
}
public Component.Apex.OutputText getDynamicText() {
Component.Apex.OutputText outx = new Component.Apex.OutputText();
outx.expressions.value = 'The category is:{!casex.CEC_Case_Category__c}';
outx.escape = false;
return outx;
}
}
Output:
The category is:Hello
So the question is, why the discrepancy? Why does the picklist value get translated correctly when the language is hard coded, but not get translated correctly when we try and do it dynamically? This looks like a SF bug, and according to this post, it's been around for at least 11 years.