Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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">
........
</apex:page>

Is it possible to achieve this via global variables?

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

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
1  
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

1 Answer 1

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".

http://www.salesforce.com/us/developer/docs/pages/Content/pages_compref_page.htm

share|improve this answer
    
I have tried <apex:page Controller="PageController" language="{!code}"> already, But It is not working for the value in inputTextarea. –  Vidula Feb 14 '13 at 11:11
2  
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. –  PJC Feb 14 '13 at 11:17
1  
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? –  Vidula 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

 
discard

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.