+ Start a Discussion
the_wolfthe_wolf 

Multi language site - How to navigate from one page to another with same lang parameter?!

Hi all,

 

I have a site with a score of Visualforce pages. This site has 5 different languages and each page is set with custom labels as suggested in the guide in this link:


http://wiki.developerforce.com/index.php/An_Introduction_to_Force.com_Sites

under Multi Language Support section.

Each page contains many links and buttons that let you navigate from page to another. But how do I keep the same language parameter (example ?lang=fr) when this happens?

Thanks in advance

 

Best Answer chosen by Admin (Salesforce Developers) 
the_wolfthe_wolf

Hi all,

 

i used this function in my visualforce controller and it work correctly!

 

public class CookieController {


public CookieController() {
  
  // default value
  Cookie lang = ApexPages.currentPage().getCookies().get('lang');
   
    String attuale = ApexPages.currentPage().getParameters().get('lang');
    
    if (attuale == null) {} // do nothing
    else {
      if (attuale != String.valueOF(lang) && attuale != null){
   
        String actualLanguage = attuale;
        lang = new Cookie('lang', actualLanguage,null,-1,false);}
    }

// Set the new cookie for the page  
    
      ApexPages.currentPage().setCookies(new Cookie[]{lang});
      
}

public String getLang() {Cookie lang = ApexPages.currentPage().getCookies().get('lang');
    if(lang == null) {
        return 'it';
    }
    return lang.getValue();
}
}

All Answers

BulentBulent

you can leverage the two new features in summer10

1- cookie support: create a language switcher component that sets a language cookie value

2- url-rewriter: read the cookie value in the url rewriter class and and pass it as a parameter to the page and use it as a directory in your url. for example, http://xyz.force.com/page?lang=en  can be rewritten as http://xyz.force.com/en/page

the_wolfthe_wolf

Hi bulent,

 

thanks for reply. Can you provide me an example of language switcher component? Or a link where there is a guide for that?

 

Thanks again

the_wolfthe_wolf

Hi all,

 

i used this function in my visualforce controller and it work correctly!

 

public class CookieController {


public CookieController() {
  
  // default value
  Cookie lang = ApexPages.currentPage().getCookies().get('lang');
   
    String attuale = ApexPages.currentPage().getParameters().get('lang');
    
    if (attuale == null) {} // do nothing
    else {
      if (attuale != String.valueOF(lang) && attuale != null){
   
        String actualLanguage = attuale;
        lang = new Cookie('lang', actualLanguage,null,-1,false);}
    }

// Set the new cookie for the page  
    
      ApexPages.currentPage().setCookies(new Cookie[]{lang});
      
}

public String getLang() {Cookie lang = ApexPages.currentPage().getCookies().get('lang');
    if(lang == null) {
        return 'it';
    }
    return lang.getValue();
}
}
This was selected as the best answer
__sandra____sandra__

Hello,

 

This code is not working for me, can I have more explanantion please?

 

Thank you so much!