2

Is it possible to set the language attribute of apex:page via javascript? I actually tried this but I'm not getting the expected result. Example:

<apex:page language="<script>getURL(decodeURIComponent(location.href))</script>" applyHtmlTag="false" showHeader="false" docType="html-5.0" cache="false" >

location.href has query string which value is encoded, and the language is part of the encoded string. getURL() is my javascript function to get the value of language.

I tried removing the script tag, but still has no luck:

language="getURL(decodeURIComponent(location.href))"

I understand that this can be achieved via controller, but that is what I'm trying to avoid since there's lot of process when dealing with controller.

Thanks in advance!

  • 1
    You cannot use javascript for this. Javascript is interpreted in the browser, i.e. it "runs" only after the html output has been delivered from server to your browser. Having that in mind, you must notice that your getURL will execute only (so to say) on your computer, it will not tell the server to render the page/component with specific language. What you must do is retrieve language through the controller and bind it to the page. – dino ursic Dec 20 '13 at 10:55
2

You can instead use global variables for your requirements

$CurrentPage.parameters.parameterName

so if your parameter name is lang

you can use

<apex:page language="{!$CurrentPage.parameters.lang}" applyHtmlTag="false" showHeader="false" docType="html-5.0" cache="false" >

Once you access from URL i think the global variable will be automatically decoded.

| improve this answer | |
  • Thank you Mohith. But the thing is, the query string is encoded. So to decode it, i want to use javascript instead of going through controller. – user3734 Dec 20 '13 at 6:18
  • 1
    @user3734 Page language has to be determined server-side, for example because it decides on field labels, custom labels... JS is not running at that point (imagine how stupid it would look if page starts to render in English, blinks and JS replaces all texts with say French). Decode the lang earlier (when you construct the link, not when you hit the page) or update the question with a sample link, maybe we'll figure something out with with functions from help.salesforce.com/apex/… – eyescream Dec 20 '13 at 8:13
  • @eyescream thank you so much for clearing that up, makes a lot of sense. I think I'll just have to go through the controllers then. – user3734 Jan 2 '14 at 5:05

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.