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
Jerun JoseJerun Jose 

Displaying multilingual error message in visualforce

Hi,

 

I am using a visualforce page in my project which also display some error messages to the users. I want to know if it is possible to change the text of the error message based on the current user's locale. Can we leverage the translational workbench for this? I'm guessing that

 

All inputs are welcome.

 

Thanks,

 

Jerun Jose

 

Best Answer chosen by Admin (Salesforce Developers) 
Eugene PozniakEugene Pozniak

You can use Custom Labels instead of a hardcoded text-message and translate it using the translational workbench.

 

e.g. apex-code:

ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, System.Label.Your_Label));

VF page:

<apex:pageMessage severity="warning" strength="2" summary="{!$Label.Your_Label}" />

To create Custom Label go to "App Setup" -> "Create" -> "Custom Labels".

 

Hope, it will be the answer on your question.

All Answers

SRKSRK

u can us

ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Record Not Saved'));

 

& on page use <apex:pagemessage attrubute>

Jerun JoseJerun Jose

Agree that we can use the pageMessages tag to display error messages.

My question was more on how can we modify the message displayed depending on the user's locale.

 

Say like, if an English user is logged in the message would be 'Record Not Saved', but if a French user logged in the message should be "Enregistrement n'est pas enregistré" (source google translate)

 

Thanks,

 

Jerun Jose

SRKSRK

Yes put try catch

Then in catch block check the user location & add what ever msg u want to add
catch(exception ex)

{
If(userlocat = 'india')

ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'India Error'));

else

ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Other Error'));

}

Eugene PozniakEugene Pozniak

You can use Custom Labels instead of a hardcoded text-message and translate it using the translational workbench.

 

e.g. apex-code:

ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, System.Label.Your_Label));

VF page:

<apex:pageMessage severity="warning" strength="2" summary="{!$Label.Your_Label}" />

To create Custom Label go to "App Setup" -> "Create" -> "Custom Labels".

 

Hope, it will be the answer on your question.

This was selected as the best answer
Jerun JoseJerun Jose

Thanks,

 

I couldnt find translation for custom label in admin setup -> translational workbench ->translate, so thats when I thought we cant translate custom labels and decided to post this question.

 

Your response got me looking further and its app setup->create->labels (pick ur label).

 

That should work.

 

Thanks,

 

Jerun Jose