I got lost here with an issue when I try to achieve a case which a user can click on a button and change the language of a form in visual force page.

I know a way which works but don't support IE browsers -( which is kind of a problem for my users) with the URLSearchParams JS method.

The second way I tried is to put the language param for the apex:page :

language="{!$CurrentPage.parameters.lang}" :

<apex:page id="formPageId" controller="PaymentFormController" docType="html-5.0" showHeader="false" standardStylesheets="false" language="{!$CurrentPage.parameters.lang}">

and then, to get the lang param with js function and set it to the value that clicked.

for Example :

const param = new URL(location.href).searchParams;

My issue here is when I try to refresh the page with my new url (new param that i just had changed).

Anyone have any idea or a better way to do so?



Why not use action:function to pass language param in URL and re-render whole page by providing id to the page? I have provided page with id formPageId and re-rendering in action function.

<apex:page id="formPageId" controller="PaymentFormController" docType="html-5.0" showHeader="false" standardStylesheets="false" language="{!$CurrentPage.parameters.lang}" >

        <!-- Define the JavaScript function sayHello-->
        <apex:actionFunction name="changeLanguage" action="{!changeLanguageApex}" rerender="formPageId" status="myStatus">
             <apex:param id="lang" name="lang" value="" />

        function onbuttonClick() {

    <button type="button" onclick="onbuttonClick()">Change Language</button>


public class PaymentFormController{

    public PageReference changeLanguageApex(){
        PageReference pageRef = ApexPages.currentPage();


       return pageRef;

  • Hi, Thanks, but now what? after I get the lang param inside the controller, how can I achieve the translations of all the custom labels and the labels of my objects inside the page?
    – Salvation
    Mar 12 '19 at 10:04
  • you are using re-render right? so page will auto re-render and get updated custom lable? Mar 12 '19 at 10:08
  • Yes I am, and also I'm using the language param : language="{!IF(ISNULL(lang),'en_US',lang)}".. but still its not change the lables..
    – Salvation
    Mar 12 '19 at 10:09
  • You have to refresh the page by passing lang param so that when lables are fetched again thy wil be translated, Mar 12 '19 at 10:33
  • Thanks! I had a mistake with my re render - Now Its working - not with a pageReference function but only with a {get;set;} param and action function.
    – Salvation
    Mar 31 '19 at 6:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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