Setting the Project Information
In this chapter you will learn how to programmatically create a simple project, and define the general project properties such as name, description, due date, etc.
Create the Project
Start by implementing a function called CreateProject
. Create a file-based project object called newProject
based on the class FileBasedProject. In our example we provide the project properties as parameter. We recommend that you generate the project properties through a separate helper function called e.g. GetProjectInfo as shown below:
FileBasedProject newProject = new FileBasedProject(info);
Set the Project Information
In the GetProjectInfo helper function, we first create a ProjectInfo object:
ProjectInfo info = new ProjectInfo();
We define the project properties by applying various properties to the project object as outlined below:
info.Name = "My First Project";
info.Description = "This is a programmatically created project.";
info.DueDate = DateTime.Now.AddDays(3);
In the above example we set the following parameters:
- Project name, which can be any descriptive name
- The (optional) project description
- The (optional) project due date, e.g. 3 days from now
The screenshot below illustrates how this information is entered in the New Project wizard of Trados Studio.
Set the Local Project Folder
All project files, i.e. translatable and localizable documents, reference files, project TMs, etc. are stored in a specific folder. By default, the main folder used for storing projects is: C:\Users\UserName\Documents\Studio 2024\Projects. Below this main folder Trados Studio creates sub-folders that carry the name of the respective project. However, you could just as well pick any other folder name, as long as the specified folder is empty so as to avoid collisions with existing files. In the example below we follow the default folder rule of Trados Studio by selecting the Studio 2024\Projects\ folder below Documents, and by appending the project name sub-folder. We then set the LocalProjectFolder property accordingly as shown in the example below:
string localProjectFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments).ToString() +
Path.DirectorySeparatorChar + $@"{Versioning.Versions.StudioDocumentsFolderName}\Projects\" + info.Name;
info.LocalProjectFolder = localProjectFolder;
Select the Project Languages
A project must have at least one language pair, i.e. a source language and one target language. Projects can have only one source language, but multiple target languages. The screenshot below highlights how languages are selected in Trados Studio:
For this example, let us assume that the source language should be English (US), and the target languages German and French. First, we create the source language object through the Language
class. The language object takes the CultureInfo as parameter. Then we assign the source language object to the project info by applying the SourceLanguage property:
Language srcLang = new Language(CultureInfo.GetCultureInfo("en-US"));
info.SourceLanguage = srcLang;
In the next step we do the same for the target languages. Since a project can have several target languages, we use an array of language objects, and then assign this array to the project info through the TargetLanguages property:
Language[] trgLangs = new Language[] { new Language(CultureInfo.GetCultureInfo("de-DE")), new Language(CultureInfo.GetCultureInfo("fr-FR")) };
info.TargetLanguages = trgLangs;
After setting the above project properties, do not forget to return the project info object:
return info;
Furthermore, to persist the project information in the project object, you need to apply the Save method:
newProject.Save();
This will create an *.sdlproj file, which is an XML-compliant document that contains all the project information. After running the above code you should already see a result in the projects folder as illustrated in the screenshot below:
Even if you have not added any translatable files yet, you will end up generating the project sub-folder (i.e. Projects\My first project), which contains the *.sdlproj file. In the following chapters you will learn how to add documents, TMs, termbases, etc. to turn your sample into a meaningful project. Note that if you run your sample application again while the My first project is still there, an error will be thrown, as the folder is not empty. It is recommended that when you re-run your sample application for testing purposes that you delete the project sub-folder, so that you have a fresh start (see also Deleting Projects).
Also note that the C:\Users\UserName\Documents\Studio 2024\Projects folder contains a file called projects.xml. This is a meta file that contains references to all the projects that have been created in Trados Studio. The projects that you create programmatically will not be referenced in this file, and thus not be listed in Trados Studio, which is by design. However, you can, of course, open the programmatically created *.sdlproj file in Trados Studio.
Putting it All Together
The complete function for setting the project properties should look as shown below:
public ProjectInfo GetProjectInfo()
{
#region "InfoObject"
ProjectInfo info = new ProjectInfo();
#endregion
#region "GeneralInfo"
info.Name = "My first project";
info.Description = "This is a programmatically created project.";
info.DueDate = DateTime.Now.AddDays(3);
#endregion
#region "ProjectFolder"
string localProjectFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments).ToString() +
Path.DirectorySeparatorChar + $@"{Versioning.Versions.StudioDocumentsFolderName}\Projects\" + info.Name;
info.LocalProjectFolder = localProjectFolder;
#endregion
#region "SourceLanguage"
Language srcLang = new Language(CultureInfo.GetCultureInfo("en-US"));
info.SourceLanguage = srcLang;
#endregion
#region "TargetLanguages"
Language[] trgLangs = new Language[] { new Language(CultureInfo.GetCultureInfo("de-DE")), new Language(CultureInfo.GetCultureInfo("fr-FR")) };
info.TargetLanguages = trgLangs;
#endregion
#region "ReturnInfo"
return info;
#endregion
}
See Also
Running Tasks on the Project Files
Creating Projects Based on Previous Projects