Sdry, I have wanted to do exactly this ever since Custom Settings came out. The problem, though, is that there is no Apex API for Custom Labels (click the link to vote for the idea for it!), so Custom Labels cannot be dynamically retrieved or requested within Apex. However, it CAN, as of Spring 12, be done in Visualforce, using Dynamic Components.
Here, I think is what you are looking for in Apex (that cannot yet be done):
Custom Settings + Custom Labels IN APEX (**not yet possible**)
// Get the stored Custom Setting record for User Preferences
User_Prefs__c p = User_Prefs__c.getInstance(UserInfo.getUserId());
// Get the stored ISO Code
String isoCode = p.ISO_Code__c;
// Get the running user's language
String languageKey = [
select LanguageLocaleKey from User
where Id = :UserInfo.getUserId()
limit 1
].LanguageLocaleKey;
// Get the translation of the ISO Code corresponding to this user's language
// **THIS IS NOT POSSIBLE YET IN APEX**
String translatedCode = System.Label.getLabel('ISOCode_'+isoCode).getTranslation(languageKey);
And here would be an equivalent if you are using Visualforce:
Custom Settings + Custom Labels IN VISUALFORCE (possible right now)
/* APEX CONTROLLER */
public class Controller {
public String getStoredISOCode() {
// Get the stored Custom Setting record for User Preferences,
// and return the ISO code
return User_Prefs__c.getInstance(UserInfo.getUserId()).ISO_Code__c;
}
}
/* VF PAGE */
<apex:page controller="MyController">
<b>ISO Code</b>{!storedISOCode}
<b>Translated</b>{!$Label['ISOCode_' & storedISOCode]}
</apex:page>
Best Answer
EDIT This is now possible! You can instantiate a dynamic visualforce component in Apex to get this.
ORIGINAL ANSWER
No, you can't reference labels dynamically in apex. You can vote for this idea here. However, you can reference them dynamically from visualforce so you can put them on the page like so: