Skip to content

Instantly share code, notes, and snippets.

@andreaGhisa
Created October 2, 2018 13:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andreaGhisa/33dc13bed8df734ae5c69b0787406234 to your computer and use it in GitHub Desktop.
Save andreaGhisa/33dc13bed8df734ae5c69b0787406234 to your computer and use it in GitHub Desktop.
CreateServerBasedTm
[ApplicationInitializer]
public class Create : IApplicationInitializer
{
public void Execute()
{
var uri = new Uri(@"Add your url");
var translationProviderServer = new TranslationProviderServer(uri, false, "user name", "password");
var serverTm = new ServerBasedTranslationMemory(translationProviderServer)
{
Name = "Tm from API"
};
var resourceTemplate =
translationProviderServer.GetLanguageResourcesTemplates(LanguageResourcesTemplateProperties.All);
var containters = translationProviderServer.GetContainers(ContainerProperties.All);
var container = containters.FirstOrDefault(c => c.Name.Equals("APSIC_TM_Container"));
if (container != null)
{
serverTm.Container = container;
serverTm.ParentResourceGroupPath = container.ParentResourceGroupPath;
serverTm.LanguageResourcesTemplate = resourceTemplate?[0];
CreateLanguageDirections(serverTm.LanguageDirections);
serverTm.Save();
}
}
private void CreateLanguageDirections(ServerBasedTranslationMemoryLanguageDirectionCollection directionsCollection)
{
var direction = new ServerBasedTranslationMemoryLanguageDirection
{
SourceLanguage = CultureInfo.GetCultureInfo("en-US"),
TargetLanguage = CultureInfo.GetCultureInfo("de-DE")
};
directionsCollection.Add(direction);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment