We need a way to copy English translations of picklist labels into other languages. Given a picklist on the Opportunity object with values Y and N translated as follows:
Value EN_us DE FR
Y Yes Ja
N No Nein
We want a scheduled apex job to fill in missing labels in French with "Yes" or "No" from the English translation until such time as someone overwrites them manually with "Oui" and "Non".
Why? Because if the label is missing in French then SalesForce displays "Y" and not "Yes". In this example it might still be understandable for an French User that "Y" means Yes but in other examples, with picklists containing technical keys it would not be.
I know how to query the labels in my current language and get "Yes" but how to I query and set labels in a different language? Ideally I want to do this in apex and not by deploying files.
List<Schema.PicklistEntry> vals = Opportunity.SomeField__c.getDescribe().getPicklistValues();
for (Schema.PicklistEntry val: vals) {
system.debug(val.getValue()+'='+val.getLabel());
// 1. How can I do val.getLabel('FR') ?
// 2. How can I do val.setLabel('FR', 'Yes') ?
}
I have tried looking at the .objectTranslation files in the IDE but they are empty even though we have translated values. For example Opportunity-de.objectTranslation
contains simply:
<?xml version="1.0" encoding="UTF-8"?>
<CustomObjectTranslation xmlns="http://soap.sforce.com/2006/04/metadata"/>
even though we have several translated picklist labels in German on the Opportunity object.
UPDATE:
Using Ant (or Force.com IDE) to retrieve translations always returns empty files even though we have picklists translated.
<sf:bulkRetrieve ... metadataType="CustomObjectTranslation" retrieveTarget="retrieved"/>
returns empty files (e.g. Opportunity-no.objectTranslation
):
<?xml version="1.0" encoding="UTF-8"?>
<CustomObjectTranslation xmlns="http://soap.sforce.com/2006/04/metadata"/>
Same story for metadataType="Translations"
Best Answer
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)
("Translations" is for apps, custom labels etc) and my Opportunity-es.objectTranslation has correct data in it: