function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
IceEngineIceEngine 

CustomLabel translations don't work in Visualforce component

Helloeveryone,

In my Visualforce component, neither in javascript

function SReason(pSelVal) {
  if (pSelVal == "{!$Label.VF_PGHELP_0001}") {...}

  nor in controller

ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, Label.Portal_LAB_MSG_0051));

the shown value is the customLabel default language, not the user language.

But In my Visualforce Page, the translation works fine.

 

here is the thing i'have done already, 

1. active languages at Translation Branch.

2. set user to the right language.

3. add translations at customLabel.

 

i also add the language attribute in the header:  language="{!displayLanguageCode}" but it doesn't help.

 

so is there anything goes wrong?

any help would be much appreciated!

 

Best Answer chosen by Admin (Salesforce Developers) 
IceEngineIceEngine

hello,
i don't really figure that out. 
my workaround is add an inputHidden field to hold the label value,

here is my code:

 

page:
<apex:inputHidden value="{!errMsg}" id="theErrMsg" />
<script> var theErrMsg = document.getElementById('{!$Component.theErrMsg}'); </script>
<apex:commandButton id="submit" value="Button_Name" action="{!dosomething}" onclick="theErrMsg.value='{!$Label.Portal_LAB_MSG_0051}';">

controller:
public String errMsg {get; set;}

 then this time, the controller get the right label value.

All Answers

nbknbk

Hello,

 

Are you able to get the language code from controller i.e {!displayLanguageCode}" , if yes it should translate in VFP.

 

one of your statement is 'But In my Visualforce Page, the translation works fine.' - so the problem only on Visual force component?

 

Please post the solution in the forum, it will help to every one who needs to implement similar requirement.

 

Thanks,

Krishna

WillybeanesWillybeanes

If possible I would like an update on this IceEngine?

 

Facing a similar issue as well.

IceEngineIceEngine

hello,
i don't really figure that out. 
my workaround is add an inputHidden field to hold the label value,

here is my code:

 

page:
<apex:inputHidden value="{!errMsg}" id="theErrMsg" />
<script> var theErrMsg = document.getElementById('{!$Component.theErrMsg}'); </script>
<apex:commandButton id="submit" value="Button_Name" action="{!dosomething}" onclick="theErrMsg.value='{!$Label.Portal_LAB_MSG_0051}';">

controller:
public String errMsg {get; set;}

 then this time, the controller get the right label value.

This was selected as the best answer