2
<apex:page id="thepage" controller="PageController1" language="{!IF(ISNULL(language),'en_US',language)}">
    <apex:form id="theform">
            <apex:commandlink action="{!changeEnglish}" rerender="thepage" value="English"/><br/>
<br/><br/>
        <apex:commandlink action="{!changeFrench}" rerender="thepage" value="French"/><br/><br/><br/>



        <apex:outputLabel value="{!$Label.french}" rendered="true" onclick="changeEnglish();"/><br/>
        <apex:outputLabel value="{!$Label.english}" rendered="true" onclick="changeFrench();"/><br/><br/><br/><br/>
        Text of page here
    </apex:form>
</apex:page>

Controller:

public with sharing class PageController1 {
public string language {get;set;}
public boolean isFrench {get;set;}

public void changeFrench(){
    language = 'fr';
     isFrench = true;
}

public void changeEnglish(){
    language = 'en_US';
        isFrench = false;

}

}

if i click on french only french language must appear from custom labels. by default english must enable?? how can i achieve it

1 Answer 1

1

This controller and page will do the language switching. I think the re-rendering you have specified is getting in the way; returning null from the action causes the entire page to refresh in any case which is what is needed.

public with sharing class MyController {

    public String language {get;set;}

    public PageReference toFrench() {
        language = 'fr';
        return null;
    }

    public PageReference toEnglish() {
        language = 'en_US';
        return null;
    }

    public MyController() {
        toEnglish();
    }
}

<apex:page language="{!language}" controller="MyController">
    <apex:form>
       <apex:commandlink action="{!toEnglish}" value="English"/>
       <br/>
       <apex:commandlink action="{!toFrench}" value="French"/>
       <br/>
       {!language}
       <br/>
       {!$ObjectType.Opportunity.label}
    </apex:form>
</apex:page>

(This is making use of the apex:page language attribute which takes precedence over the language defined for the user. In this example the only text that will change is the opportunity object label.)

You must log in to answer this question.

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