@Charles : Yes, I had gone ahead with the custom object option as there was not any room of making API calls just for translations.
But did create per column for every language. in my case there were 12, so having 12 more columns on an object was better..sicne overall, record consumption would still be 2kb/record
Thanks
JJ
I ran a piece of anonymous Apex based on the code you provided. The strange thing is that it indeed does change the language correctly and even reflects this in the UserInfo class, but the toLabel() function of SOQL doesn't use the new language.
system.debug(userinfo.getLanguage());
User currentUser = [SELECT LanguageLocaleKey FROM User WHERE Id =: UserInfo.getUserId()];
currentUser.LanguageLocaleKey = 'NL_nl';
update currentUser;
system.debug(userinfo.getLanguage());
Opportunity opp = [SELECT toLabel(StageName) FROM Opportunity Limit 1];
System.debug(opp);
First time I run it (I started with English as language), the debug logs show:
But the second time I run (so after the language is changed by the first run), it does translate the label:
So either the SOQL engine doesn't look at the current UserInfo values, but at the values at the start of the execution context, or this is a bug.
Have you contacted Salesforce support about this?
Workaround:
What you could also do, is use the Schema Describe info to get the labels that correspond to the picklist values you query from your Opportunity record.
Schema.DescribeFieldResult field = Opportunity.Phase__c.getDescribe();
List<Schema.PicklistEntry> picklistValues = field.getPicklistValues();
Go through this list of picklist values and use getLabel() to get the translated value.
Best Answer
You have to add the languages into the community via the community builder. Once enabled, the translations from the translation workbench will start to come through.