[SalesForce] Combine Custom settings with Custom Labels

Is there a way to combine custom settings with custom labels ? So that the output from a setting value would be a custom label ?

To explain:

In example, we have an international organisation, and say countries are stored as an ISO code. As this is a limited and stable set of data, using custom settings would be the appropriate way to deal with say the full country name. The issue arises when I do not just want to store the English country name, but want to have it translatable, presenting the right translation depending on the user's locale. Now, this is the point where I'd like to integrate custom settings with custom labels.

So that say the custom setting with name 'some iso code' doesn't return the full country name, but Label.Country'some iso code', which is than automatically translated in the right version.

Sounds good right. But as custom settings are fixed to certain types, as far as I've gotten is put the label name in the settings as a string value. And then .. i'm stuck :).
No way to cast a string to a Custom label, or have it be interpreted (and translated) as such, or is there ?

I'm aware this can be done in a custom object & apex, I was hoping for a more automated, "cleaner", less resource consuming way, better integrated, configurable way.

Additional clarrification:
*The goal is to extend the use of custom labels (translation workbench), by adding a mapping from any data-based value to a custom label.*

While we could do a long matching process in apex, it would be faster & neater if the custom settings mechanism could be used.
There are disadvantaged to custom objects, they require soql & apex, while custom settings & custom labels are cached. They too can be used in many other places. Countries were an example, I'd use this mechanism for every variable value that needs to be translatable.

Best Answer

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>
Related Topic