Translations sound suspiciously close to Metadata API which means it's not accessible from Apex (at least not without some callout-like hacks). Can't you just use standard Translation Workbench? Export to Excel, let users translate, import back... sure beats crafting XML files.
Besides even if you had such possibility to modify translations from Apex - how do you plan to write a "metadata change sniffer" that'd "fire" every time a new picklist is added or existing one modified? Or that would detect the fact a new language was enabled in the system?
I believe "you're doing it wrong" ;) I think it makes more sense to leverage the fact Salesforce kept picklist name & value identical (so no way to configure system out of the box to have <select>...<option value="Y">Yes</option>...</select>
). If you need this Yes/No somewhere else as Y/N - consider making a formula field?
EDIT
Translations metadata missing in Eclipse - check your package.xml. Mine contains (among others)
<types>
<members>*</members>
<name>CustomObjectTranslation</name>
</types>
<types>
<members>*</members>
<name>Translations</name>
</types>
("Translations" is for apps, custom labels etc) and my Opportunity-es.objectTranslation has correct data in it:
<?xml version="1.0" encoding="UTF-8"?>
<CustomObjectTranslation xmlns="http://soap.sforce.com/2006/04/metadata">
...
<fields>
<help>Si es Indirecto, debe rellenar el campo de mayorista</help>
<label>Directo / Indirecto</label>
<name>Direct_Indirect__c</name>
<picklistValues>
<masterLabel>Direct</masterLabel>
<translation>Directo</translation>
</picklistValues>
<picklistValues>
<masterLabel>Indirect</masterLabel>
<translation>Indirecto</translation>
</picklistValues>
</fields>
...
<fields>
<name>LeadSource</name>
<picklistValues>
<masterLabel>Advertisement</masterLabel>
<translation><!-- Advertisement --></translation>
</picklistValues>
<picklistValues>
<masterLabel>Customer Event</masterLabel>
<translation><!-- Customer Event --></translation>
</picklistValues>
...
This might do the trick:
Schema.DescribeFieldResult F = Account.MyField__c.getDescribe();
List<Schema.PicklistEntry> P = F.getPicklistValues();
Map<String, String> mapMyFieldTranslation = new Map<String, String>();
for(Schema.PicklistEntry e : P){
mapMyFieldTranslation.put(e.value, e.label);
}
String result = mapMyFieldTranslation.get(myAccount.MyField__c));
With 'result' containing the translation.
Best Answer
You can use a SOQL function
toLabel()
to get translated picklist values:Here is the official documentation: