Return to doc.sitecore.com

Adding Translations

Translations are used to translate content between SharePoint and Sitecore. You can create your own translations under /Sitecore/system/modules/sharepoint/translations. You need to implement the Sitecore.Modules.SharePoint.Translations.ITranslation interface. The class displayed below is an example from the SharePoint module core. To use a custom translation, you should select one of the existing list connections, then select a field mapping and specify an alternative translation.

1.  Code Sample

using System;

namespace Sitecore.Modules.SharePoint.Translations {
    
    
/// <summary>
    
/// Translates SharePoint dateformat to Sitecore dateformat
    
/// </summary>
    public class DateTime : ITranslation {
        
        
public DateTime() {}

        
public string TranslateFromSharePoint(string valueToTransform) {
            
string result = System.String.Empty;

            
try {
                result
= Sitecore.DateUtil.ToIsoDate(System.DateTime.Parse(valueToTransform));
            }
catch (Exception ex) {
                Logging.Log(String.Format(
"Could not translate the value \"{0}\" to IsoDate format", valueToTransform), ex, Logging.Category.Warning, "sharepoint.999");
            }

            
return result;
        }

        
public string TranslateFromSitecore(string valueToTransform) {
            
string result = System.String.Empty;

            
try {
                result
= Sitecore.DateUtil.IsoDateToNormal(valueToTransform).ToString();
            }
catch (Exception ex) {
                Logging.Log(String.Format(
"Could not translate the value \"{0}\" from IsoDate format", valueToTransform), ex, Logging.Category.Warning, "sharepoint.999");
            }

            
return result;
        }
    }
}