I have a force.com site with many Visualforce pages in it. I want to convert those pages into different languages (Ex: Spanish) based on the Locale of the user who has logged in.

Our force.com site sign-up page has "Locale" as user input field. So, planning to change the site content based on this field. Ideally, we would check the Locale and then translate the VF pages into that language for that logger in user.

We have enabled translation workbench (and activated the required languages).

What I want to know is how to proceed further, how will the page be translated? So, all my VF pages code (or apex class) should be changed to check for the Locale? What should be written in the "IF" condition? Lets say,

if(locale__c=='Spanish') { 
      //what should I do here?

I don't think, this is the right way of doing. Is there an easier way? I should use this code in all the pages/controllers?

What should be my next steps? Please let me know.

  • I think translation workbench is meant to be used with labels and the users language. In your case I would redirect to a different VF page for each language.
    – David Renz
    Commented Jul 21, 2014 at 7:16
  • Thanks for the reply. What should different VF pages contain? Same text in different languages? So I translate the whole content in different languages by myself?
    – sfdcFanBoy
    Commented Jul 21, 2014 at 7:23
  • The translation workbench has no automated translation also.
    – David Renz
    Commented Jul 21, 2014 at 7:28
  • Ok. About the custom labels- I have created a custom label. What should be the "Translation text" contain for a custom label? Any idea?
    – sfdcFanBoy
    Commented Jul 21, 2014 at 7:32
  • "This text overrides the value specified in the label's Value field when a user's default language is the translation language." - help.salesforce.com/…
    – David Renz
    Commented Jul 21, 2014 at 7:36

1 Answer 1


You could use the language attribute of the VF page:

<apex:page language="es">
    <apex:outputText value="{!$Label.Foo}">

            <apex:outputField value="{!Account.BillingStreet}"/>

The label Foo and the fieldlabel for the Billing Street are in spanish then. Of course you must provide a spanish translation for the custom label.

The language attribute does accept ISO country codes plus an optional locale like

  • en
  • en_US
  • de
  • de_DE

You may also refer to a variable in order to set the locale dynamically:

<apex:page language="{!lang}">

This should allow you to write a VF page only once and use the platform specific translation mechanisms to translate all texts and labels.

  • Thanks. Wonderful. I get it now. I'm also using tag <apex:pageMessages /> to display the standard error messages in my VF page, how to deal with this?
    – sfdcFanBoy
    Commented Jul 21, 2014 at 8:44
  • I think the page messages are automatically translated in the users language.
    – David Renz
    Commented Jul 21, 2014 at 8:52
  • @BruceLee Messages generated by the system (e.g. from validation rules) are or can be translated at the workbench. For your own messages, i suggest to also work with custom labels e.g. ApexPages.addMessage(Label.MyMessage); Commented Jul 21, 2014 at 9:31
  • Yes, I tried. The standard messages are translated directly. For custom ones, I will use Labels. Thanks a lot everyone! Cheers
    – sfdcFanBoy
    Commented Jul 21, 2014 at 9:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .