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
Praveen Kumar 212Praveen Kumar 212 

Changing Language of <apex:outputlabel>

I am trying to change language of outputlabel using apex:page language attribute and picklist, but its not working. Help needed please!.
VF
<apex:page language="{!lang}" controller="Language" >
 <apex:form >
 
 <apex:selectList value="{!langlist}" size="1">
     <apex:actionSupport event="onchange" action="{!change}"/>
     <apex:selectOptions value="{!selectlang}"/>
    </apex:selectList>
  <apex:pageBlock >
  
   <apex:pageBlockSection >
   <apex:pageblockSectionItem >
    <apex:outputLabel value="{!$ObjectType.Amenity__c.label}"></apex:outputLabel>
    <apex:inputtext value="{!name}"/>
    </apex:pageblockSectionItem><br/>
    <apex:pageBlockSectionitem >
    <apex:outputLabel value="{!$ObjectType.Amenity__c.label}"></apex:outputLabel>
    <apex:inputtext value="{!email}"/>
    </apex:pageBlockSectionitem>
    
   </apex:pageBlockSection>
  </apex:pageBlock>
 </apex:form>
</apex:page>

Controller
 
public with sharing class Language {

    public String lang {get; set;}

    public String selectlang { set; }
    
    public List<selectoption> getselectlang(){
    
     List<selectoption> opt = new List<selectoption>();
     
     opt.add(new selectoption('None','None'));
     opt.add(new selectoption('English','English'));
     opt.add(new selectoption('Japanese','Japanese'));
     opt.add(new selectoption('Urdu', 'Urdu'));
     
     return opt;
    
    }

    public PageReference change() {
    
    if(langlist == 'English')
     {
    
       lang='en';
     
     } else if (langlist=='Japanese')
       {
     
         lang='ja';
         
       } else if(langlist=='Urdu')
       
        {
        
         lang='ur';
         
        }
        return null;
    }


    public String langlist { get; set; }

    public String email { get; set; }

    public String name { get; set; }
}

 
Gaurav KheterpalGaurav Kheterpal
Have you tried hardcoding this to a different language once to see if that works?

If my answer helps resolve your query, please mark it as the 'Best Answer' & upvote it to benefit others and improve the overall quality of Discussion Forums.

Gaurav Kheterpal
Certified Force.com Developer| Salesforce Mobile Evangelist| Developer Forums Moderator| Dreamforce Speaker