Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to assign the language dynamically in a Visualforce page which I have specified in controller. Right now it is hard coded as

<apex:page language="de">

Is it possible to achieve this via global variables?

<apex:page controller="controller_1" Language="{!code}" >
 <apex:form >
  <apex:inputTextarea value="{!test}"/>

public class controller_1{
    public String test {get; set;}
    public String code {get; set;}

    public controller_1()
      code ='de';     
      Schema.DescribeFieldResult f = Schema.sObjectType.Lead.fields.Company;
      test = f.getLabel();
share|improve this question
You can use Custom Labels, where you can add translations for each language supported. Based on the User's language, the corresponding translation from the Custom Label will be displayed. – techtrekker Feb 14 '13 at 10:35

Yes, you can do that in your apex:page tag, by using the attribute language, then dynamically bind it to a value in your controller or extension:

<apex:page Controller="PageController" language="{!code}">

From the documentation: The language used to display labels that have associated translations in Salesforce. This value overrides the language of the user viewing the page. Possible values for this attribute include any language keys for languages supported by Salesforce, for example, "en" or "en-US".

share|improve this answer
I have tried <apex:page Controller="PageController" language="{!code}"> already, But It is not working for the value in inputTextarea. – Vids Feb 14 '13 at 11:11
that's kind of normal, you don't translate the values IN fields (except from picklist values, which you can translate iirc) you can only translate the field labels, custom labels, objects, ... not the data itself in the translation workbench. – pjcarly Feb 14 '13 at 11:17
Of course it won't. The language will affect "only" field names, picklist values, custom labels etc. Any data (content entered by users into textareas) will remain exactly as is. Are you saying you expect some kind of automatic Google Translate for your data? – eyescream Feb 14 '13 at 11:21
When I am giving <apex:page Controller="PageController" language="de">, It is translating the values IN fields But not when <apex:page Controller="PageController" language="{!code}">. And yes I am expecting some kind of automatic translation functionality. Is there any suggestion? – Vids Feb 14 '13 at 12:21
@user2406 can you add some sample code to your question that works with 'de' and doesn't work with '{!code}'. – Greg Grinberg Feb 14 '13 at 15:36

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.