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
paul-lmipaul-lmi 

Setting label language in Apex

I have a VF page that uses custom labels, which are translated, and are properly localized when setting the page language via a URL param.  I also have a custom radio button list that uses labels for some of the values, which is created on the fly in the controller.  I'm running into an issue where the VF-included labels are properly grabbing the correct language translation, but the Apex-included labels are not.

 

So...howdo I override the controller itself to be using a specific language, rather than just the VF page?

 

In Apex, you can only call a label via System.Label.labelname , so it seems like it's completely dependent on the user's browsing/set language.  I need this for Sites, so I would like to ensure that the language param passed to the VF page overrides any SF magic/automation on language detection/setting.

paul-lmipaul-lmi
anyone?
eoateseoates
I'm having the exact same problem. Does anybody have a solution?
sfdcfoxsfdcfox
The only hint that I seem to have available is that you'd want to use the function toLabel() in order to translate values to the appropriate localization. This function is used inside of SOQL queries to get the localized value of picklists. I believe the Describe mechanisms also have a way to get the labels of picklist values in the correct (localized) language.
paul-lmipaul-lmi

hmmm

 

i'm already calling this with the $Label global.  i'll try it, but i have doubts.

eoateseoates

 

I have found a sort of workaround, but it's really "cludgy." What I ended up doing is placing some inputHidden components on my page and bound them to string variables in the controller. Then in the VF page, I added Javascript when the page loads to populate the hidden fields with the value of the labels I needed via $Label.labelname.

Message Edited by eoates on 08-05-2009 08:26 AM
richardvrichardv

What a bummer - I was totally blind-sided by this.  I have a controller that has almost a hundred labels and just now realized those labels are being translated.  I'm going to workaround it with a variant of what you suggested @eoates.

 

Force.com Prod Mgmt: PLEASE FIX THIS ASAP!