+ Start a Discussion
Edward GeeEdward Gee 

Dealing with user language in an S-Control

Hi everyone,

The overall goal I'm trying to achieve is to retrieve language-specific data (not stored in salesforce objects) to my S-Control in an optimized manner.  One way that was devised is to include an S-Control snippet that acts as sort of a gateway to include another S-Control snippet that contains language-specific data.  For example, assume I have created the following objects:
  • Call Report - main S-Control
  • Account_Metadata - gateway snippet code that takes the language as an input parameter and returns another snippet coded for that language
  • Account_Metadata_en_US, Account_Metadata_de, Account_Metadata_es, Account_Metadata_fr, etc... - snippet code containing language-specific data
Ideally, I would like to have my Call Report S-Control contain a simple include directive as follows but unfortunately user language is not exposed as a merge field:
Code:
...
{!INCLUDE($SControl.Account_Metadata, [userLanguage="{$User.UserLanguage}"])}
...
for (var j=0; j<Account_Metadata.Salutation.length; j++) {
var label = Account_Metadata.Salutation[j].label;
var value = Account_Metadata.Salutation[j].value;
...
}
...

The Account_Metadata snippet contains the following:
Code:
{!
IF($Request.userLanguage = "en_US", INCLUDE($SControl.Account_Metadata_en_US), 
   IF($Request.userLanguage = "es", INCLUDE($SControl.Account_Metadata_es), 
      IF($Request.userLanguage = "de", INCLUDE($SControl.Account_Metadata_de), 
      ...
      ...
      }
   )
)
}
And for example, Account_Metadata_es would have the following:
Code:
<script type="text/javascript">
function Account_Metadata() {
}

Account_Metadata.Salutation = [ {label:"Sr.", value:"Sr."}, {label:"Srta.", value:"Srta."}, {label:"Sra.", value:"Sra."}, {label:"Dr.", value:"Dr."}, {label:"Prof.", value:"Prof."} ];
...
</script>

Assuming the language code snippets contained the same variable/function names, I could have referred to language-specific data in a common way from my main S-Control and swap out the data easily based on the user's language preference.  I would also save on footprint size as I wouldn't have to include every language in my S-Control.  But as mentioned above, language code is not a merge field and I don't believe the Include directive allows passing of non-constant values as parameters.

Has anyone tried solving a similar problem?  Any ideas other than requesting from salesforce to include the user language as a merge field off the User object?  Is there a way to programmatically do this by including javascript files (e.g., <script src="./es/Account_Metadata.js">?

- Ed