| Setting and Retrieving TM Properties |
After creating a translation memory there are various properties that you can retrieve, set, or change such as the TM description, an expiration date, the translation unit count, etc.
As we are going to implement the functionality for setting and retrieving the TM properties in a separate class. Create a new class called TmProperties. Next, add a function called GetAndSetProperties, which takes the TM file name and path as string parameter, and which can be called as shown below:
TMProperties objProps = new TMProperties();
objProps.GetAndSetProperties(_translationMemoryFilePath);tm.Description = "This is the TM description."; tm.Copyright = "(c) 2010 SDL International"; tm.ExpirationDate = DateTime.Now.AddDays(7);
Below you see a few examples of properties that you can retrieve on a given TM and then output in a message box.
string tmInfo; tmInfo = "TU count: " + tm.GetTranslationUnitCount().ToString(); tmInfo += "; Password-protected: " + tm.IsProtected.ToString(); tmInfo += "; Expires on: " + tm.ExpirationDate.ToString(); MessageBox.Show(tmInfo);
The complete class should now look as shown below:
namespace Sdl.SDK.LanguagePlatform.Samples.TmAutomation { using System; using System.Windows.Forms; using Sdl.LanguagePlatform.TranslationMemoryApi; public class TMProperties { public void GetAndSetProperties(string tmPath) { FileBasedTranslationMemory tm = new FileBasedTranslationMemory(tmPath); #region "set" tm.Description = "This is the TM description."; tm.Copyright = "(c) 2010 SDL International"; tm.ExpirationDate = DateTime.Now.AddDays(7); #endregion #region "get" string tmInfo; tmInfo = "TU count: " + tm.GetTranslationUnitCount().ToString(); tmInfo += "; Password-protected: " + tm.IsProtected.ToString(); tmInfo += "; Expires on: " + tm.ExpirationDate.ToString(); MessageBox.Show(tmInfo); #endregion } } }